array(), 'visible_button' => true, ); private static $firstLoad = true; /** * Constructor * * @since 1.4 */ function __construct( $settings, $owner ) { parent::__construct( $settings, $owner ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueueSortable' ) ); add_action( 'admin_head', array( __CLASS__, 'createSortableScript' ) ); add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueueSortable' ) ); } /** * Enqueues the jQuery UI scripts * * @return void * @since 1.4 */ public function enqueueSortable() { wp_enqueue_script( 'jquery-ui-core' ); wp_enqueue_script( 'jquery-ui-sortable' ); } /** * Creates the javascript needed for sortable to run * * @return void * @since 1.4 */ public static function createSortableScript() { if ( ! self::$firstLoad ) { return; } self::$firstLoad = false; ?> settings['options'] ) ) { return; } if ( ! count( $this->settings['options'] ) ) { return; } $this->echoOptionHeader( true ); $values = $this->getValue(); if ( $values == '' ) { $values = array_keys( $this->settings['options'] ); } if ( is_serialized( $values ) ) { $values = unserialize( $values ); } if ( count( $values ) != count( $this->settings['options'] ) ) { $this->settings['visible_button'] = true; } $visibleButton = ''; if ( $this->settings['visible_button'] === true ) { $visibleButton = ""; } ?>
", $this->getID(), $this->getID(), esc_attr( $values ) ); $this->echoOptionFooter( false ); } /** * 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 ) { return stripslashes( $value ); } /** * Cleans the raw value for getting * * @param string $value The raw value * @return string The cleaned value * @since 1.4 */ public function cleanValueForGetting( $value ) { if ( is_array( $value ) ) { return $value; } if ( is_serialized( stripslashes( $value ) ) ) { return unserialize( $value ); } return $value; } /** * 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.4 */ public function registerCustomizerControl( $wp_customize, $section, $priority = 1 ) { $wp_customize->add_control( new TitanFrameworkOptionSortableControl( $wp_customize, $this->getID(), array( 'label' => $this->settings['name'], 'section' => $section->settings['id'], 'settings' => $this->getID(), 'description' => $this->settings['desc'], 'priority' => $priority, 'options' => $this->settings['options'], 'visible_button' => $this->settings['visible_button'], ) ) ); } } /* * We create a new control for the theme customizer */ add_action( 'customize_register', 'registerTitanFrameworkOptionSortableControl', 1 ); /** * Creates the option for the theme customizer * * @return void * @since 1.4 */ function registerTitanFrameworkOptionSortableControl() { class TitanFrameworkOptionSortableControl extends WP_Customize_Control { public $description; public $options; public $visible_button; public function render_content() { TitanFrameworkOptionSortable::createSortableScript(); if ( ! is_array( $this->options ) ) { return; } if ( ! count( $this->options ) ) { return; } ?> {$this->description}

"; } } }