Ticket #38672: 38672.extensibility.diff
File 38672.extensibility.diff, 6.6 KB (added by , 8 years ago) |
---|
-
src/wp-includes/customize/class-wp-customize-custom-css-setting.php
diff --git src/wp-includes/customize/class-wp-customize-custom-css-setting.php src/wp-includes/customize/class-wp-customize-custom-css-setting.php index ba4a58c..b7fc753 100644
16 16 * 17 17 * @see WP_Customize_Setting 18 18 */ 19 finalclass WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting {19 class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting { 20 20 21 21 /** 22 22 * The setting type. … … final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting { 100 100 } 101 101 102 102 /** 103 * Filter wp_get_custom_css for applying customized value to return value. 103 * Filter `wp_get_custom_css` for applying the customized value. 104 * 105 * This is used in the preview when `wp_get_custom_css()` is called for rendering the styles. 104 106 * 105 107 * @since 4.7.0 106 108 * @access private 109 * @see wp_get_custom_css() 107 110 * 108 111 * @param string $css Original CSS. 109 112 * @param string $stylesheet Current stylesheet. … … final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting { 120 123 } 121 124 122 125 /** 123 * Fetch the value of the setting. 126 * Fetch the value of the setting. Will return the previewed value when `preview()` is called. 124 127 * 125 128 * @since 4.7.0 126 129 * @access public … … final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting { 128 131 * @return string 129 132 */ 130 133 public function value() { 131 $value = wp_get_custom_css( $this->stylesheet ); 134 if ( $this->is_previewed && null !== $this->post_value( null ) ) { 135 return $this->post_value(); 136 } 137 $value = ''; 138 $post = wp_get_custom_css_post( $this->stylesheet ); 139 if ( $post ) { 140 $value = $post->post_content; 141 } 132 142 if ( empty( $value ) ) { 133 143 $value = $this->default; 134 144 } -
src/wp-includes/js/customize-preview.js
diff --git src/wp-includes/js/customize-preview.js src/wp-includes/js/customize-preview.js index be24e41..9a3944f 100644
594 594 }; 595 595 } )(); 596 596 597 api.settingPreviewHandlers = { 598 599 /** 600 * Preview changes to custom logo. 601 * 602 * @param {number} attachmentId Attachment ID for custom logo. 603 * @returns {void} 604 */ 605 custom_logo: function( attachmentId ) { 606 $( 'body' ).toggleClass( 'wp-custom-logo', !! attachmentId ); 607 }, 608 609 /** 610 * Preview changes to custom css. 611 * 612 * @param {string} value Custom CSS.. 613 * @returns {void} 614 */ 615 custom_css: function( value ) { 616 $( '#wp-custom-css' ).text( value ); 617 }, 618 619 /** 620 * Preview changes to any of the background settings. 621 * 622 * @returns {void} 623 */ 624 background: function() { 625 var css = '', settings = {}; 626 627 _.each( ['color', 'image', 'preset', 'position_x', 'position_y', 'size', 'repeat', 'attachment'], function( prop ) { 628 settings[ prop ] = api( 'background_' + prop ); 629 } ); 630 631 /* 632 * The body will support custom backgrounds if either the color or image are set. 633 * 634 * See get_body_class() in /wp-includes/post-template.php 635 */ 636 $( document.body ).toggleClass( 'custom-background', !! ( settings.color() || settings.image() ) ); 637 638 if ( settings.color() ) { 639 css += 'background-color: ' + settings.color() + ';'; 640 } 641 642 if ( settings.image() ) { 643 css += 'background-image: url("' + settings.image() + '");'; 644 css += 'background-size: ' + settings.size() + ';'; 645 css += 'background-position: ' + settings.position_x() + ' ' + settings.position_y() + ';'; 646 css += 'background-repeat: ' + settings.repeat() + ';'; 647 css += 'background-attachment: ' + settings.attachment() + ';'; 648 } 649 650 $( '#custom-background-css' ).text( 'body.custom-background { ' + css + ' }' ); 651 } 652 }; 653 597 654 $( function() { 598 655 var bg, setValue; 599 656 … … 759 816 return 'background_' + prop; 760 817 } ); 761 818 762 api.when.apply( api, bg ).done( function( color, image, preset, positionX, positionY, size, repeat, attachment ) { 763 var body = $(document.body), 764 head = $('head'), 765 style = $('#custom-background-css'), 766 update; 767 768 update = function() { 769 var css = ''; 770 771 // The body will support custom backgrounds if either 772 // the color or image are set. 773 // 774 // See get_body_class() in /wp-includes/post-template.php 775 body.toggleClass( 'custom-background', !! ( color() || image() ) ); 776 777 if ( color() ) 778 css += 'background-color: ' + color() + ';'; 779 780 if ( image() ) { 781 css += 'background-image: url("' + image() + '");'; 782 css += 'background-size: ' + size() + ';'; 783 css += 'background-position: ' + positionX() + ' ' + positionY() + ';'; 784 css += 'background-repeat: ' + repeat() + ';'; 785 css += 'background-attachment: ' + attachment() + ';'; 786 } 787 788 // Refresh the stylesheet by removing and recreating it. 789 style.remove(); 790 style = $('<style type="text/css" id="custom-background-css">body.custom-background { ' + css + ' }</style>').appendTo( head ); 791 }; 792 819 api.when.apply( api, bg ).done( function() { 793 820 $.each( arguments, function() { 794 this.bind( update);821 this.bind( api.settingPreviewHandlers.background ); 795 822 }); 796 823 }); 797 824 … … 802 829 * 803 830 * @since 4.5.0 804 831 */ 805 api( 'custom_logo', function( setting ) { 806 $( 'body' ).toggleClass( 'wp-custom-logo', !! setting.get() ); 807 setting.bind( function( attachmentId ) { 808 $( 'body' ).toggleClass( 'wp-custom-logo', !! attachmentId ); 809 }); 810 }); 832 api( 'custom_logo', function ( setting ) { 833 api.settingPreviewHandlers.custom_logo.call( setting, setting.get() ); 834 setting.bind( api.settingPreviewHandlers.custom_logo ); 835 } ); 811 836 812 api( 'custom_css[' + api.settings.theme.stylesheet + ']', function( value ) { 813 value.bind( function( to ) { 814 $( '#wp-custom-css' ).text( to ); 815 } ); 837 api( 'custom_css[' + api.settings.theme.stylesheet + ']', function( setting ) { 838 setting.bind( api.settingPreviewHandlers.custom_css ); 816 839 } ); 817 840 818 841 api.trigger( 'preview-ready' ); -
src/wp-includes/theme.php
diff --git src/wp-includes/theme.php src/wp-includes/theme.php index baad12f..bf1c55c 100644
function _custom_background_cb() { 1500 1500 $color = false; 1501 1501 } 1502 1502 1503 if ( ! $background && ! $color ) 1503 if ( ! $background && ! $color ) { 1504 if ( is_customize_preview() ) { 1505 echo '<style type="text/css" id="custom-background-css"></style>'; 1506 } 1504 1507 return; 1508 } 1505 1509 1506 1510 $style = $color ? "background-color: #$color;" : ''; 1507 1511 … … function wp_get_custom_css_post( $stylesheet = '' ) { 1621 1625 } 1622 1626 1623 1627 /** 1624 * Fetch the saved Custom CSS content .1628 * Fetch the saved Custom CSS content for rendering. 1625 1629 * 1626 1630 * @since 4.7.0 1627 1631 * @access public