本文介绍了如何拥有多个“主题选项” OptionTree页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
()允许非常简单地为主题创建 主题选项页面。
OptionTree (GitHub) allows to create a "Theme Options" page for themes very simply.
如何扩展OptionTree以便为我的插件创建一个 插件选项页面?
How could I extend OptionTree in order to create a "Plugin Options" page for my plugin?
谢谢!
推荐答案
实际上非常简单。以下代码将在设置页面下创建一个名为 Test Page 的页面。这就是OptionTree创建自己的页面的方式。
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' => ''
)
)
)
)
)
)
);
}
}
这篇关于如何拥有多个“主题选项” OptionTree页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!