X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/8f374b7233bc2815ccc387e448d208c5434eb961..c55863f11e8589bf8d4a5698bf15752406654f1c:/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..cad9f135 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/wp-includes/class-wp-customize-manager.php @@ -1,12 +1,11 @@ doing_ajax() ) @@ -86,6 +89,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 +98,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 */ @@ -135,6 +141,11 @@ final class WP_Customize_Manager { $this->start_previewing_theme(); } + /** + * Callback to validate a theme once it is loaded + * + * @since 3.4.0 + */ function after_setup_theme() { if ( ! $this->doing_ajax() && ! validate_current_theme() ) { wp_redirect( 'themes.php?broken=true' ); @@ -277,6 +288,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() ) @@ -289,11 +303,14 @@ final class WP_Customize_Manager { * Decode the $_POST attribute used to override the WP_Customize_Setting values. * * @since 3.4.0 + * + * @param mixed $setting A WP_Customize_Setting derived object + * @return string Sanitized attribute */ 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,6 +325,8 @@ 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' ); @@ -362,6 +381,13 @@ final class WP_Customize_Manager { 'channel' => esc_js( $_POST['customize_messenger_channel'] ), ); + 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(); } @@ -453,6 +479,7 @@ final class WP_Customize_Manager { * * @since 3.4.0 * + * @param $current_theme {@internal Parameter is not used} * @return string Theme name. */ public function current_theme( $current_theme ) { @@ -468,14 +495,14 @@ final class WP_Customize_Manager { if ( ! $this->is_preview() ) die; - check_ajax_referer( 'customize_controls-' . $this->get_stylesheet(), 'nonce' ); + check_ajax_referer( 'save-customize_' . $this->get_stylesheet(), 'nonce' ); // Do we have to switch themes? if ( ! $this->is_theme_active() ) { // Temporarily stop previewing the theme to allow switch_themes() // to operate properly. $this->stop_previewing_theme(); - switch_theme( $this->get_template(), $this->get_stylesheet() ); + switch_theme( $this->get_stylesheet() ); $this->start_previewing_theme(); } @@ -485,6 +512,8 @@ final class WP_Customize_Manager { $setting->save(); } + do_action( 'customize_save_after', $this ); + die; } @@ -619,6 +648,7 @@ final class WP_Customize_Manager { * * @param object $a Object A. * @param object $b Object B. + * @return int */ protected final function _cmp_priority( $a, $b ) { $ap = $a->priority; @@ -869,9 +899,7 @@ final class WP_Customize_Manager { if ( $menus ) { $choices = array( 0 => __( '— Select —' ) ); foreach ( $menus as $menu ) { - $truncated_name = wp_html_excerpt( $menu->name, 40 ); - $truncated_name = ( $truncated_name == $menu->name ) ? $menu->name : trim( $truncated_name ) . '…'; - $choices[ $menu->term_id ] = $truncated_name; + $choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '…' ); } foreach ( $locations as $location => $description ) { @@ -947,11 +975,22 @@ final class WP_Customize_Manager { * Callback for validating the header_textcolor value. * * Accepts 'blank', and otherwise uses sanitize_hex_color_no_hash(). + * Returns default text color if hex color is empty. * * @since 3.4.0 + * + * @param string $color + * @return string */ public function _sanitize_header_textcolor( $color ) { - return ( 'blank' === $color ) ? 'blank' : sanitize_hex_color_no_hash( $color ); + if ( 'blank' === $color ) + return 'blank'; + + $color = sanitize_hex_color_no_hash( $color ); + if ( empty( $color ) ) + $color = get_theme_support( 'custom-header', 'default-text-color' ); + + return $color; } }; @@ -962,6 +1001,9 @@ final class WP_Customize_Manager { * For validating values without a #, see sanitize_hex_color_no_hash(). * * @since 3.4.0 + * + * @param string $color + * @return string|null */ function sanitize_hex_color( $color ) { if ( '' === $color ) @@ -984,6 +1026,10 @@ function sanitize_hex_color( $color ) { * 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 */ function sanitize_hex_color_no_hash( $color ) { $color = ltrim( $color, '#' ); @@ -1001,6 +1047,9 @@ function sanitize_hex_color_no_hash( $color ) { * This method should only be necessary if using sanitize_hex_color_no_hash(). * * @since 3.4.0 + * + * @param string $color + * @return string */ function maybe_hash_hex_color( $color ) { if ( $unhashed = sanitize_hex_color_no_hash( $color ) )