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_customize_control_interface', 'hoot_customize_bettercheckbox_control_interface', 10, 3 ); endif; /** * Modify the settings array and prepare bettercheckbox settings for Customizer Library Interface functions * * @since 3.0.0 * @param array $value * @param string $key * @param array $setting * @param int $count * @return void */ function hoot_customize_prepare_bettercheckbox_settings( $value, $key, $setting, $count ) { if ( $setting['type'] == 'checkbox' ) { $setting['type'] = 'bettercheckbox'; $value[ $key ] = $setting; } return $value; } add_filter( 'hoot_customize_prepare_settings', 'hoot_customize_prepare_bettercheckbox_settings', 10, 4 ); /** * Add sanitization function * * @since 3.0.0 * @param string $callback * @param string $type * @param array $setting * @param string $name name (id) of the setting * @return string */ function hoot_customize_sanitize_bettercheckbox_callback( $callback, $type, $setting, $name ) { if ( $type == 'bettercheckbox' ) { if ( !empty( $setting['choices'] ) && is_array( $setting['choices'] ) ) $callback = 'hoot_sanitize_customize_multicheckbox'; else $callback = 'hoot_sanitize_checkbox'; } return $callback; } add_filter( 'hoot_customize_sanitize_callback', 'hoot_customize_sanitize_bettercheckbox_callback', 5, 4 ); /** * Sanitize multicheckbox value to allow only allowed choices. * * @since 3.0.0 * @param string $value The value to sanitize. * @param mixed $setting 'WP_Customize_Setting' Object (called by Customizer) or Setting Name (called by hoot_get_mod) * @return string The sanitized value. */ function hoot_sanitize_customize_multicheckbox( $value, $setting ) { $name = ''; if ( is_object( $setting ) ) $name = $setting->id; elseif ( is_string( $setting ) ) $name = $setting; $choices = hoot_customize_get_choices( $name ); return hoot_sanitize_multicheck( $value, $choices, true ); }