How to have more than one “Theme Options” page with OptionTree?

北城以北 提交于 2019-12-10 11:09:58

问题


OptionTree (GitHub) allows to create a "Theme Options" page for themes very simply.

How could I extend OptionTree in order to create a "Plugin Options" page for my plugin?

Thank you!


回答1:


It's actually pretty simple. The following code will create a page under the settings page called Test Page. This is how OptionTree creates its own pages.

/**
 * Hook to register admin pages 
 */
add_action( 'init', 'register_options_pages' );

/**
 * Registers all the required admin pages.
 */
function register_options_pages() {

  // Only execute in admin & if OT is installed
  if ( is_admin() && function_exists( 'ot_register_settings' ) ) {

    // Register the pages
    ot_register_settings( 
      array(
        array( 
          'id'              => 'custom_options',
          'pages'           => array(
            array(
              'id'              => 'test_page',
              'parent_slug'     => 'options-general.php',
              'page_title'      => 'Test Page',
              'menu_title'      => 'Test Page',
              'capability'      => 'edit_theme_options',
              'menu_slug'       => 'test-page',
              'icon_url'        => null,
              'position'        => null,
              'updated_message' => 'Test Page updated.',
              'reset_message'   => 'Test Page reset.',
              'button_text'     => 'Save Changes',
              'show_buttons'    => true,
              'screen_icon'     => 'options-general',
              'contextual_help' => null,
              'sections'        => array(
                array(
                  'id'          => 'test_section',
                  'title'       => __( 'Test Section', 'motif-core' )
                )
              ),
              'settings'        => array(
                array(
                  'id'          => 'test_section_input',
                  'label'       => 'Test Input',
                  'desc'        => 'Pretty freaking awesome!',
                  'std'         => '',
                  'type'        => 'text',
                  'section'     => 'test_section',
                  'class'       => ''
                )
              )
            )
          )
        )
      )
    );

  }

}


来源:https://stackoverflow.com/questions/18414823/how-to-have-more-than-one-theme-options-page-with-optiontree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!