type ) { case 'bettercheckbox' : ?> label ) ) : ?> label ); ?> description ) ) : ?> description ; ?> sublabel ) ) : ?> sublabel ; ?> choices ) && is_array( $this->choices ) ) { $multi_values = ( !is_array( $this->value() ) ) ? explode( ',', $this->value() ) : $this->value(); $multi_values = array_map( 'trim', $multi_values ); foreach ( $this->choices as $value => $label ) : ?> link(); ?> value="" /> link(); checked( $this->value() ); ?> /> add_control( new Hoot_Customize_Bettercheckbox_Control( $wp_customize, $id, $setting ) ); } endif; } add_action( 'hoot_customizer_control_interface', 'hoot_customizer_bettercheckbox_control_interface', 10, 3 ); endif; /** * Modify the settings array and prepare bettercheckbox settings for Customizer Library Interface functions * * @since 2.0.0 * @param array $value * @param string $key * @param array $setting * @param int $count * @return void */ function hoot_customizer_prepare_bettercheckbox_settings( $value, $key, $setting, $count ) { if ( $setting['type'] == 'checkbox' ) { $setting['type'] = 'bettercheckbox'; $value[ $key ] = $setting; } return $value; } add_filter( 'hoot_customizer_prepare_settings', 'hoot_customizer_prepare_bettercheckbox_settings', 10, 4 ); /** * Add sanitization function * * @since 2.0.0 * @param string $name * @param string $type * @param array $setting * @return string */ function hoot_customizer_bettercheckbox_sanitization_function( $name, $type, $setting ) { if ( $type == 'bettercheckbox' ) { if ( !empty( $setting['choices'] ) && is_array( $setting['choices'] ) ) $name = 'hoot_customizer_sanitize_multicheckbox'; else $name = 'hoot_customizer_sanitize_checkbox'; } return $name; } add_filter( 'hoot_customizer_sanitization_function', 'hoot_customizer_bettercheckbox_sanitization_function', 5, 3 ); /** * Sanitize multicheckbox value to allow only allowed choices. * * @since 2.0.0 * @param string $value The unsanitized string. * @param mixed $setting The setting for which the sanitizing is occurring. * @return string The sanitized value. */ function hoot_customizer_sanitize_multicheckbox( $value, $setting ) { if ( is_object( $setting ) ) $setting = $setting->id; $choices = hoot_customizer_get_choices( $setting ); $multi_values = array_map( 'trim', explode( ',', $value ) ); $return = array(); foreach ( $multi_values as $key ) { if ( array_key_exists( $key, $choices ) ) $return[] = $key; } return implode( ',', $return ); }