'small', // or medium or large 'placeholder' => '', // show this when blank 'min' => 0, 'max' => 1000, 'step' => 1, 'default' => 0, 'unit' => '' ); /** * Constructor * * @since 1.4 */ function __construct( $settings, $owner ) { parent::__construct( $settings, $owner ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueueSlider' ) ); add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueueSlider' ) ); add_action( 'admin_head', array( __CLASS__, 'createSliderScript' ) ); } /** * Cleans up the serialized value before saving * * @param string $value The serialized value * @return string The cleaned value * @since 1.4 */ public function cleanValueForSaving( $value ) { if ( $value == '' ) { return 0; } return $value; } /** * Cleans the value for getOption * * @param string $value The raw value of the option * @return mixes The cleaned value * @since 1.4 */ public function cleanValueForGetting( $value ) { if ( $value == '' ) { return 0; } return $value; } /** * Enqueues the jQuery UI scripts * * @return void * @since 1.4 */ public function enqueueSlider() { wp_enqueue_script( 'jquery-ui-core' ); wp_enqueue_script( 'jquery-ui-slider' ); } /** * Prints out the script the initializes the jQuery slider * * @return void * @since 1.4 */ public static function createSliderScript() { ?> echoOptionHeader(); echo "
"; printf(" %s

%s

", $this->settings['size'], $this->getID(), $this->settings['placeholder'], $this->getID(), esc_attr( $this->getValue() ), $this->settings['min'], $this->settings['max'], $this->settings['step'], $this->settings['unit'], $this->settings['desc'] ); $this->echoOptionFooter(false); } /** * Registers the theme customizer control, for displaying the option * * @param WP_Customize $wp_enqueue_script The customize object * @param TitanFrameworkCustomizerSection $section The section where this option will be placed * @param int $priority The order of this control in the section * @return void * @since 1.0 */ public function registerCustomizerControl( $wp_customize, $section, $priority = 1 ) { $wp_customize->add_control( new TitanFrameworkOptionNumberControl( $wp_customize, $this->getID(), array( 'label' => $this->settings['name'], 'section' => $section->getID(), 'settings' => $this->getID(), 'description' => $this->settings['desc'], 'priority' => $priority, 'size' => $this->settings['size'], 'min' => $this->settings['min'], 'max' => $this->settings['max'], 'step' => $this->settings['step'], 'unit' => $this->settings['unit'], ) ) ); } } /* * We create a new control for the theme customizer */ add_action( 'customize_register', 'registerTitanFrameworkOptionNumberControl', 1 ); /** * Creates the option for the theme customizer * * @return void * @since 1.0 */ function registerTitanFrameworkOptionNumberControl() { class TitanFrameworkOptionNumberControl extends WP_Customize_Control { public $description; public $size; public $min; public $max; public $step; public $unit; private static $firstLoad = true; public function render_content() { // Print out the jQuery slider initializer if ( self::$firstLoad ) { TitanFrameworkOptionNumber::createSliderScript(); } self::$firstLoad = false; ?> description ) ) { echo "

{$this->description}

"; } } } }