protected $previewing = false;
/**
- * Methods and properties deailing with managing widgets in the customizer.
+ * Methods and properties deailing with managing widgets in the Customizer.
*
* @var WP_Customize_Widgets
*/
protected $customized;
+ /**
+ * Controls that may be rendered from JS templates.
+ *
+ * @since 4.1.0
+ * @access protected
+ * @var array
+ */
+ protected $registered_control_types = array();
+
/**
* $_POST values for Customize Settings.
*
// Run wp_redirect_status late to make sure we override the status last.
add_action( 'wp_redirect_status', array( $this, 'wp_redirect_status' ), 1000 );
- // Do not spawn cron (especially the alternate cron) while running the customizer.
+ // Do not spawn cron (especially the alternate cron) while running the Customizer.
remove_action( 'init', 'wp_cron' );
// Do not run update checks when rendering the controls.
add_filter( 'stylesheet', array( $this, 'get_stylesheet' ) );
add_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) );
- // @link: http://core.trac.wordpress.org/ticket/20027
+ // @link: https://core.trac.wordpress.org/ticket/20027
add_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) );
add_filter( 'pre_option_template', array( $this, 'get_template' ) );
remove_filter( 'stylesheet', array( $this, 'get_stylesheet' ) );
remove_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) );
- // @link: http://core.trac.wordpress.org/ticket/20027
+ // @link: https://core.trac.wordpress.org/ticket/20027
remove_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) );
remove_filter( 'pre_option_template', array( $this, 'get_template' ) );
*
* @since 3.4.0
*
- * @param mixed $setting A WP_Customize_Setting derived object
+ * @param WP_Customize_Setting $setting A WP_Customize_Setting derived object
* @return string $post_value Sanitized value
*/
public function post_value( $setting ) {
}
/**
- * Print javascript settings.
+ * Print JavaScript settings.
*
* @since 3.4.0
*/
}
/**
- * Print javascript settings for preview frame.
+ * Print JavaScript settings for preview frame.
*
* @since 3.4.0
*/
$settings = array(
'values' => array(),
'channel' => wp_unslash( $_POST['customize_messenger_channel'] ),
+ 'activePanels' => array(),
+ 'activeSections' => array(),
'activeControls' => array(),
);
foreach ( $this->settings as $id => $setting ) {
$settings['values'][ $id ] = $setting->js_value();
}
+ foreach ( $this->panels as $id => $panel ) {
+ $settings['activePanels'][ $id ] = $panel->active();
+ foreach ( $panel->sections as $id => $section ) {
+ $settings['activeSections'][ $id ] = $section->active();
+ }
+ }
+ foreach ( $this->sections as $id => $section ) {
+ $settings['activeSections'][ $id ] = $section->active();
+ }
foreach ( $this->controls as $id => $control ) {
$settings['activeControls'][ $id ] = $control->active();
}
?>
<script type="text/javascript">
- var _wpCustomizeSettings = <?php echo json_encode( $settings ); ?>;
+ var _wpCustomizeSettings = <?php echo wp_json_encode( $settings ); ?>;
</script>
<?php
}
/**
- * Prints a signature so we can ensure the customizer was properly executed.
+ * Prints a signature so we can ensure the Customizer was properly executed.
*
* @since 3.4.0
*/
}
/**
- * Removes the signature in case we experience a case where the customizer was not properly executed.
+ * Removes the signature in case we experience a case where the Customizer was not properly executed.
*
* @since 3.4.0
*/
}
/**
- * Helper function to compare two objects by priority.
+ * Register a customize control type.
+ *
+ * Registered types are eligible to be rendered via JS and created dynamically.
+ *
+ * @since 4.1.0
+ * @access public
+ *
+ * @param string $control Name of a custom control which is a subclass of
+ * {@see WP_Customize_Control}.
+ */
+ public function register_control_type( $control ) {
+ $this->registered_control_types[] = $control;
+ }
+
+ /**
+ * Render JS templates for all registered control types.
+ *
+ * @since 4.1.0
+ * @access public
+ */
+ public function render_control_templates() {
+ foreach ( $this->registered_control_types as $control_type ) {
+ $control = new $control_type( $this, 'temp', array() );
+ $control->print_template();
+ }
+ }
+
+ /**
+ * Helper function to compare two objects by priority, ensuring sort stability via instance_number.
*
* @since 3.4.0
*
- * @param object $a Object A.
- * @param object $b Object B.
+ * @param {WP_Customize_Panel|WP_Customize_Section|WP_Customize_Control} $a Object A.
+ * @param {WP_Customize_Panel|WP_Customize_Section|WP_Customize_Control} $b Object B.
* @return int
*/
protected final function _cmp_priority( $a, $b ) {
- $ap = $a->priority;
- $bp = $b->priority;
-
- if ( $ap == $bp )
- return 0;
- return ( $ap > $bp ) ? 1 : -1;
+ if ( $a->priority === $b->priority ) {
+ return $a->instance_number - $a->instance_number;
+ } else {
+ return $a->priority - $b->priority;
+ }
}
/**
*/
public function prepare_controls() {
- $this->controls = array_reverse( $this->controls );
$controls = array();
+ uasort( $this->controls, array( $this, '_cmp_priority' ) );
foreach ( $this->controls as $id => $control ) {
if ( ! isset( $this->sections[ $control->section ] ) || ! $control->check_capabilities() ) {
$this->controls = $controls;
// Prepare sections.
- // Reversing makes uasort sort by time added when conflicts occur.
- $this->sections = array_reverse( $this->sections );
uasort( $this->sections, array( $this, '_cmp_priority' ) );
$sections = array();
if ( ! $section->panel ) {
// Top-level section.
- $sections[] = $section;
+ $sections[ $section->id ] = $section;
} else {
// This section belongs to a panel.
if ( isset( $this->panels [ $section->panel ] ) ) {
- $this->panels[ $section->panel ]->sections[] = $section;
+ $this->panels[ $section->panel ]->sections[ $section->id ] = $section;
}
}
}
$this->sections = $sections;
// Prepare panels.
- // Reversing makes uasort sort by time added when conflicts occur.
- $this->panels = array_reverse( $this->panels );
uasort( $this->panels, array( $this, '_cmp_priority' ) );
$panels = array();
continue;
}
- usort( $panel->sections, array( $this, '_cmp_priority' ) );
- $panels[] = $panel;
+ uasort( $panel->sections, array( $this, '_cmp_priority' ) );
+ $panels[ $panel->id ] = $panel;
}
$this->panels = $panels;
*/
public function register_controls() {
+ /* Control Types (custom control classes) */
+ $this->register_control_type( 'WP_Customize_Color_Control' );
+ $this->register_control_type( 'WP_Customize_Upload_Control' );
+ $this->register_control_type( 'WP_Customize_Image_Control' );
+ $this->register_control_type( 'WP_Customize_Background_Image_Control' );
+
/* Site Title & Tagline */
$this->add_section( 'title_tagline', array(
* Returns either '', a 3 or 6 digit hex color (without a #), or null.
*
* @since 3.4.0
- * @uses sanitize_hex_color()
*
* @param string $color
* @return string|null