0

Here is my plugin's current menu/submenu structure:

add_menu_page('Sunshine', 'Sunshine', 'sunshine_manage_options', 'sunshine_admin', 'sunshine_dashboard_display', plugins_url( 'assets/images/sunshine-icon.png' , $plugin_dir_path ));
add_submenu_page('sunshine_admin', __('Dashboard','sunshine'), __('Dashboard','sunshine'), 'sunshine_manage_options',  'sunshine_admin', 'sunshine_dashboard_display');
add_submenu_page('sunshine_admin', __('Settings','sunshine'),  __('Settings','sunshine'), 'sunshine_manage_options', 'admin.php?page=sunshine');

$sunshine_admin_submenu = array();
$sunshine_admin_submenu[10] = array(__('Galleries','sunshine'), __('Galleries','sunshine'), 'sunshine_manage_options', 'edit.php?post_type=sunshine-gallery');
$sunshine_admin_submenu[20] = array(__('Product Categories','sunshine'), __('Product Categories','sunshine'), 'sunshine_manage_options', 'edit-tags.php?taxonomy=sunshine-product-category&post_type=sunshine-product');
$sunshine_admin_submenu[30] = array(__('Products','sunshine'), __('Products','sunshine'), 'sunshine_manage_options', 'edit.php?post_type=sunshine-product');
$sunshine_admin_submenu[40] = array(__('Orders','sunshine'), __('Orders','sunshine'), 'sunshine_manage_options', 'edit.php?post_type=sunshine-order');
$sunshine_admin_submenu = apply_filters('sunshine_admin_menu', $sunshine_admin_submenu);
ksort($sunshine_admin_submenu);
foreach ($sunshine_admin_submenu as $item) {
    add_submenu_page('sunshine_admin', $item[0], $item[1], $item[2], $item[3], $item[4]);
}

I apply a filter on the submenus because I have addons for my plugin which can add additional submenu items.

My issues arise with the "Settings" page and "Product Categories" taxonomy

When you click on "Settings" tab or "Product Categories" taxonomy, my main Sunshine menu does not open up to reveal all the submenu options. If I click on "Galleries", it shows just fine with all the submenu items visible and "Galleries" highlighted in white/bold.

I did some searching and found a support topic which lead me to implement the following:

function sunshine_submenu_show_fix($parent_file) {
    global $current_screen;
    $taxonomy = $current_screen->taxonomy;
    if ($taxonomy == 'sunshine-product-category')
        $parent_file = 'sunshine_admin';
    return $parent_file;
}
add_action('parent_file', 'sunshine_submenu_show_fix');

This sort of gets there, when clicking on "Product Categories" all the submenu items are now visible but "Product Categories" itself is not bold/white like "Galleries".

My goal here is to be able to click on "Settings" or "Product Categories" and have the "Sunshine" submenu items all visible and the respective page show in white/bold.

1

Try it:

function sunshine_submenu_show_fix($parent_file) {
    global $plugin_page;
    $taxonomy = $current_screen->taxonomy;
    if ($taxonomy == 'sunshine-product-category')
        $plugin_page = 'sunshine_admin';
    return $parent_file;
}
add_action('parent_file', 'sunshine_submenu_show_fix');

explanation:

in file /wp-admin/menu-header.php:

$parent_file = apply_filters( 'parent_file', $parent_file );

get_admin_page_parent();
...
function _wp_menu_output(...) {
...
        if ( ( $parent_file && $item[2] == $parent_file ) || ( empty($typenow) && $self == $item[2] ) ) {
        $class[] = ! empty( $submenu_items ) ? 'wp-has-current-submenu wp-menu-open' : 'current';
...
                } else if (
                ( ! isset( $plugin_page ) && $self == $sub_item[2] ) ||
                ( isset( $plugin_page ) && $plugin_page == $sub_item[2] && ( $item[2] == $self_type || $item[2] == $self || file_exists($menu_file) === false ) )
            ) {
                $class[] = 'current';
            }
...
}

in file /wp-admin/includes/plugin.php:

...
function get_admin_page_parent( $parent = '' ) {
...
            if ( $parent_menu[2] == $plugin_page ) {
            $parent_file = $plugin_page;
...
            if ( isset( $plugin_page ) && ($plugin_page == $submenu_array[2] ) ) {
                $parent_file = $parent;
...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.