如何从头(panel)到尾(setting)添加一个自定义选项(Customize-Options)(草稿)
准备工作:
1)在functions.php添加如下代码
2)添加钩子及相关主函数
3)准备好一些净化函数
在functions.php添加如下代码:
include ONEPAGE_DIR . 'includes/customizer/customizer.php'; include ONEPAGE_DIR . 'includes/customizer/onepage-sanitize.php';
添加钩子及相关主函数:
// Setup the Theme Customizer settings and controls... add_action('customize_register', 'Cube_Register');
function Cube_Register($wp_customize) {
……
}
function Cubethemes_registers() { …… } add_action('customize_controls_enqueue_scripts', 'Cubethemes_registers');
净化函数:
添加面板(Panel)
$wp_customize->add_panel(
'Cube_theme_setting',
array( 'title' => __('Theme Settings', 'one-page'), 'description' => __('Allows you to configure Cube Theme.', 'one-page'), //Descriptive tooltip 'priority' => '9', 'capability' => 'edit_theme_options' ) );
添加部件(Section)
$wp_customize->add_section( 'Cube_theme_general_settings', array( 'title' => __('General Settings', 'one-page'), 'description' => __('Allows you to set general settings for Cube Theme.', 'one-page'), //Descriptive tooltip 'panel' => 'Cube_theme_setting', 'priority' => '10', 'capability' => 'edit_theme_options' ) ); $wp_customize->add_section( 'Cube_theme_custom_settings', array( 'title' => __('Custom Settings', 'one-page'), 'description' => __('Allows you to apply your own custom codes in Cube Theme.', 'one-page'), //Descriptive tooltip 'panel' => 'Cube_theme_setting', 'priority' => '11', 'capability' => 'edit_theme_options' ) );
添加设置项(Settings)
$wp_customize->add_setting( $settings_control[$control_id]['setting_id'], array( 'default' => $settings_control[$control_id]['setting_default'], 'capability' => 'edit_theme_options', 'sanitize_callback' => 'onepage_sanitize_editor', 'type' => $settings_control[$control_id]['setting_type'] ) );