Skip to:
Content
Pages
Categories
Search
Top
Bottom

Removing bp_nav menu item for specific users


  • Grant Derepas
    Participant

    @dr_scythe

    BP 1.6.5
    WP 3.5.1

    My buddypress environment has two distinct profile types set by an x-profile field.
    I’m using BP-Media which adds a media tab to a users menu
    I want to remove that tab from one profile types menus.
    I’m guessing I need to remove it from both the bp_is_my_profile() nav layout and the public nav layout…. When i try setting a global bp_core_remove_nav_item(‘media’) it removes it from other peoples pages but break my own profile

    Heres what I’ve got so far:

    
    //For own profile
    //First i need the logged in users id
    global $bp
    $userid = $bp->loggedin_user['id']
    //Then use that ID to work out what type of user they are
    $usertype = bp_profile_field_data( 'field=User Type&user_id=$userid' );
    
    if ($usertype == 'type1'){
    	function remove_media_tab(){
    	bp_core_remove_nav_item('media');
    	}
    }
    
    add_action('bp_friends_setup_nav','remove_media_tab');
    

    Direction, advice and comments appreciated!

Viewing 5 replies - 1 through 5 (of 5 total)
  • You should be crashing & burning with:
    $bp->loggedin_user[‘id’]

    It’s an object so should be this:
    $bp->loggedin_user->id

    Or better use:
    bp_loggedin_user_id()


    Grant Derepas
    Participant

    @dr_scythe

    
    //For own profile
    //First i need the logged in users id
    global $bp;
    $userid = bp_loggedin_user_id();
    //Then use that ID to work out what type of user they are
    $usertype = bp_profile_field_data( 'field=User Type&user_id=$userid' );
    
    if ($usertype == 'type1'){
    	function remove_media_tab(){
    	bp_core_remove_nav_item('media');
    	}
    }
    
    add_action('bp_friends_setup_nav','remove_media_tab');
    

    Ok updated that code and added it to my themes functions.php file.

    Upon testing the code doesn’t seem to be doing anything. Logged in as specified user type and viewed my own profile as well as another member of that types profile and both are still showing the media tab.

    Thoughts?


    Grant Derepas
    Participant

    @dr_scythe

    After some further debugging the code is failing at this line:

    $usertype = bp_profile_field_data( 'field=User Type&user_id=$userid' );

    I’ve also tried the following and the correct data is still not being pulled from the database

    $usertype = bp_get_profile_field_data( array(‘user_id’=>$userid,’field’=>'User Type' ));

    In both cases I’ve also tried swapping the field= to the field id number which still doesn’t work.


    Grant Derepas
    Participant

    @dr_scythe

    //For own profile
    //First i need the logged in users id
    function global_remove_media_tab() {
    
    global $bp;
    
    $userid = bp_loggedin_user_id();
    //Then use that ID to work out what type of user they are
    $usertype = xprofile_get_field_data( 'User Type', $userid );
    if ($usertype == 'Groupie'){
    	bp_core_remove_nav_item('media');
    	}
    }
    
    add_action('bp_setup_nav','global_remove_media_tab');

    Ok this code “works”.
    But it removes the media tab for every profile when logged in as a “Groupie” User type.
    What I want is to remove the tab from all Groupie Member profiles only including groupie members looking at their own profile.


    Grant Derepas
    Participant

    @dr_scythe

    Achieved what I was after with the following code

    function global_remove_media_tab() {
    
    global $bp;
    
    $profileid = bp_displayed_user_id();
    $profiletype = xprofile_get_field_data( 'User Type', $profileid );
    if ($profiletype == 'Groupie'){
    	bp_core_remove_nav_item('media');
    	}
    }
    
    add_action('bp_setup_nav','global_remove_media_tab');
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Removing bp_nav menu item for specific users’ is closed to new replies.
Skip to toolbar