• Hi,

    I need to add my own submenu just below the “your profile” submenu and I succeeded for admin users but not for simple users.
    for admin, the following naturally works
    add_submenu_page('users.php','biographie', 'bio', 10, __FILE__, 'get_bio_link');
    bu not for simple users because their “your profile” submenu is not under the “users” menu but under a “profile” menu as shown in the menu.php in the admin folder of WP
    ligne 91:

    if ( current_user_can('edit_users') ) {
    $_wp_real_parent_file['profile.php'] = 'users.php'; // Back-compat for plugins adding submenus to profile.php.
    $submenu['users.php'][5] = array(__('Authors & Users'), 'edit_users', 'users.php');
    $submenu['users.php'][10] = array(__('Add New'), 'create_users', 'user-new.php');
    $submenu['users.php'][15] = array(__('Your Profile'), 'read', 'profile.php');
    } else {
    $_wp_real_parent_file['users.php'] = 'profile.php';
    $submenu['profile.php'][5] = array(__('Your Profile'), 'read', 'profile.php');
    }

    therefore I try to use add_submenu_page('profile.php','biographie', 'bio', 10, __FILE__, 'get_bio_link');
    but this doesn’t work: My submenu does not appear anywhere ! ??

    any ideas ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • Both these pieces of code..

    add_submenu_page('profile.php','biographie', 'bio', 10, __FILE__, 'get_bio_link');
    
    add_submenu_page('users.php','biographie', 'bio', 10, __FILE__, 'get_bio_link');

    Use a capability requirement of 10, which i can only assumes translates to level_10 (old style capability checking).

    Firstly, user levels are old and deprecated now, use a capbility instead(edit_users,edit_posts,whatever).
    Second, it’s also the reason the code doesn’t work, anyone below admin is not level 10.

    Ammend the 10 for a capability and your menu item will appear.. ??

    Thread Starter dimple75018

    (@dimple75018)

    silly me !!!
    i wasn’t paying attention properly on this one !

    many thanks for the help ??

    Happy to help.. ??

    theshae

    (@theshae)

    I am trying to add a submenu item to the profiles menu that links to an external link. I am able to get it to work under a menu like users. Here is the code I am using:

    add_action( 'admin_menu' , 'admin_menu_new_items' );
    function admin_menu_new_items() {
        global $submenu;
        $submenu['users.php'][500] = array( 'Return to HomePage', 'manage_options' , 'https://www.utilityupgradeproject.com' );
    }

    changing ‘users.php’ to ‘profile.php’ does not work.

    Any ideas?

    You’re setting the requirement for the menu item to manage_options, it’s only visible to admins, all of whom will have the users.php as the parent item for the users menu, profile.php is only the parent item when the user viewing the admin page is not able to edit users.

    Basically, depending on the role of the logged in user, the parent item will differ depending on the capaiblities of the given user(but this a moot point anyway, because your new item has manage_options as the required capability, only admins could ever possibly see it).

    theshae

    (@theshae)

    Ahhh, got it. Thanks for the help!

    This is the code I used:

    add_action( 'admin_menu' , 'admin_menu_new_items' );
    function admin_menu_new_items() {
        global $submenu;
        $submenu['profile.php'][500] = array( 'Return to HomePage', 'read' , 'https://www.utilityupgradeproject.com' );
    }

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘how to add sub-menu in the sidebar admin profile menu for simple users’ is closed to new replies.