Custom Fields
Re-Envisioned
Support MB Settings Page Adding submenu to Metabox settings page replacing parent menu

This topic contains 1 reply, has 2 voices, and was last updated by  Anh Tran 6 months, 2 weeks ago.

  • Creator
    Topic
  • #12425
    Resolved
    Aishwarya
    Participant

    I trying to add an Import and export function to my settings page. First, I have created settings page with Metabox plugin using following code

    // Register myplugin settings page
    add_filter( 'mb_settings_pages', 'myplugin_options_page' );
    function myplugin_options_page( $settings_pages ) {
        $settings_pages[] = array(
            'id'          => 'myplugin_settings',
            'option_name' => 'myplugin_settings',
            'menu_title'  =>  'Plugin settings',
            'icon_url'    => 'dashicons-edit',
            'style'       => 'boxes',
            'columns'     => 1,
            'capability'  => 'edit_theme_options',
            'tabs'        => array(
              'settings_tab' => esc_html__('Settings', 'myplugin'),
              'help'     => esc_html__('Help', 'myplugin'),
            ),
            'position'    => 68,
        );
        $settings_pages[] = array(
            'id'          => 'myplugin-export',
            'option_name' => 'myplugin-export,
            'menu_title'  => esc_html__('Export settings', 'myplugin'),
            'parent'      => 'myplugin_settings',
            'style'       => 'boxes',
            'columns'     => 1,
            'capability'  => 'edit_theme_options',
        );
        return $settings_pages;
    }

    As metabox plugin doesn’t have settings import feature I am trying to add a custom page for importing and tried to add a sub menu inside the Parent menu created with the Metabox plugin with the menu slug ‘myplugin_settings’.

    add_action('admin_menu', 'add_import_menu');
    function add_import_menu() {
      add_submenu_page( 'myplugin_settings', 'Import settings', 'Import settings', 'edit_theme_options', 'new-submenu', 'plugin_submenu_page' );
    }

    This is replacing the parent menu “Plugin settings” (‘myplugin_settings’) with Import settings. Not sure what I am doing wrong.

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #12440

    Anh Tran
    Keymaster

    Hi,

    When you create a top-level settings page, make sure you create a sub-menu for the settings first. The first sub-menu will be used for the top-level menu. That’s the default behavior in WordPress.

    So make sure your custom page is added after all settings page (top-menu and sub-menu) are added.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.