BuddyDev

Search

[Resolved] Enable thread nested comments or "comment reply button" for specific user-role

  • Participant
    Level: Enlightened
    Posts: 69
    evil lizard on #22155

    hi @ravi this is the NEW topic for that my problem i was on about.


    I was wondering about this my former post: https://buddydev.com/support/forums/topic/enable-threaded-nested-comments/


    Been searching for a solution all over facebook and stackoverflow ..but no solution yet.

    You think maybe you could help me out with it..please?

    I just want a specific user-role to be able to see this “REPLY” button: https://postimg.cc/crz2jTMj

    Instead of everyone seeing it… ?? Please?

    Maybe you could code the filter around this logic? :
    https://developer.wordpress.org/reference/hooks/comment_reply_link/

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #22159

    Hello Evillizard,

    Please try the following code to hide the reply link on comments.

    
    /**
     * Check weather current user can see reply button or not
     *
     * @param string $link Reply link.
     *
     * @return bool
     */
    function buddydev_user_role_check_on_comment_reply_button( $link ) {
    	if ( ! is_user_logged_in() || is_super_admin() ) {
    		return $link;
    	}
    
    	$current_user  = wp_get_current_user();
    	$allowed_roles = array( 'contributor', 'author' ); // Replace by your user role.
    
    	$common_roles = array_intersect( $allowed_roles, $current_user->roles );
    
    	if ( empty( $common_roles ) ) {
    		return false;
    	}
    
    	return $link;
    }
    add_filter( 'comment_reply_link', 'buddydev_user_role_check_on_comment_reply_button' );
    

    Thanks
    Ravi

  • Participant
    Level: Master
    Posts: 285
    evillizard on #22162

    Ok, so with this code..only contributor and author role would be able to see the link right?

    ..

    And if i wona change it so another role wld see..i would just add it to the “$allowed_roles” right??

  • Participant
    Level: Master
    Posts: 285
    evillizard on #22163

    Im asking instead of testing the code because: I don’t have electricity to test right now.. Cos they only sometimes give us electricity at mid-night

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #22164

    Yes evillizard, You can add as much as roles to Allowed roles array. Only users with these roles can see the reply button.

    Thank You
    Ravi

  • Participant
    Level: Enlightened
    Posts: 69
    evil lizard on #22166

    Ok ravi

    Ild check it as soon as i have the time.

    Thanks alot

    Regards!
    eviL-Lizard

    • This reply was modified 3 years, 5 months ago by evil lizard.
  • Participant
    Level: Master
    Posts: 285
    evillizard on #22177

    Thanks @Ravi you a wonderful guy..do you know that?

    Your code worked so perfectly!

    You all @buddydev are incredibly awesome,

    Thanks alot, im honoured and very grateful, thank you

    Regards!
    eviL-Lizard

You must be logged in to reply to this topic.

This topic is: resolved