Skip to:
Content
Pages
Categories
Search
Top
Bottom

Remove “Edit” link in reply header for certain roles


  • enkoes
    Participant

    @enkoes

    Hi, I’m using the codes below to remove “Edit” link in reply header without any issue:

    add_filter ('bbp_reply_admin_links', 'rew_remove_edit') ;
    add_filter ('bbp_topic_admin_links', 'rew_remove_edit') ;
    
    function rew_remove_edit ($links) {
    	unset ($links['edit']) ;
    return $links ;	
    }

    My question: If I want the codes to work only for Role A & Role B, but NOT for other roles, how would I amend the code above?

    Regards.

Viewing 11 replies - 1 through 11 (of 11 total)

  • Robin W
    Moderator

    @robin-w

    are these wordpress roles, bbpress roles, (say membership) plugin roles, or some customs roles you have written?


    enkoes
    Participant

    @enkoes

    They are all bbpress roles.


    Robin W
    Moderator

    @robin-w

    add_filter ('bbp_reply_admin_links', 'rew_remove_edit') ;
    add_filter ('bbp_topic_admin_links', 'rew_remove_edit') ;
    
    function rew_remove_edit ($links) {
    $user_role = bbp_get_user_role( $user_id );
    if ($user_role == bbp_get_keymaster_role()) unset ($links['edit']) ;
    if ($user_role == bbp_get_moderator_role()) unset ($links['edit']) ;
    if ($user_role == bbp_get_participant_role()) unset ($links['edit']) ;
    if ($user_role == bbp_get_spectator_role()) unset ($links['edit']) ;
    if ($user_role == bbp_get_blocked_role()) unset ($links['edit']) ;
    return $links ;	
    }

    and amend as needed

    spectator and blocked not really needed as neither can post, but included for completeness !!


    enkoes
    Participant

    @enkoes

    Hi Robin, thanks for your prompt reply.

    The code does not work. Perhaps something missing?

    I only take this
    if ($user_role == bbp_get_moderator_role()) unset ($links['edit']) ;
    When moderator log in, he still can see the “edit” link.

    Regards.


    Robin W
    Moderator

    @robin-w

    sorry, try this

    add_filter ('bbp_reply_admin_links', 'rew_remove_edit') ;
    add_filter ('bbp_topic_admin_links', 'rew_remove_edit') ;
    
    function rew_remove_edit ($links) {
    $user_id = bbp_get_current_user_id() ;
    $user_role = bbp_get_user_role( $user_id );
    if ($user_role == bbp_get_keymaster_role()) unset ($links['edit']) ;
    if ($user_role == bbp_get_moderator_role()) unset ($links['edit']) ;
    if ($user_role == bbp_get_participant_role()) unset ($links['edit']) ;
    if ($user_role == bbp_get_spectator_role()) unset ($links['edit']) ;
    if ($user_role == bbp_get_blocked_role()) unset ($links['edit']) ;
    return $links ;	
    }

    enkoes
    Participant

    @enkoes

    Yes. It works beautifully! 🙂

    I just found out something when I thought the issue is solved. The code works well with native bbpress role, but not work with new role created. I have a new role “prime_moderator” created using your plugin, but the code return error when I apply this new role to the codes. Any suggestions?

    Regards.


    Robin W
    Moderator

    @robin-w

    ok, so what is the role on this line

    $bbp_roles['bbp_tutor'] = array(

    and what is the code you have added in the code above?


    enkoes
    Participant

    @enkoes

    There it is:
    $bbp_roles['bbp_prime_moderator'] = array(

    I’ve tried the two options below but both return errors:
    if ($user_role == bbp_get_bbp_prime_moderator_role()) unset ($links['edit']) ;
    if ($user_role == bbp_get_prime_moderator_role()) unset ($links['edit']) ;


    Robin W
    Moderator

    @robin-w

    if ($user_role == 'bbp_prime_moderator') unset ($links['edit']) ;

    for custom roles, you just name the role itself.,


    enkoes
    Participant

    @enkoes

    Yes, Robin. The codes run without any error. Appreciated your effort in helping me to solve the issue.


    Robin W
    Moderator

    @robin-w

    no problem

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.
Skip to toolbar