Skip to:
Content
Pages
Categories
Search
Top
Bottom

Hiding Menu by User Role


  • 083n
    Participant

    @083n

    I need to show BuddyPress menu item just specific roles and hide all other users.
    I have 2 user roles like subscriber and author.
    For example; I want to show my friends only to the authors and to me. None of the other subscribers can see.

    I can hide menu items with this code in functions.php ;

    function bp_remove_nav_item() {
        global $bp;    
        bp_core_remove_nav_item( 'buddyblog' );
        }
    add_action( 'wp', 'bp_remove_nav_item' );

    How can I edit this for excepting to me and the authors ?

Viewing 1 replies (of 1 total)

  • 083n
    Participant

    @083n

    I solved it with my own effort.

    function bp_remove_nav_item() {
        $current_user   = wp_get_current_user();
        $role_name      = $current_user->roles[0];
        if($role_name==='administrator'){
           bp_core_remove_nav_item( 'buddyblog' );
        }
    }
    add_action( 'wp', 'bp_remove_nav_item' );

    This code delete blog menu for administrator.

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