我正在寻找一种向自定义实时预览面板添加新控件的方法。我已经看到了如何使用来向面板添加新部分
add_action( 'customize_register'...
我要实现的控件是另一种颜色选择器。在上一篇文章中,我们看到了如何扩展核心类以添加小部件,但是我在这里所缺少的是一个钩子,该钩子使我能够将对象带入范围-WP_Customize_Palette_Control。在
您可以在此处看到代码的开头。这段代码在functions.php
我主题的文件中。
谢谢你的帮助。抢
刚刚更新了代码。现在我必须require_once
上课。所以现在我没有PHP错误,但是我的新控件HTML没有出现。
<?php
require_once( ABSPATH . WPINC . '/class-wp-customize-setting.php' );
require_once( ABSPATH . WPINC . '/class-wp-customize-section.php' );
require_once( ABSPATH . WPINC . '/class-wp-customize-control.php' );
class WP_Customize_Palette_Control extends WP_Customize_Image_Control {
public $type = 'palette';
public $removed = '';
public $context;
public function enqueue() {
//wp_enqueue_script( 'wp-plupload' );
}
public function to_json() {
parent::to_json();
$this->json['removed'] = $this->removed;
if ( $this->context )
$this->json['context'] = $this->context;
}
public function render_content() {
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<div>
<a href="#" class="button-secondary upload"><?php _e( 'Upload' ); ?></a>
<a href="#" class="remove"><?php _e( 'Remove' ); ?></a>
</div>
</label>
<?php
}
}
//new WP_Customize_Palette_Control();
//add_action('customize_controls_init', 'WP_Customize_Palette_Control');
// add an option to the customize panel
function sci_customize_controls_init($wp_customize) {
$wp_customize->add_section( 'themename_color_scheme', array(
'title' => __( 'Color Scheme', 'themename' ),
'priority' => 35,
) );
$wp_customize->add_setting( 'themename_theme_options[color_scheme]', array(
'default' => 'some-default-value',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'themename_color_scheme', array(
'label' => __( 'Color Scheme', 'themename' ),
'section' => 'themename_color_scheme',
'settings' => 'themename_theme_options[color_scheme]',
'type' => 'palette',
'choices' => array(
'value1' => 'Choice 1',
'value2' => 'Choice 2',
'value3' => 'Choice 3',
),
) );
}
add_action( 'customize_register', 'sci_customize_controls_init' );