有没有办法让这些子菜单一直可见? (WordPress 管理菜单栏)

问题描述 投票:0回答:0

WordPress 6.2 The Wordpress admin bar problem.

当我点击仪表板时,它会停留在那里,但当我向下移动时,它会从管理栏中消失。我怎样才能防止这种情况发生?

这是我为它写的函数:

function createPages(): void {
        // ======= Declaring Variables =======
        // Classes
        $license = new OGLicense();
        $postTypeData = new OGPostTypeData();
        // Vars
        $boolPluginActivated = $license->checkActivation();
        $objectAccess = $license->checkPostTypeAccess();

        // Making the Global Settings Page
        add_menu_page(
            'Admin Settings',
            'OG Settings',
            'manage_options',
            'pixelplus-og-plugin-settings',
            array($this, 'HTMLOGAdminSettings'),
            'dashicons-admin-generic',
            101
        );
        add_submenu_page(
            'pixelplus-og-plugin-settings',
            'Algemeen',
            'Algemeen',
            'manage_options',
            'pixelplus-og-plugin-settings',
            array($this, 'HTMLOGAdminSettings')
        );

        // ======= When Plugin is activated =======
        if ($boolPluginActivated) {
            // ==== OG Settings ====
            // Submenu Items based on the OG Post Types for in the OG Settings
            foreach ($postTypeData->customPostTypes as $postType => $postTypeArray) {
                if (in_array($postType, $objectAccess)) {
                    $name = $postTypeArray['post_type_args']['labels']['menu_name'];
                    // Creating submenu for in the OG Settings
                    add_submenu_page(
                        'pixelplus-og-plugin-settings',
                        $name,
                        $name,
                        'manage_options',
                        'pixelplus-og-plugin-settings-' . strtolower($name),
                        array($this, 'HTMLOGAdminSettings'.$name)
                    );
                }
            }

            // ==== Items OG Admin ====
            // Menu Item: OG Dashboard
            add_menu_page(
                'Admin Dashboard',
                'OG Admin Dashboard',
                'manage_options',
                'pixelplus-og-plugin',
                array($this, 'HTMLOGAdminDashboard'),
                'dashicons-plus-alt',
                100);
            // First sub-menu item name change
            add_submenu_page(
                'pixelplus-og-plugin',
                'Admin Dashboard',
                'Dashboard',
                'manage_options',
                'pixelplus-og-plugin',
                array($this, 'HTMLOGAdminDashboard'));

            // ==== Items OG Aanbod ====
            // Menu Item: OG Aanbod Dashboard
            add_menu_page(
                'OG Aanbod',
                'OG Aanbod',
                'manage_options',
                'pixelplus-og-plugin-aanbod',
                array($this, 'HTMLOGAanbodDashboard'),
                'dashicons-admin-multisite',
                40);
            // First sub-menu item name change
            add_submenu_page(
                'pixelplus-og-plugin-aanbod',
                'Aanbod Dashboard',
                'Dashboard',
                'manage_options',
                'pixelplus-og-plugin-aanbod',
                array($this, 'HTMLOGAanbodDashboard'));
            // Submenu Items based on the OG Post Types for in the OG Aanbod
            foreach ($postTypeData->customPostTypes as $postType => $postTypeArray) {
                // Creating submenu for in the OG Aanbod
                if (in_array($postType, $objectAccess)) {
                    add_submenu_page(
                        'pixelplus-og-plugin-aanbod',
                        $postTypeArray['post_type_args']['labels']['menu_name'],
                        $postTypeArray['post_type_args']['labels']['menu_name'],
                        'manage_options',
                        'edit.php?post_type=' . $postType
                    );
                }
            }
        }
    }

负责此特定菜单/子菜单的部分是底部。但这里只是为了效率:

// Menu Item: OG Aanbod Dashboard
add_menu_page(
    'OG Aanbod',
    'OG Aanbod',
    'manage_options',
    'pixelplus-og-plugin-aanbod',
    array($this, 'HTMLOGAanbodDashboard'),
    'dashicons-admin-multisite',
    40);
// First sub-menu item name change
add_submenu_page(
    'pixelplus-og-plugin-aanbod',
    'Aanbod Dashboard',
    'Dashboard',
    'manage_options',
    'pixelplus-og-plugin-aanbod',
    array($this, 'HTMLOGAanbodDashboard'));
// Submenu Items based on the OG Post Types for in the OG Aanbod
foreach ($postTypeData->customPostTypes as $postType => $postTypeArray) {
    // Creating submenu for in the OG Aanbod
    if (in_array($postType, $objectAccess)) {
        add_submenu_page(
            'pixelplus-og-plugin-aanbod',
            $postTypeArray['post_type_args']['labels']['menu_name'],
            $postTypeArray['post_type_args']['labels']['menu_name'],
            'manage_options',
            'edit.php?post_type=' . $postType
        );
    }
}

我已经尝试给子菜单起不同的名字,以防我干扰其他菜单/子菜单。

我认为这个问题与我使用 edit.php?post_type= 而不是普通链接有关。但我以前有过这个工作,所以我不确定。

如果你们能帮助我,那就太棒了:)

干杯,

乔迪

php wordpress custom-wordpress-pages wordpress-plugin-creation
© www.soinside.com 2019 - 2024. All rights reserved.