Skip to:

How to reduce user’s view on groups only to his owns

  • JanDieckmann


    The setting is that users are only created by the admins and can’t join or leave groups by themselves.

    That is why I would like to remove the All groups tab on the http://…/groups/ page for all non admins. Would it be enough to set a display:none if a user is not admin?

    Additionally I would like to have a navigation menu link that leads directly to http://…/members/*username*/groups/my-groups/. So I am looking for way to build a menu link depending on the username.

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

  • JanDieckmann


    I finally succeed in creating the dynamic menu link. I’ve taken a part of code that was made to create an entry in the menu for the latest post and modified it in a way that it obviously works:

    // Front end only, don't hack on the settings page
    if ( ! is_admin() ) {
        // Hook in early to modify the menu
        // This is before the CSS "selected" classes are calculated
        add_filter( 'wp_get_nav_menu_items', 'replace_placeholder_nav_menu_item_with_mygroups', 10, 3 );
    // Replaces a custom URL placeholder with the URL to mygroups
    function replace_placeholder_nav_menu_item_with_mygroups( $items, $menu, $args ) {
            $key = 'http://#mygroups:';
    	global $current_user;
        // Loop through the menu items looking for placeholder(s)
        foreach ( $items as $item ) {
            // Is this the placeholder we're looking for?
            if ( 0 === strpos( $item->url, $key ) )
    	// Get the username
            $username = $current_user->user_login;
            if ( empty( $username ) )
            // Replace the placeholder with the real URL
            $item->url = '' . $username . '/groups/my-groups/';
        // Return the modified (or maybe unmodified) menu items array
        return $items;

    If some one with more experience and knowledge sees problems with security or performance I am glad to learn how to change this code.



    Try this, untested:

    function jan_add_nav_menu_items( $items, $args ) {
        if ( is_user_logged_in() ) 
    	$items .= '<li><a href="' . bp_loggedin_user_domain() . '/groups/">My Groups</a></li>';
        return $items;
    add_filter( 'wp_nav_menu_items', 'jan_add_nav_menu_items', 10, 2 );



    Still works good what I have put together there.

    Even if your suggestion looks much easier and more compact, I wonder how to determinate the position in the menu?



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