0

today I tried a lot of things to fix this problem, I hope somebody can help me. I will explain my problem with example. : lets take i have a user named Maykl and I want to prevent Maykil to write comment for posts that have Movies kategory. This user can read comments but he must not write comment to this post. Warning ! I dont want to restrict user role. I want to restrict a specific user. How can I do this or is it possible in wordress? Thanks for your attention !

<?php
    if( (current_user_can( 'expert_1') && has_category( 'category_1')) ||
        (current_user_can( 'expert_2') && has_category( 'category_2')) ||
        (current_user_can( 'expert_3') && has_category( 'category_3')) ) {
            if ( comments_open() || get_comments_number() ) {
                comments_template();//or comment_form() or whatever function you are using to display the comment form
            }
    }
?>

I can do it with user role but can not do it for specific users

4
  • I hope your user is not named Maykil, you still have a duty to protect peoples privacy. Note that it's tempting here to hardcode the users user ID and the term ID which would be a mistake – Tom J Nowell Jan 18 at 17:09
  • no. XD my user name is not Maykil. I am glad to see you again Tom J Nowell. Some how I am happy when see your name in my topic – Gidromasservis QSC Jan 18 at 17:17
  • I guess what you'd need to do to really make this work is create a section in your dashboard where you can add user IDs to a black list, then you'd have to either edit the comments_template() or create an override template where before loading the comment form you first run a conditional check to see if the current user's ID is in the array of blocked users or not. – Tony Djukic Jan 18 at 18:06
  • can this affect my website speed performance? – Gidromasservis QSC Jan 18 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.