BuddyDev

Search

[Resolved] Create a tab (nav_item) that can display custom post type items of user.

  • Keymaster
    (BuddyDev Team)
    Posts: 24075
    Brajesh Singh on #46701

    Hi Lefteris,
    The goal of the code was to check for the displayed user as we were checking the availability and not the visibility.

    What is your goal with the tab, on whose profile it should be available and who can see it? Please clarify.

    We did not register the nav on non user pages, so this will not be available as nav item. You can use custom link option in the page and then use the dynamic url( http://example.com/members/me/shows/) to replace with logged user’s own shows page.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 71
    Lefteris on #46705

    Hello Brajesh,

    Thank you very much for your reply 🙂
    My theme is using a profile dropdown menu very similar like in your website https://ibb.co/641Q022.
    I would like to create this tab just for 3 user roles (for example ‘editor’, ‘administrator’, ‘author’).
    So basically everybody can see this tab on those 3 users profile,but only those 3 user roles have it.
    But when the logged in user is ‘author’ and he visits a profile page of a ‘subscriber’, the nav_item is getting removed from his own profile dropdown menu.

    If you wish i can give you access to a stage site of mine to see the result.Please let me know.

    Best Regards,
    Lefteris

  • Keymaster
    (BuddyDev Team)
    Posts: 24075
    Brajesh Singh on #46752

    Hi Lefteris,
    Thank you for the details.

    Here is the updated code. Please give it a try.

    
    function mb_bp_profile_menu_radio_shows() {
    
    	$user_id = bp_is_user() ? bp_displayed_user_id() : bp_loggedin_user_id();
    
    	$user = get_user_by( 'id', $user_id );
    
    	if ( ! $user || ! array_intersect( $user->roles, array( 'editor', 'administrator', 'author' ) ) ) {
    		return;
    	}
    
    	bp_core_new_nav_item(
    		array(
    			'name'                    => 'ΕΚΠΟΜΠΕΣ',
    			'slug'                    => 'shows',
    			'position'                => 30,
    			'default_subnav_slug'     => 'shows',
    			'screen_function'         => 'producer_shows',
    			'show_for_displayed_user' => true,
    		)
    	);
    
    }
    

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 71
    Lefteris on #46765

    Hello Brajesh,

    Thank you for your help 🙂
    I tested your code but still the problem remains. When the logged in user is ‘author’ and he visits a profile page of a ‘subscriber’, the nav_item is getting removed from his own profile dropdown menu.
    Following, when a ‘subscriber’ visits a profile page of an ‘author’ he can see the nav_item registered on his own profile dropdown menu.

    Best Regards,
    Lefteris

  • Keymaster
    (BuddyDev Team)
    Posts: 24075
    Brajesh Singh on #46769

    Hi Lefteris,
    For the menu, I don’t have any solution. To be honest, the theme should use menu items fetched from wwp admin bar account node and not the BuddyPress component.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 71
    Lefteris on #46776

    Hello Brajesh,

    Thank you very much for your help. I do appreciate your time 🙂
    I think i will just try to hide the tab with some css for the unwanted roles.

    Best Regards,
    Lefteris

  • Keymaster
    (BuddyDev Team)
    Posts: 24075
    Brajesh Singh on #46780

    Thank you.

The topic ‘ [Resolved] Create a tab (nav_item) that can display custom post type items of user.’ is closed to new replies.

This topic is: resolved