array(), ); function __construct( $settings, $owner ) { parent::__construct( $settings, $owner ); add_action( 'tf_livepreview_pre_' . $this->getOptionNamespace(), array( $this, 'preLivePreview' ), 10, 3 ); } /* * Display for options and meta */ public function display() { if ( empty( $this->settings['options'] ) ) { return; } if ( $this->settings['options'] == array() ) { return; } $this->echoOptionHeader(); // Get the correct value, since we are accepting indices in the default setting $value = $this->getValue(); if ( $value == '' ) { $value = 0; } if ( ! is_array( $value ) ) { $value = $this->settings['options'][$value]; } // print the palettes foreach ( $this->settings['options'] as $key => $colorSet ) { printf( '"; } $this->echoOptionFooter(); } // Save the index of the selected palette public function cleanValueForSaving( $value ) { if ( ! is_array( $this->settings['options'] ) ) { return $value; } // if the key above is zero, we will get a blank value if ( $value === '' ) { $value = 0; } return $value; } // The value we should return is an array of the selected colors public function cleanValueForGetting( $value ) { if ( is_array( $value ) ) { return $value; } $value = stripslashes( $value ); if ( is_serialized( $value ) ) { return unserialize( $value ); } if ( empty( $value ) ) { $value = 0; } if ( array_key_exists( $value, $this->settings['options'] ) ) { return $this->settings['options'][$value]; } return $value; } /* * Display for theme customizer */ public function registerCustomizerControl( $wp_customize, $section, $priority = 1 ) { $wp_customize->add_control( new TitanFrameworkOptionRadioPaletteControl( $wp_customize, $this->getID(), array( 'label' => $this->settings['name'], 'section' => $section->settings['id'], 'type' => 'select', 'choices' => $this->settings['options'], 'settings' => $this->getID(), 'description' => $this->settings['desc'], 'priority' => $priority, ) ) ); } // For live previews, we need to give our options to javascript and then get the proper value from it public function preLivePreview( $optionID, $optionType, $option ) { if ( $optionID != $this->settings['id'] || empty( $this->settings['options'] ) ) { return; } if ( $this->settings['options'] == array() ) { return; } ?> var options = JSON.parse('settings['options'] ) ?>'), key = value; value = options[value]; value(); if ( $value == '' ) { $value = 0; } ?>label ); ?>description ) ) { echo "

" . $this->description . "

"; } // print the palettes foreach ( $this->choices as $key => $colorSet ) { if ( ! is_array( $colorSet ) ) { continue; } ?>