array(), ); /* * Display for options and meta */ public function display() { $this->echoOptionHeader( true ); echo "
"; $savedValue = $this->cleanValueForGetting( $this->getValue() ); if ( empty( $savedValue ) ) { $savedValue = array(); } foreach ( $this->settings['options'] as $value => $label ) { printf('
', $this->getID() . $value, $this->getID() . $value, $this->getID(), esc_attr( $value ), checked( in_array( $value, $savedValue ), true, false ), $label ); } echo "
"; $this->echoOptionFooter( false ); } public function cleanValueForSaving( $value ) { if ( empty( $value ) ) { return array(); } if ( is_serialized( $value ) ) { return $value; } // CSV if ( is_string( $value ) ) { $value = explode( ',', $value ); } return serialize( $value ); } public function cleanValueForGetting( $value ) { if ( empty( $value ) ) { return array(); } if ( is_array( $value ) ) { return $value; } if ( is_serialized( $value ) ) { return unserialize( $value ); } if ( is_string( $value ) ) { return explode( ',', $value ); } } /* * Display for theme customizer */ public function registerCustomizerControl( $wp_customize, $section, $priority = 1 ) { $wp_customize->add_control( new TitanFrameworkOptionMulticheckControl( $wp_customize, $this->getID(), array( 'label' => $this->settings['name'], 'section' => $section->settings['id'], 'settings' => $this->getID(), 'description' => $this->settings['desc'], 'options' => $this->settings['options'], 'priority' => $priority, ) ) ); } } /* * WP_Customize_Control with description */ add_action( 'customize_register', 'registerTitanFrameworkOptionMulticheckControl', 1 ); function registerTitanFrameworkOptionMulticheckControl() { class TitanFrameworkOptionMulticheckControl extends WP_Customize_Control { public $description; public $options; private static $firstLoad = true; // Since theme_mod cannot handle multichecks, we will do it with some JS public function render_content() { // the saved value is an array. convert it to csv if ( is_array( $this->value() ) ) { $savedValueCSV = implode( ',', $this->value() ); $values = $this->value(); } else { $savedValueCSV = $this->value(); $values = explode( ',', $this->value() ); } if ( self::$firstLoad ) { self::$firstLoad = false; ?> description ) ) { $description = "

" . $this->description . "

"; } ?>