BuddyDev

Search

Disabling WordPress Admin Bar except Buddypress Notifications

Tagged: ,

  • Participant
    Level: Initiated
    Posts: 15
    Kerem Erdal on #17876

    Hi,

    Is there a way to diasble wordpress admin bar except buddypress notifications? I know that buddypress notifications and profile section is in the wordpress top bar. However, I want users can take the notifications and see the “Hello username” menu which includes settings, groups etc. But, i don’t want them to access wordpress backend area which is wp-admin area. I want them to see only notifications and “Hello username” menu. Is it possible? If so, how can i achieve that?

    Thanks,
    Kerem

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #17885

    Hi Kerem,

    Thank you for asking.

    Please use the following code

    
    
    /**
     * Disable all items from adminbar except the BuddyPress User Menu and notifications for the logged in user.
     */
    function buddydev_remove_adminbar_items() {
    	global $wp_admin_bar;
    
    	if ( ! is_user_logged_in() || ! is_admin_bar_showing() ) {
    		return;
    	}
    
    	$nodes = $wp_admin_bar->get_nodes();
    
    	if ( empty( $nodes ) ) {
    		return;
    	}
    
    	foreach ( $nodes as $node_id => $node ) {
    		if ( $node->parent ) {
    			continue;// we will only remove top leel nodes.
    		}
    
    		if ( 'top-secondary' !== $node_id ) {
    			$wp_admin_bar->remove_node( $node_id );
    		}
    	}
    
    	// Comment this line to keep search in the admin bar.
    	$wp_admin_bar->remove_node( 'search' );
    
    }
    
    add_action( 'wp_before_admin_bar_render', 'buddydev_remove_adminbar_items', 2000001 );
    
    

    That will do it.

  • Participant
    Level: Initiated
    Posts: 15
    Kerem Erdal on #17906

    Hi Brajesh,

    Thank you very much for the code. Now, at the right top of the page there is notification and hello username menu. I want exactly this appereance. However, when i click on four sections from top to down(hello username, profile picture, username and edit my profile except log out) it forwards user to wp-admin/profile.php adress. I want exactly this apperance(notifications and hello username menu) but i don’t want a backend forwarding link in hello username, profile picture username and edit my profile. In other words, i don’t want them to access wp-admin/profile.php adress in any situation. This appereance without the backend forwarding to wp-admin/profile.php is the exact thing that i want. Is it possible? If so, can you send me the code?

    Sorry for the long explanation i just wanted to clarify what i want.

    Thanks,

    Kerem

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #17916

    Hi Kerem,
    Most probably either you are checking from the dashboard or the Profile component is disabled on your site.

    Those are the only cases when BuddyPress profile links to admin.

    Also, if you want to restrict users, you should look at a admin restriction plugin. The above code does not restrict anyone. It simply cleans up the links.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved