Moving the Admin Menu

Since version 2.0.3 of The Permalinks Cascade, moving the plugin's administration menu to one of the WordPress' core admin menus is attainable by adding just three lines of code to your theme's functions.php file:

if ( is_admin() ) {
    // Moves the plugin's admin menu to the 'Tools' menu of WordPress. 
    add_filter( 'tpc_admin_page_parent_slug', function() { return 'tools.php'; } );
}

The tpc_admin_page_parent_slug filter hook is triggered only when an admin page of The Permalinks Cascade is in the making.

The above code sample will produce the following result:

The WordPress' admin menus before and after the rearrangement.
The WordPress' admin menus before and after the rearrangement.

Each Admin Page Accessible from a Distinct Menu

Rearranging the administration menu is mostly a matter of personal preference, that's why it may happen that you don't want all the administration pages to be accessible from the same menu, but instead that each of them is accessible from a specific menu of WordPress. To achieve that, the callback of the filter hook needs to choose the value to return according to which administration page is being created:

if ( is_admin() ) {
    /**
     * Moves the plugin's dashboard menu item to the main 
     * 'Dashboard' menu and the other plugin's menu items 
     * to the 'Settings' menu of WordPress.
     * 
     * @param string $parent_slug   The slug of the default 
     *                              parent admin page.
     * @param string $admin_page_id ID of the admin page that is
     *                              being created.
     * @return string
     */ 
    function my_rearrange_admin_menu( $parent_slug, $admin_page_id ) {
        if ( 'dashboard' == $admin_page_id ) {
            $parent_slug = 'index.php';
        }
        else {
            $parent_slug = 'options-general.php';
        }

        return $parent_slug;
    }
    add_filter( 'tpc_admin_page_parent_slug', 'my_rearrange_admin_menu', 10, 2 );
}
Last update: