Make WordPress Core

Ticket #38672: 38672.extensibility.diff

File 38672.extensibility.diff, 6.6 KB (added by westonruter, 8 years ago)

https://github.com/xwp/wordpress-develop/pull/199

  • 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
     
    1616 *
    1717 * @see WP_Customize_Setting
    1818 */
    19 final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting {
     19class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting {
    2020
    2121        /**
    2222         * The setting type.
    final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting { 
    100100        }
    101101
    102102        /**
    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.
    104106         *
    105107         * @since 4.7.0
    106108         * @access private
     109         * @see wp_get_custom_css()
    107110         *
    108111         * @param string $css        Original CSS.
    109112         * @param string $stylesheet Current stylesheet.
    final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting { 
    120123        }
    121124
    122125        /**
    123          * Fetch the value of the setting.
     126         * Fetch the value of the setting. Will return the previewed value when `preview()` is called.
    124127         *
    125128         * @since 4.7.0
    126129         * @access public
    final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting { 
    128131         * @return string
    129132         */
    130133        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                }
    132142                if ( empty( $value ) ) {
    133143                        $value = $this->default;
    134144                }
  • 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
     
    594594                };
    595595        } )();
    596596
     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
    597654        $( function() {
    598655                var bg, setValue;
    599656
     
    759816                        return 'background_' + prop;
    760817                } );
    761818
    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() {
    793820                        $.each( arguments, function() {
    794                                 this.bind( update );
     821                                this.bind( api.settingPreviewHandlers.background );
    795822                        });
    796823                });
    797824
     
    802829                 *
    803830                 * @since 4.5.0
    804831                 */
    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                } );
    811836
    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 );
    816839                } );
    817840
    818841                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() { 
    15001500                $color = false;
    15011501        }
    15021502
    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                }
    15041507                return;
     1508        }
    15051509
    15061510        $style = $color ? "background-color: #$color;" : '';
    15071511
    function wp_get_custom_css_post( $stylesheet = '' ) { 
    16211625}
    16221626
    16231627/**
    1624  * Fetch the saved Custom CSS content.
     1628 * Fetch the saved Custom CSS content for rendering.
    16251629 *
    16261630 * @since 4.7.0
    16271631 * @access public