douyi4991 2013-08-24 04:08
浏览 98
已采纳

如何在OptionTree中拥有多个“主题选项”页面?

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条回答 默认 最新

  • dsfh40613182 2013-09-11 15:38
    关注

    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'       => ''
                    )
                  )
                )
              )
            )
          )
        );
    
      }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计