Last active
August 29, 2015 14:27
-
-
Save brettsmason/8e84257ea2c912af6df3 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 | |
/** | |
* Multiple checkbox customize control class. | |
* | |
* @since 1.0.0 | |
* @access public | |
*/ | |
class JT_Customize_Control_Checkbox_Multiple extends WP_Customize_Control { | |
/** | |
* The type of customize control being rendered. | |
* | |
* @since 1.0.0 | |
* @access public | |
* @var string | |
*/ | |
public $type = 'checkbox-multiple'; | |
/** | |
* Enqueue scripts/styles. | |
* | |
* @since 1.0.0 | |
* @access public | |
* @return void | |
*/ | |
public function enqueue() { | |
wp_enqueue_style( 'control-checkbox-multiple', trailingslashit( get_template_directory_uri() ) . 'includes/customizer/controls/control-checkbox-multiple/control-checkbox-multiple.css' ); | |
wp_enqueue_script( 'control-checkbox-multiple', trailingslashit( get_template_directory_uri() ) . 'includes/customizer/controls/control-checkbox-multiple/control-checkbox-multiple.js', array('jquery', 'jquery-ui-sortable'), '', true ); | |
} | |
/** | |
* Displays the control content. | |
* | |
* @since 1.0.0 | |
* @access public | |
* @return void | |
*/ | |
public function render_content() { | |
if ( empty( $this->choices ) ) | |
return; ?> | |
<?php if ( !empty( $this->label ) ) : ?> | |
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> | |
<?php endif; ?> | |
<?php if ( !empty( $this->description ) ) : ?> | |
<span class="description customize-control-description"><?php echo $this->description; ?></span> | |
<?php endif; ?> | |
<?php $multi_values = !is_array( $this->value() ) ? explode( ',', $this->value() ) : $this->value(); ?> | |
<ul> | |
<?php foreach ( $this->choices as $value => $label ) : ?> | |
<li id="<?php echo esc_attr( $value ); ?>"> | |
<label> | |
<input type="checkbox" value="<?php echo esc_attr( $value ); ?>" <?php checked( in_array( $value, $multi_values ) ); ?> /> | |
<?php echo esc_html( $label ); ?> | |
</label> | |
<i class='dashicons dashicons-menu'></i> | |
</li> | |
<?php endforeach; ?> | |
</ul> | |
<input type="text" <?php $this->link(); ?> value="<?php echo esc_attr( implode( ',', $multi_values ) ); ?>" /> | |
<?php } | |
} | |
function jt_sanitize_favorite_fruit( $values ) { | |
$multi_values = !is_array( $values ) ? explode( ',', $values ) : $values; | |
return !empty( $multi_values ) ? array_map( 'sanitize_text_field', $multi_values ) : array(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment