X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/8f374b7233bc2815ccc387e448d208c5434eb961..9e77185fafaf4e60e2b73821e0e4b9b1a11fb85f:/wp-includes/class-wp-customize-manager.php diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php index c1ce0510..4465a805 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/wp-includes/class-wp-customize-manager.php @@ -1,24 +1,63 @@ widgets = new WP_Customize_Widgets( $this ); add_filter( 'wp_die_handler', array( $this, 'wp_die_handler' ) ); @@ -54,10 +97,12 @@ final class WP_Customize_Manager { add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_control_scripts' ) ); } - /** + /** * Return true if it's an AJAX request. * * @since 3.4.0 + * + * @return bool */ public function doing_ajax() { return isset( $_POST['customized'] ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ); @@ -67,10 +112,10 @@ final class WP_Customize_Manager { * Custom wp_die wrapper. Returns either the standard message for UI * or the AJAX message. * - * @param mixed $ajax_message AJAX return - * @param mixed $message UI message - * * @since 3.4.0 + * + * @param mixed $ajax_message AJAX return + * @param mixed $message UI message */ protected function wp_die( $ajax_message, $message = null ) { if ( $this->doing_ajax() ) @@ -86,6 +131,8 @@ final class WP_Customize_Manager { * Return the AJAX wp_die() handler if it's a customized request. * * @since 3.4.0 + * + * @return string */ public function wp_die_handler() { if ( $this->doing_ajax() ) @@ -93,10 +140,11 @@ final class WP_Customize_Manager { return '_default_wp_die_handler'; } + /** - * Start preview and customize theme. - * - * Check if customize query variable exist. Init filters to filter the current theme. + * Start preview and customize theme. + * + * Check if customize query variable exist. Init filters to filter the current theme. * * @since 3.4.0 */ @@ -110,8 +158,9 @@ final class WP_Customize_Manager { show_admin_bar( false ); - if ( ! current_user_can( 'edit_theme_options' ) ) + if ( ! current_user_can( 'customize' ) ) { $this->wp_die( -1 ); + } $this->original_stylesheet = get_stylesheet(); @@ -121,13 +170,16 @@ final class WP_Customize_Manager { // Once the theme is loaded, we'll validate it. add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ) ); } else { + // If the requested theme is not the active theme and the user doesn't have the + // switch_themes cap, bail. if ( ! current_user_can( 'switch_themes' ) ) $this->wp_die( -1 ); - // If the theme isn't active, you can't preview it if it is not allowed or has errors. + // If the theme has errors while loading, bail. if ( $this->theme()->errors() ) $this->wp_die( -1 ); + // If the theme isn't allowed per multisite settings, bail. if ( ! $this->theme()->is_allowed() ) $this->wp_die( -1 ); } @@ -135,7 +187,12 @@ final class WP_Customize_Manager { $this->start_previewing_theme(); } - function after_setup_theme() { + /** + * Callback to validate a theme once it is loaded + * + * @since 3.4.0 + */ + public function after_setup_theme() { if ( ! $this->doing_ajax() && ! validate_current_theme() ) { wp_redirect( 'themes.php?broken=true' ); exit; @@ -143,9 +200,8 @@ final class WP_Customize_Manager { } /** - * Start previewing the selected theme. - * - * Adds filters to change the current theme. + * If the theme to be previewed isn't the active theme, add filter callbacks + * to swap it out at runtime. * * @since 3.4.0 */ @@ -170,6 +226,13 @@ final class WP_Customize_Manager { add_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) ); } + /** + * Fires once the Customizer theme preview has started. + * + * @since 3.4.0 + * + * @param WP_Customize_Manager $this WP_Customize_Manager instance. + */ do_action( 'start_previewing_theme', $this ); } @@ -200,6 +263,13 @@ final class WP_Customize_Manager { remove_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) ); } + /** + * Fires once the Customizer theme preview has stopped. + * + * @since 3.4.0 + * + * @param WP_Customize_Manager $this WP_Customize_Manager instance. + */ do_action( 'stop_previewing_theme', $this ); } @@ -236,6 +306,17 @@ final class WP_Customize_Manager { return $this->controls; } + /** + * Get the registered containers. + * + * @since 4.0.0 + * + * @return array + */ + public function containers() { + return $this->containers; + } + /** * Get the registered sections. * @@ -247,6 +328,18 @@ final class WP_Customize_Manager { return $this->sections; } + /** + * Get the registered panels. + * + * @since 4.0.0 + * @access public + * + * @return array Panels. + */ + public function panels() { + return $this->panels; + } + /** * Checks if the current theme is active. * @@ -264,6 +357,14 @@ final class WP_Customize_Manager { * @since 3.4.0 */ public function wp_loaded() { + + /** + * Fires once WordPress has loaded, allowing scripts and styles to be initialized. + * + * @since 3.4.0 + * + * @param WP_Customize_Manager $this WP_Customize_Manager instance. + */ do_action( 'customize_register', $this ); if ( $this->is_preview() && ! is_admin() ) @@ -277,6 +378,9 @@ final class WP_Customize_Manager { * Instead, the JS will sniff out the location header. * * @since 3.4.0 + * + * @param $status + * @return int */ public function wp_redirect_status( $status ) { if ( $this->is_preview() && ! is_admin() ) @@ -286,14 +390,17 @@ final class WP_Customize_Manager { } /** - * Decode the $_POST attribute used to override the WP_Customize_Setting values. + * Decode the $_POST['customized'] values for a specific Customize Setting. * * @since 3.4.0 + * + * @param mixed $setting A WP_Customize_Setting derived object + * @return string $post_value Sanitized value */ public function post_value( $setting ) { if ( ! isset( $this->_post_values ) ) { if ( isset( $_POST['customized'] ) ) - $this->_post_values = json_decode( stripslashes( $_POST['customized'] ), true ); + $this->_post_values = json_decode( wp_unslash( $_POST['customized'] ), true ); else $this->_post_values = false; } @@ -308,9 +415,12 @@ final class WP_Customize_Manager { * @since 3.4.0 */ public function customize_preview_init() { + $this->nonce_tick = check_ajax_referer( 'preview-customize_' . $this->get_stylesheet(), 'nonce' ); + $this->prepare_controls(); wp_enqueue_script( 'customize-preview' ); + add_action( 'wp', array( $this, 'customize_preview_override_404_status' ) ); add_action( 'wp_head', array( $this, 'customize_preview_base' ) ); add_action( 'wp_head', array( $this, 'customize_preview_html5' ) ); add_action( 'wp_footer', array( $this, 'customize_preview_settings' ), 20 ); @@ -321,9 +431,30 @@ final class WP_Customize_Manager { $setting->preview(); } + /** + * Fires once the Customizer preview has initialized and JavaScript + * settings have been printed. + * + * @since 3.4.0 + * + * @param WP_Customize_Manager $this WP_Customize_Manager instance. + */ do_action( 'customize_preview_init', $this ); } + /** + * Prevent sending a 404 status when returning the response for the customize + * preview, since it causes the jQuery AJAX to fail. Send 200 instead. + * + * @since 4.0.0 + * @access public + */ + public function customize_preview_override_404_status() { + if ( is_404() ) { + status_header( 200 ); + } + } + /** * Print base element for preview frame. * @@ -359,12 +490,23 @@ final class WP_Customize_Manager { public function customize_preview_settings() { $settings = array( 'values' => array(), - 'channel' => esc_js( $_POST['customize_messenger_channel'] ), + 'channel' => wp_unslash( $_POST['customize_messenger_channel'] ), + 'activeControls' => array(), ); + if ( 2 == $this->nonce_tick ) { + $settings['nonce'] = array( + 'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ), + 'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ) + ); + } + foreach ( $this->settings as $id => $setting ) { $settings['values'][ $id ] = $setting->js_value(); } + foreach ( $this->controls as $id => $control ) { + $settings['activeControls'][ $id ] = $control->active(); + } ?>