Can comment filter ...
 
Share:
Notifications
Clear all

[Solved] Can comment filter not working, help?

2 Posts
2 Users
0 Likes
486 Views
Posts: 15
Topic starter
(@beachcalsixaol-com)
Eminent Member
Joined: 2 years ago

Hi, I am referencing from the previous question posted. Link here

The solution provided was the following filter shown below (link):

add_filter("wpdiscuz_user_role_can_comment", function ($canComment, $role) {
if ($role === "Paidplanrole") {
$canComment = true;
}
return $canComment;
}, 10, 2);

 

Like the user that previously posted, My users have a basic subscriber role for the free plan and then a new role for the paid plans. So every paying user gets 2 roles: subscriber and paidplanrole.

If I block subscriber roles from commenting, no one is able to comment because every user has subscriber auto set. 

I tried adding the filter above to my functions.php and set the paidplanrole can comment. 

It did not work at all. Anyone can comment whether or not they have paidplanrole. 

I would like it to be only users that have paidplanrole assigned to them can comment. 

Is this possible?

Thank you!

1 Reply
Asti
Posts: 7056
 Asti
Support
(@asti)
Illustrious Member
Joined: 6 years ago

Hi,

Please try out this hook code:

add_filter('wpdiscuz_user_role_can_comment', function ($canComment) {
    $user = wp_get_current_user();
    return in_array( 'Paidplanrole', (array) $user->roles);
}, 11);
Share: