0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WordPressのカスタマイズ画面でのフォーム項目の出し分け active_callback

Posted at

これからはFSEの時代ですがまだカスタマイザも2年くらいは現役だろうなという事で覚書。

add_action( 'customize_register', 'lightning_customize_register_basic' );
function lightning_customize_register_basic( $wp_customize ) {

	$wp_customize->add_section(
		'lightning_basic',
		array(
			'title'    => __( 'Basic settings', 'lightning' ),
		)
	);
	$wp_customize->add_setting( 'demo_radio_control', array(
		'default'        => 'a',
	 ) );
	  
	 $wp_customize->add_control( 'demo_radio_control', array(
		'label'      => 'radio_control',
		'section'    => 'lightning_basic',
		'settings'   => 'demo_radio_control',
		'type'       => 'radio',
		'choices'    => array(
		'a' => 'Choice A',
		'b' => 'Choice B',
		),
	 ) );

	 $wp_customize->add_setting( 'choice_a_text', array(
		'default' => '',
	 ) );
	  
	 $wp_customize->add_control( 'choice_a_text', array(
		'label'      => 'Choice A: ',
		'section'    => 'lightning_basic',
		'type'       => 'text',
		'active_callback' => 'choice_a_callback',
	 ) );
	 function choice_a_callback( $control ) {
		if ( $control->manager->get_setting('demo_radio_control')->value() == 'a' ) {
		   return true;
		} else {
		   return false;
		}
	 }
}

参照
http://ottopress.com/2015/whats-new-with-the-customizer/

Special Thanks
@Toro_Unit

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?