The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
Search
Close
AI Search
Classic Search
 Search Phrase:
 Search Type:
Advanced search options
 Search in Forums:
 Search in date period:

 Sort Search Results by:

AI Assistant
Can comment filter ...
 
Share:
Notifications
Clear all

[Solved] Can comment filter not working, help?

2 Posts
2 Users
0 Reactions
1,216 Views
Posts: 15
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@beachcalsixaol-com)
Eminent Member
Joined: 4 years ago
[#3859]

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: 8210
 Asti
Support
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@asti)
Illustrious Member
Joined: 8 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: