Wordpress定制器自定义控件传输postMessage无法正常工作

问题描述 投票:3回答:1

我正在构建一个WordPress主题,需要在自定义程序中添加自定义controls,输入字段显示但是当我更改输入值时没有任何反应。

这是我的代码。

class WP_Customize_Custom_Control extends WP_Customize_Control {
  public $type = 'custom_control';

  function render_content(){
  }
  public function content_template() {
    ?>
    <input type="text" id="custom_control" name="custom_control" />
    <?php
  }
}

function company_customize_register( $wp_customize ){
  $wp_customize->register_control_type( 'WP_Customize_Custom_Control' );
  $wp_customize->add_setting('custom_smthing', array( 'default' => get_theme_mod( "custom_smthing" ), 'transport' =>'postMessage' ) );
  $wp_customize->add_control(new WP_Customize_Custom_Control($wp_customize,'custom_smthing',
    array(
      'label'      => __( 'Custom Control', 'company' ),
      'section'    => 'body_backgrounds',
      'settings'   => 'custom_smthing',
     )
   )
  );
}
add_action( 'customize_register', 'company_customize_register' );

和js是

( function( $ ) {
  console.log("test1");
  wp.customize( 'custom_smthing', function( value ) {
    console.log("test2");
    value.bind( function( to ) {
      console.log("test3");
    } );
  });
})( jQuery );

test1和test2正在运行,但test3从未触发。

javascript php jquery wordpress wordpress-theming
1个回答
0
投票

test3只会在custom_smthing的值发生变化时触发。

© www.soinside.com 2019 - 2024. All rights reserved.