Created
November 20, 2017 20:26
-
-
Save westonruter/dcdef485f91b5782b30521009b071078 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// @todo The following does not work. | |
add_action( 'customize_register', function( WP_Customize_Manager $wp_customize ) { | |
$choices = array( | |
'foo' => __( 'Foo' ), | |
'bar' => __( 'Bar' ), | |
'baz' => __( 'Baz' ), | |
); | |
$wp_customize->add_setting( 'favorite_meta_vars', array( | |
'sanitize_callback' => function( $values ) use ( $choices ) { | |
if ( ! is_array( $choices ) ) { | |
return new WP_Error( 'invalid_value_type', __( 'Invalid value type.', '...' ) ); | |
} | |
$allowed_options = array_keys( $choices ); | |
$values = array_values( $values ); | |
foreach ( $values as $value ) { | |
if ( in_array( $value, $allowed_options, true ) ) { | |
return new WP_Error( 'illegal_value', __( 'Illegal value.', '...' ) ); | |
} | |
} | |
return $values; | |
}, | |
) ); | |
$wp_customize->add_control( 'favorite_meta_vars', array( | |
'label' => __( 'Favorite meta var(s)', '...' ), | |
'type' => 'select', | |
'choices' => $choices, | |
'setting' => 'favorite_meta_vars', | |
'section' => 'title_tagline', | |
'input_attrs' => array( // @todo The select control doesn't read from input_attrs. | |
'multiple' => true, | |
), | |
'multiple' => true, // @todo Support this. | |
) ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment