Ticket #29988: 29988.patch
File 29988.patch, 20.0 KB (added by , 9 years ago) |
---|
-
src/wp-admin/js/customize-controls.js
diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js index fad223e..b1f2ebc 100644
170 170 control.setting.set( false ); 171 171 } 172 172 }); 173 174 this.setting.bind( function ( value ) { 175 picker.val( value ); 176 picker.wpColorPicker( 'color', value ); 177 }); 173 178 } 174 179 }); 175 180 -
src/wp-content/themes/twentyfifteen/functions.php
diff --git src/wp-content/themes/twentyfifteen/functions.php src/wp-content/themes/twentyfifteen/functions.php index fd49484..d287733 100644
function twentyfifteen_setup() { 87 87 'aside', 'image', 'video', 'quote', 'link', 'gallery', 'status', 'audio', 'chat' 88 88 ) ); 89 89 90 $color_scheme = twentyfifteen_get_color_scheme();91 $default_color = trim( $color_scheme[0], '#' );92 93 // Setup the WordPress core custom background feature.94 add_theme_support( 'custom-background', apply_filters( 'twentyfifteen_custom_background_args', array(95 'default-color' => $default_color,96 'default-attachment' => 'fixed',97 ) ) );98 99 90 /* 100 91 * This theme styles the visual editor to resemble the theme style, 101 92 * specifically font, colors, icons, and column width. … … endif; // twentyfifteen_setup 106 97 add_action( 'after_setup_theme', 'twentyfifteen_setup' ); 107 98 108 99 /** 100 * Core adds the wp-head-callbacks for the custom header and background on the 101 * wp_head action at the default priority of 10. At the same time, Core by default 102 * adds wp_print_styles to the wp_head action at the priority of 8. For this reason 103 * the inline styles added in the head callback fail to get added in time to be 104 * output with any styles output by wp_print_styles. This is a workaround for that. 105 * Also, since we're using the wp_add_inline_styles() for the sake of faster 106 * style updates in the Customizer, we can add the callbacks to wp_enqueue_scripts 107 * instead of wp_head. 108 * 109 * @see _custom_header_background_just_in_time(). 110 */ 111 function twentyfifteen_custom_header_background_just_in_even_more_time() { 112 $print_styles_priority = has_filter( 'wp_head', 'wp_print_styles' ); 113 114 if ( current_theme_supports( 'custom-header' ) ) { 115 $args = get_theme_support( 'custom-header' ); 116 $callback = $args[0]['wp-head-callback']; 117 if ( $callback ) { 118 remove_action( 'wp_head', $callback, 10 ); 119 add_action( 'wp_enqueue_scripts', $callback, 11 ); 120 } 121 } 122 123 if ( current_theme_supports( 'custom-background' ) ) { 124 $args = get_theme_support( 'custom-background' ); 125 $callback = $args[0]['wp-head-callback']; 126 if ( $callback ) { 127 remove_action( 'wp_head', $callback, 10 ); 128 add_action( 'wp_enqueue_scripts', $callback, 11 ); 129 } 130 } 131 } 132 add_action( 'wp_loaded', 'twentyfifteen_custom_header_background_just_in_even_more_time', 11 ); 133 134 /** 109 135 * Register widget area. 110 136 * 111 137 * @since Twenty Fifteen 1.0 … … add_filter( 'walker_nav_menu_start_el', 'twentyfifteen_nav_description', 10, 4 ) 318 344 require get_template_directory() . '/inc/custom-header.php'; 319 345 320 346 /** 347 * Implement the Custom Background feature. 348 * 349 * @since Twenty Fifteen 1.0 350 */ 351 require get_template_directory() . '/inc/custom-background.php'; 352 353 /** 321 354 * Custom template tags for this theme. 322 355 * 323 356 * @since Twenty Fifteen 1.0 -
new file src/wp-content/themes/twentyfifteen/inc/custom-background.php
diff --git src/wp-content/themes/twentyfifteen/inc/custom-background.php src/wp-content/themes/twentyfifteen/inc/custom-background.php new file mode 100644 index 0000000..bde858a
- + 1 <?php 2 /** 3 * Implement Custom Background functionality for Twenty Fifteen. 4 * 5 * @package WordPress 6 * @subpackage Twenty_Fifteen 7 * @since Twenty Fifteen 1.0 8 */ 9 10 /** 11 * Set up the WordPress core custom header feature. 12 * 13 * @uses twentyfifteen_background_style() 14 */ 15 function twentyfifteen_custom_background_setup() { 16 $color_scheme = twentyfifteen_get_color_scheme(); 17 $default_color = trim( $color_scheme[0], '#' ); 18 19 // Setup the WordPress core custom background feature. 20 add_theme_support( 'custom-background', apply_filters( 'twentyfifteen_custom_background_args', array( 21 'default-color' => $default_color, 22 'default-attachment' => 'fixed', 23 'wp-head-callback' => 'twentyfifteen_background_style', 24 ) ) ); 25 } 26 add_action( 'after_setup_theme', 'twentyfifteen_custom_background_setup' ); 27 28 29 if ( ! function_exists( 'twentyfifteen_background_style' ) ) : 30 /** 31 * Styles the header image and text displayed on the blog. 32 * 33 * @since Twenty Fifteen 1.0 34 * @see twentyfifteen_custom_background_setup(). 35 * @see _custom_background_cb() 36 */ 37 function twentyfifteen_background_style() { 38 39 // $background is the saved custom image, or the default image. 40 $background = set_url_scheme( get_background_image() ); 41 42 // $color is the saved custom color. 43 // A default has to be specified in style.css. It will not be printed here. 44 $color = get_background_color(); 45 46 if ( $color === get_theme_support( 'custom-background', 'default-color' ) ) { 47 $color = false; 48 } 49 50 if ( ! $background && ! $color ) { 51 return; 52 } 53 54 $style = $color ? "background-color: #$color;" : ''; 55 56 if ( $background ) { 57 $image = " background-image: url('$background');"; 58 59 $repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ); 60 if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) ) { 61 $repeat = 'repeat'; 62 } 63 $repeat = " background-repeat: $repeat;"; 64 65 $position = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); 66 if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) ) { 67 $position = 'left'; 68 } 69 $position = " background-position: top $position;"; 70 71 $attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ); 72 if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) ) { 73 $attachment = 'scroll'; 74 } 75 $attachment = " background-attachment: $attachment;"; 76 77 $style .= $image . $repeat . $position . $attachment; 78 } 79 80 if ( $style ) { 81 $sheet = sprintf( 'body.custom-background { %s } ', trim( $style ) ); 82 wp_add_inline_style( 'twentyfifteen-style', $sheet ); 83 } 84 85 } 86 endif; // twentyfifteen_background_style -
src/wp-content/themes/twentyfifteen/inc/custom-header.php
diff --git src/wp-content/themes/twentyfifteen/inc/custom-header.php src/wp-content/themes/twentyfifteen/inc/custom-header.php index bdcaef9..3664ef5 100644
function twentyfifteen_header_style() { 86 86 return; 87 87 } 88 88 89 // If we get this far, we have custom styles. Let's do this. 90 ?> 91 <style type="text/css" id="twentyfifteen-header-css"> 92 <?php 93 if ( ! empty( $header_image ) ) : 94 ?> 95 .site-header { 96 background: url(<?php header_image(); ?>) no-repeat 50% 50%; 97 -webkit-background-size: cover; 98 -moz-background-size: cover; 99 -o-background-size: cover; 100 background-size: cover; 101 } 89 $css = ''; 102 90 103 @media screen and (min-width: 59.6875em) { 104 body:before { 105 background: url(<?php header_image(); ?>) no-repeat 100% 50%; 91 if ( ! empty( $header_image ) ) { 92 $css .= sprintf( 93 ' 94 /* Header image */ 95 .site-header { 96 background: url( %1$s ) no-repeat 50%% 50%%; 106 97 -webkit-background-size: cover; 107 98 -moz-background-size: cover; 108 99 -o-background-size: cover; 109 100 background-size: cover; 110 border-right: 0;111 101 } 112 102 113 .site-header { 114 background: transparent; 103 @media screen and (min-width: 59.6875em) { 104 body:before { 105 background: url( %1$s ) no-repeat 100%% 50%%; 106 -webkit-background-size: cover; 107 -moz-background-size: cover; 108 -o-background-size: cover; 109 background-size: cover; 110 border-right: 0; 111 } 112 113 .site-header { 114 background: transparent; 115 } 115 116 } 116 } 117 <?php 118 endif; 119 120 // Has the text been hidden? 121 if ( ! display_header_text() ) : 122 ?> 123 .site-title, 124 .site-description { 125 clip: rect(1px, 1px, 1px, 1px); 126 position: absolute; 127 } 128 <?php 129 // If the user has set a custom color for the text use that 130 elseif ( $text_color != get_theme_support( 'custom-header', 'default-text-color' ) ) : 131 ?> 132 .site-title a, 133 .site-title a:hover, 134 .site-title a:focus, 135 .site-description { 136 color: #<?php echo esc_attr( $text_color ); ?>; 137 } 138 <?php endif; ?> 139 </style> 140 <?php 117 ', 118 esc_url( $header_image ) 119 ); 120 } 121 122 if ( ! display_header_text() ) { 123 $css .= ' 124 /* Hide display header text */ 125 .site-title, 126 .site-description { 127 clip: rect(1px, 1px, 1px, 1px); 128 position: absolute; 129 } 130 '; 131 } 132 133 if ( $text_color != get_theme_support( 'custom-header', 'default-text-color' ) ) { 134 $css .= sprintf( 135 ' 136 /* Header text color */ 137 .site-title a, 138 .site-title a:hover, 139 .site-title a:focus, 140 .site-description { 141 color: %1$s; 142 } 143 ', 144 sanitize_hex_color( '#' . $text_color ) 145 ); 146 } 147 148 if ( $css ) { 149 wp_add_inline_style( 'twentyfifteen-style', $css ); 150 } 151 141 152 } 142 153 endif; // twentyfifteen_header_style 143 154 -
src/wp-content/themes/twentyfifteen/inc/customizer.php
diff --git src/wp-content/themes/twentyfifteen/inc/customizer.php src/wp-content/themes/twentyfifteen/inc/customizer.php index 2daee26..f7062b7 100644
8 8 */ 9 9 10 10 /** 11 * Get the settings which should be postMessage and which should trigger a 12 * refresh of the CSS via Ajax. 13 * 14 * @since Twenty Fifteen 1.0 15 * 16 * @return array 17 */ 18 function twentyfifteen_get_inline_style_settings() { 19 return array( 20 'header_image', 21 'header_image_data', 22 'header_textcolor', 23 'color_scheme', 24 'header_background_color', 25 'sidebar_textcolor', 26 'background_color', 27 'background_attachment', 28 'background_repeat', 29 'background_position_x', 30 'background_image', 31 ); 32 } 33 34 /** 11 35 * Add postMessage support for site title and description for the Customizer. 12 36 * 13 37 * @since Twenty Fifteen 1.0 … … 17 41 function twentyfifteen_customize_register( $wp_customize ) { 18 42 $color_scheme = twentyfifteen_get_color_scheme(); 19 43 20 $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';21 $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';22 $wp_customize->get_setting( 'background_color' )->transport = 'refresh';23 24 44 // Add color scheme setting and control. 25 45 $wp_customize->add_setting( 'color_scheme', array( 26 46 'default' => 'default', … … function twentyfifteen_customize_register( $wp_customize ) { 55 75 'label' => esc_html__( 'Header & Sidebar Background Color', 'twentyfifteen' ), 56 76 'section' => 'colors', 57 77 ) ) ); 78 79 $post_message_settings = array_merge( 80 array( 81 'blogname', 82 'blogdescription', 83 ), 84 twentyfifteen_get_inline_style_settings() 85 ); 86 87 foreach ( $post_message_settings as $setting ) { 88 $wp_customize->get_setting( $setting )->transport = 'postMessage'; 89 } 58 90 } 59 91 add_action( 'customize_register', 'twentyfifteen_customize_register', 11 ); 60 92 … … function twentyfifteen_color_scheme_css() { 650 682 add_action( 'wp_enqueue_scripts', 'twentyfifteen_color_scheme_css' ); 651 683 652 684 /** 685 * Return the CSS via Ajax for the Customizer preview so that updates to the 686 * settings needn't require a full page refresh when a new color scheme is 687 * selected. 688 * 689 * @since Twenty Fifteen 1.0 690 */ 691 function twentyfifteen_ajax_inline_styles() { 692 /** 693 * @var WP_Styles $wp_styles 694 * @var WP_Customize_Manager $wp_customize 695 */ 696 global $wp_styles, $wp_customize; 697 698 if ( empty( $wp_customize ) ) { 699 wp_send_json_error( 'customizer_required' ); 700 } 701 702 $nonce_tick = check_ajax_referer( 'twentyfifteen_inline_styles' , 'nonce', false ); 703 if ( ! $nonce_tick ) { 704 wp_send_json_error( 'bad_nonce' ); 705 } 706 707 foreach ( $wp_customize->settings() as $setting ) { 708 if ( $setting->check_capabilities() ) { 709 $setting->preview(); 710 } 711 } 712 713 wp_enqueue_scripts(); 714 715 $inline_styles = array(); 716 foreach ( $wp_styles->queue as $handle ) { 717 $data = $wp_styles->get_data( $handle, 'after' ); 718 if ( $data ) { 719 $inline_styles[ $handle ] = implode( "\n", $data ); 720 } 721 } 722 723 $data = array( 724 'inlineStyles' => $inline_styles, 725 'theme' => get_stylesheet(), 726 ); 727 if ( 2 === $nonce_tick ) { 728 $data['nonce'] = wp_create_nonce( 'twentyfifteen_inline_styles' ); 729 } 730 731 wp_send_json_success( $data ); 732 } 733 add_action( 'wp_ajax_twentyfifteen_inline_styles', 'twentyfifteen_ajax_inline_styles' ); 734 735 /** 653 736 * Binds JS handlers to make Customizer preview reload changes asynchronously. 654 737 * 655 738 * @since Twenty Fifteen 1.0 656 739 */ 657 740 function twentyfifteen_customize_preview_js() { 658 wp_enqueue_script( 'twentyfifteen-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20141005', true ); 741 global $wp_scripts; 742 743 wp_enqueue_script( 'twentyfifteen-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview', 'wp-util', 'underscore' ), '20141005', true ); 744 745 $exports = array( 746 'inlineStyleSettings' => twentyfifteen_get_inline_style_settings(), 747 'nonce' => wp_create_nonce( 'twentyfifteen_inline_styles' ), 748 ); 749 750 /** 751 * @var WP_Scripts $wp_scripts 752 */ 753 $wp_scripts->add_data( 754 'twentyfifteen-customizer', 755 'data', 756 sprintf( 'var _twentyfifteenCustomizerExports = %s;', json_encode( $exports ) ) 757 ); 659 758 } 660 add_action( 'customize_preview_init', 'twentyfifteen_customize_preview_js' ); 661 No newline at end of file 759 add_action( 'customize_preview_init', 'twentyfifteen_customize_preview_js' ); -
src/wp-content/themes/twentyfifteen/js/color-scheme-control.js
diff --git src/wp-content/themes/twentyfifteen/js/color-scheme-control.js src/wp-content/themes/twentyfifteen/js/color-scheme-control.js index 4462f98..46f4a47 100644
5 5 * Adds listener to Color Scheme control to update other color controls with new values/defaults 6 6 */ 7 7 8 ( function( wp) {9 wp.customize.controlConstructor.colorScheme = wp.customize.Control.extend( {8 ( function( customize ) { 9 customize.controlConstructor.colorScheme = customize.Control.extend( { 10 10 ready: function() { 11 var parentSection = this.container.closest( '.control-section' ),12 headerTextColor = parentSection.find( '#customize-control-header_textcolor .color-picker-hex' ),13 backgroundColor = parentSection.find( '#customize-control-background_color .color-picker-hex' ),14 sidebarColor = parentSection.find( '#customize-control-header_background_color .color-picker-hex' ),15 sidebarTextColor = parentSection.find( '#customize-control-sidebar_textcolor .color-picker-hex' );16 11 17 12 this.setting.bind( 'change', function( value ) { 18 13 // if Header Text is not hidden, update value 19 if ( 'blank' !== wp.customize( 'header_textcolor' ).get() ) {20 wp.customize( 'header_textcolor' ).set( colorScheme[value].colors[4] );21 headerTextColor.val( colorScheme[value].colors[4])14 if ( 'blank' !== customize( 'header_textcolor' ).get() ) { 15 customize( 'header_textcolor' ).set( colorScheme[value].colors[4] ); 16 customize.control( 'header_textcolor' ).container.find( '.color-picker-hex' ) 22 17 .data( 'data-default-color', colorScheme[value].colors[4] ) 23 .wpColorPicker( 'color', colorScheme[value].colors[4] )24 18 .wpColorPicker( 'defaultColor', colorScheme[value].colors[4] ); 25 19 } 26 20 27 21 // update Background Color 28 wp.customize( 'background_color' ).set( colorScheme[value].colors[0] );29 backgroundColor.val( colorScheme[value].colors[0])22 customize( 'background_color' ).set( colorScheme[value].colors[0] ); 23 customize.control( 'background_color' ).container.find( '.color-picker-hex' ) 30 24 .data( 'data-default-color', colorScheme[value].colors[0] ) 31 .wpColorPicker( 'color', colorScheme[value].colors[0] )32 25 .wpColorPicker( 'defaultColor', colorScheme[value].colors[0] ); 33 26 34 27 // update Header/Sidebar Background Color 35 wp.customize( 'header_background_color' ).set( colorScheme[value].colors[1] );36 sidebarColor.val( colorScheme[value].colors[1])28 customize( 'header_background_color' ).set( colorScheme[value].colors[1] ); 29 customize.control( 'header_background_color' ).container.find( '.color-picker-hex' ) 37 30 .data( 'data-default-color', colorScheme[value].colors[1] ) 38 .wpColorPicker( 'color', colorScheme[value].colors[1] )39 31 .wpColorPicker( 'defaultColor', colorScheme[value].colors[1] ); 40 32 41 33 // update Sidebar Text Color 42 wp.customize( 'sidebar_textcolor' ).set( colorScheme[value].colors[4] );43 sidebarTextColor.val( colorScheme[value].colors[4])34 customize( 'sidebar_textcolor' ).set( colorScheme[value].colors[4] ); 35 customize.control( 'sidebar_textcolor' ).container.find( '.color-picker-hex' ) 44 36 .data( 'data-default-color', colorScheme[value].colors[4] ) 45 .wpColorPicker( 'color', colorScheme[value].colors[4] )46 37 .wpColorPicker( 'defaultColor', colorScheme[value].colors[4] ); 47 38 } ); 48 39 } 49 40 } ); 50 } )( this.wp ); 51 No newline at end of file 41 } )( this.wp.customize ); -
src/wp-content/themes/twentyfifteen/js/customizer.js
diff --git src/wp-content/themes/twentyfifteen/js/customizer.js src/wp-content/themes/twentyfifteen/js/customizer.js index 0aa9728..e83e1f0 100644
1 /*global _twentyfifteenCustomizerExports */ 2 /*exported TwentyFifteenCustomizer */ 3 1 4 /** 2 5 * Customizer enhancements for a better user experience. 3 6 * 4 7 * Contains handlers to make Customizer preview reload changes asynchronously. 5 8 */ 9 var TwentyFifteenCustomizer = ( function( $ ) { 10 var self; 11 12 self = { 13 inlineStyleSettings: [], 14 nonce: '', 15 theme: '', 16 debounceDelay: 100 17 }; 18 $.extend( self, _twentyfifteenCustomizerExports ); 6 19 7 ( function( $ ) {8 20 // Site title and description. 9 21 wp.customize( 'blogname', function( value ) { 10 22 value.bind( function( to ) { … … 16 28 $( '.site-description' ).text( to ); 17 29 } ); 18 30 } ); 19 } )( jQuery ); 20 No newline at end of file 31 32 // Update inline styles 33 self.refreshCss = function () { 34 var customized = {}; 35 $.each( self.inlineStyleSettings, function ( i, name ) { 36 customized[ name ] = wp.customize( name ).get(); 37 }); 38 39 wp.ajax.send( 'twentyfifteen_inline_styles', { 40 data: { 41 wp_customize: 'on', 42 customized: JSON.stringify( customized ), 43 theme: self.theme, 44 nonce: self.nonce 45 }, 46 success: function ( data ) { 47 $.each( data.inlineStyles, function ( handle, css ) { 48 var id = 'wp-inline-style-' + handle; 49 $( '#' + id ).text( css ); 50 } ); 51 52 if ( data.nonce ) { 53 self.nonce = data.nonce; 54 } 55 } 56 } ); 57 }; 58 59 self.refreshCss = _.debounce( self.refreshCss, self.debounceDelay ); 60 61 $.each( self.inlineStyleSettings, function ( i, setting ) { 62 wp.customize( setting, function ( value ) { 63 value.bind( self.refreshCss ); 64 }); 65 }); 66 67 return self; 68 } )( jQuery ); -
src/wp-includes/class.wp-styles.php
diff --git src/wp-includes/class.wp-styles.php src/wp-includes/class.wp-styles.php index 1a017ac..0de9051 100644
class WP_Styles extends WP_Dependencies { 120 120 } 121 121 122 122 public function add_inline_style( $handle, $code ) { 123 if ( ! $code )123 if ( ! $code ) { 124 124 return false; 125 } 125 126 126 127 $after = $this->get_data( $handle, 'after' ); 127 if ( ! $after )128 if ( ! $after ) { 128 129 $after = array(); 130 } 129 131 130 132 $after[] = $code; 131 133 … … class WP_Styles extends WP_Dependencies { 135 137 public function print_inline_style( $handle, $echo = true ) { 136 138 $output = $this->get_data( $handle, 'after' ); 137 139 138 if ( empty( $output ) ) 140 if ( empty( $output ) ) { 139 141 return false; 142 } 140 143 141 144 $output = implode( "\n", $output ); 142 145 143 if ( ! $echo )146 if ( ! $echo ) { 144 147 return $output; 148 } 145 149 146 echo "<style type='text/css'>\n";150 echo "<style id='" . esc_attr( "wp-inline-style-$handle" ) . "' type='text/css'>\n"; 147 151 echo "$output\n"; 148 152 echo "</style>\n"; 149 153