I installed a plugin for my users in WPMU and I want to make it appear at the end of the admin menu ….

I tried this but the menu never appears at the end:

function custom_menu_order($menu_ord) {  
if (!$menu_ord) return true;  

return array(  
    'index.php', // Dashboard  
    'edit.php', // Posts 
    'upload.php', // Media
    'options-general.php', // Settings  
 => 'admin.php?page=support', // my plugin

);
}  
add_filter('custom_menu_order', 'custom_menu_order'); // Activate custom_menu_order  
add_filter('menu_order', 'custom_menu_order');

my plugin menu is “admin.php?page=support”

2 Answers
2

The global variable $menu can be manipulated. Here, we are moving the Pages menu item to the end:

moved pages to the end of the menu

Maybe there’s a simpler method to do the recursive array search, I’ve grabbed an example from PHP Manual. The value to be searched has to be inspected inside the $menu var, enable the debug lines to brute force inspect it.

add_action( 'admin_menu', 'move_menu_item_wpse_94808', 999 );

function move_menu_item_wpse_94808() 
{
    global $menu;

    // Inspect the $menu variable:
    // echo '<pre>' . print_r( $menu, true ) . '</pre>';
    // die();

    // Pinpoint menu item
    $move = recursive_array_search_php_91365( 'edit.php?post_type=page', $menu );

    // Validate
    if( !$move )
        return;

    // Store menu item
    $new = $menu[ $move ];

    // Remove menu item, and add previously stored at the end
    unset( $menu[ $move ] );
    $menu[] = $new;
}

// http://www.php.net/manual/en/function.array-search.php#91365
function recursive_array_search_php_91365( $needle, $haystack ) 
{
    foreach( $haystack as $key => $value ) 
    {
        $current_key = $key;
        if( 
            $needle === $value 
            OR ( 
                is_array( $value )
                && recursive_array_search_php_91365( $needle, $value ) !== false 
            )
        ) 
        {
            return $current_key;
        }
    }
    return false;
}

Leave a Reply

Your email address will not be published. Required fields are marked *