<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[39209] trunk: Customize: Improve extensibility of Custom CSS.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/39209">39209</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/39209","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>westonruter</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-11-13 02:42:04 +0000 (Sun, 13 Nov 2016)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Customize: Improve extensibility of Custom CSS.

* Add `customize_value_custom_css` filter to `WP_Customize_Custom_CSS::value()` method.
* Introduce `customize_update_custom_css_post_content_args` filter in `WP_Customize_Custom_CSS::update()` method.
* Make clear that `wp_get_custom_css()` and `wp_get_custom_css` filter are specifically for obtaining the value to render/display. Eliminate use of `wp_get_custom_css()` when getting the setting value. Use the underlying `post_value` directly when `is_previewed`.
* Move anonymous functions handing JS previewing for `custom_logo`, `custom_css`, and `background` into named functions on the `wp.customize.settingPreviewHandlers` to allow plugins to override/extend preview logic.
* Update `_custom_background_cb` to always print a `style` tag wen in the customizer preview, and update background preview logic to replace existing style element instead of appending a new style to the head so that background changes don't unexpectedly override any Custom CSS in the preview's stylesheet cascade.

Props westonruter, georgestephanis.
See <a href="https://core.trac.wordpress.org/ticket/22058">#22058</a>.
Fixes <a href="https://core.trac.wordpress.org/ticket/38672">#38672</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludescustomizeclasswpcustomizecustomcsssettingphp">trunk/src/wp-includes/customize/class-wp-customize-custom-css-setting.php</a></li>
<li><a href="#trunksrcwpincludesjscustomizepreviewjs">trunk/src/wp-includes/js/customize-preview.js</a></li>
<li><a href="#trunksrcwpincludesthemephp">trunk/src/wp-includes/theme.php</a></li>
<li><a href="#trunktestsphpunittestscustomizecustomcsssettingphp">trunk/tests/phpunit/tests/customize/custom-css-setting.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludescustomizeclasswpcustomizecustomcsssettingphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/customize/class-wp-customize-custom-css-setting.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/customize/class-wp-customize-custom-css-setting.php 2016-11-13 01:29:29 UTC (rev 39208)
+++ trunk/src/wp-includes/customize/class-wp-customize-custom-css-setting.php   2016-11-13 02:42:04 UTC (rev 39209)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -100,10 +100,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Filter wp_get_custom_css for applying customized value to return value.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Filter `wp_get_custom_css` for applying the customized value.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * This is used in the preview when `wp_get_custom_css()` is called for rendering the styles.
+        *
</ins><span class="cx" style="display: block; padding: 0 10px">          * @since 4.7.0
</span><span class="cx" style="display: block; padding: 0 10px">         * @access private
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @see wp_get_custom_css()
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param string $css        Original CSS.
</span><span class="cx" style="display: block; padding: 0 10px">         * @param string $stylesheet Current stylesheet.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -120,18 +123,31 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Fetch the value of the setting.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Fetch the value of the setting. Will return the previewed value when `preview()` is called.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 4.7.0
</span><span class="cx" style="display: block; padding: 0 10px">         * @access public
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @see WP_Customize_Setting::value()
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @return string
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function value() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $value = wp_get_custom_css( $this->stylesheet );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $id_base = $this->id_data['base'];
+               if ( $this->is_previewed && null !== $this->post_value( null ) ) {
+                       return $this->post_value();
+               }
+               $value = '';
+               $post = wp_get_custom_css_post( $this->stylesheet );
+               if ( $post ) {
+                       $value = $post->post_content;
+               }
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( empty( $value ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $value = $this->default;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               /** This filter is documented in wp-includes/class-wp-customize-setting.php */
+               $value = apply_filters( "customize_value_{$id_base}", $value, $this );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 return $value;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -226,15 +242,58 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return int|false The post ID or false if the value could not be saved.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function update( $css ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $setting = $this;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( empty( $css ) ) {
+                       $css = '';
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $args = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'post_content' => $css ? $css : '',
-                       'post_title' => $this->stylesheet,
-                       'post_name' => sanitize_title( $this->stylesheet ),
-                       'post_type' => 'custom_css',
-                       'post_status' => 'publish',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'post_content' => $css,
+                       'post_content_filtered' => '',
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                /**
+                * Filters the `post_content` and `post_content_filtered` args for a `custom_css` post being updated.
+                *
+                * This filter can be used by plugin that offer CSS pre-processors, to store the original
+                * pre-processed CSS in `post_content_filtered` and then store processed CSS in `post_content`.
+                * When used in this way, the `post_content_filtered` should be supplied as the setting value
+                * instead of `post_content` via a the `customize_value_custom_css` filter, for example:
+                *
+                * <code>
+                * add_filter( 'customize_value_custom_css', function( $value, $setting ) {
+                *     $post = wp_get_custom_css_post( $setting->stylesheet );
+                *     if ( $post && ! empty( $post->post_content_filtered ) ) {
+                *         $css = $post->post_content_filtered;
+                *     }
+                *     return $css;
+                * }, 10, 2 );
+                * </code>
+                *
+                * @since 4.7.0
+                * @param array  $args {
+                *     Content post args (unslashed) for `wp_update_post()`/`wp_insert_post()`.
+                *
+                *     @type string $post_content          CSS.
+                *     @type string $post_content_filtered Pre-processed CSS. Normally empty string.
+                * }
+                * @param string                          $css     Original CSS being updated.
+                * @param WP_Customize_Custom_CSS_Setting $setting Custom CSS Setting.
+                */
+               $args = apply_filters( 'customize_update_custom_css_post_content_args', $args, $css, $setting );
+               $args = wp_array_slice_assoc( $args, array( 'post_content', 'post_content_filtered' ) );
+
+               $args = array_merge(
+                       $args,
+                       array(
+                               'post_title' => $this->stylesheet,
+                               'post_name' => sanitize_title( $this->stylesheet ),
+                               'post_type' => 'custom_css',
+                               'post_status' => 'publish',
+                       )
+               );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // Update post if it already exists, otherwise create a new one.
</span><span class="cx" style="display: block; padding: 0 10px">                $post = wp_get_custom_css_post( $this->stylesheet );
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $post ) {
</span></span></pre></div>
<a id="trunksrcwpincludesjscustomizepreviewjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/js/customize-preview.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/js/customize-preview.js     2016-11-13 01:29:29 UTC (rev 39208)
+++ trunk/src/wp-includes/js/customize-preview.js       2016-11-13 02:42:04 UTC (rev 39209)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -594,6 +594,63 @@
</span><span class="cx" style="display: block; padding: 0 10px">                };
</span><span class="cx" style="display: block; padding: 0 10px">        } )();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        api.settingPreviewHandlers = {
+
+               /**
+                * Preview changes to custom logo.
+                *
+                * @param {number} attachmentId Attachment ID for custom logo.
+                * @returns {void}
+                */
+               custom_logo: function( attachmentId ) {
+                       $( 'body' ).toggleClass( 'wp-custom-logo', !! attachmentId );
+               },
+
+               /**
+                * Preview changes to custom css.
+                *
+                * @param {string} value Custom CSS..
+                * @returns {void}
+                */
+               custom_css: function( value ) {
+                       $( '#wp-custom-css' ).text( value );
+               },
+
+               /**
+                * Preview changes to any of the background settings.
+                *
+                * @returns {void}
+                */
+               background: function() {
+                       var css = '', settings = {};
+
+                       _.each( ['color', 'image', 'preset', 'position_x', 'position_y', 'size', 'repeat', 'attachment'], function( prop ) {
+                               settings[ prop ] = api( 'background_' + prop );
+                       } );
+
+                       /*
+                        * The body will support custom backgrounds if either the color or image are set.
+                        *
+                        * See get_body_class() in /wp-includes/post-template.php
+                        */
+                       $( document.body ).toggleClass( 'custom-background', !! ( settings.color() || settings.image() ) );
+
+                       if ( settings.color() ) {
+                               css += 'background-color: ' + settings.color() + ';';
+                       }
+
+                       if ( settings.image() ) {
+                               css += 'background-image: url("' + settings.image() + '");';
+                               css += 'background-size: ' + settings.size() + ';';
+                               css += 'background-position: ' + settings.position_x() + ' ' + settings.position_y() + ';';
+                               css += 'background-repeat: ' + settings.repeat() + ';';
+                               css += 'background-attachment: ' + settings.attachment() + ';';
+                       }
+
+                       $( '#custom-background-css' ).text( 'body.custom-background { ' + css + ' }' );
+               }
+       };
+
</ins><span class="cx" style="display: block; padding: 0 10px">         $( function() {
</span><span class="cx" style="display: block; padding: 0 10px">                var bg, setValue;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -759,39 +816,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return 'background_' + prop;
</span><span class="cx" style="display: block; padding: 0 10px">                } );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                api.when.apply( api, bg ).done( function( color, image, preset, positionX, positionY, size, repeat, attachment ) {
-                       var body = $(document.body),
-                               head = $('head'),
-                               style = $('#custom-background-css'),
-                               update;
-
-                       update = function() {
-                               var css = '';
-
-                               // The body will support custom backgrounds if either
-                               // the color or image are set.
-                               //
-                               // See get_body_class() in /wp-includes/post-template.php
-                               body.toggleClass( 'custom-background', !! ( color() || image() ) );
-
-                               if ( color() )
-                                       css += 'background-color: ' + color() + ';';
-
-                               if ( image() ) {
-                                       css += 'background-image: url("' + image() + '");';
-                                       css += 'background-size: ' + size() + ';';
-                                       css += 'background-position: ' + positionX() + ' ' + positionY() + ';';
-                                       css += 'background-repeat: ' + repeat() + ';';
-                                       css += 'background-attachment: ' + attachment() + ';';
-                               }
-
-                               // Refresh the stylesheet by removing and recreating it.
-                               style.remove();
-                               style = $('<style type="text/css" id="custom-background-css">body.custom-background { ' + css + ' }</style>').appendTo( head );
-                       };
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         api.when.apply( api, bg ).done( function() {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $.each( arguments, function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                this.bind( update );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         this.bind( api.settingPreviewHandlers.background );
</ins><span class="cx" style="display: block; padding: 0 10px">                         });
</span><span class="cx" style="display: block; padding: 0 10px">                });
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -802,17 +829,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span><span class="cx" style="display: block; padding: 0 10px">                 * @since 4.5.0
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                api( 'custom_logo', function( setting ) {
-                       $( 'body' ).toggleClass( 'wp-custom-logo', !! setting.get() );
-                       setting.bind( function( attachmentId ) {
-                               $( 'body' ).toggleClass( 'wp-custom-logo', !! attachmentId );
-                       });
-               });
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         api( 'custom_logo', function ( setting ) {
+                       api.settingPreviewHandlers.custom_logo.call( setting, setting.get() );
+                       setting.bind( api.settingPreviewHandlers.custom_logo );
+               } );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                api( 'custom_css[' + api.settings.theme.stylesheet + ']', function( value ) {
-                       value.bind( function( to ) {
-                               $( '#wp-custom-css' ).text( to );
-                       } );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         api( 'custom_css[' + api.settings.theme.stylesheet + ']', function( setting ) {
+                       setting.bind( api.settingPreviewHandlers.custom_css );
</ins><span class="cx" style="display: block; padding: 0 10px">                 } );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                api.trigger( 'preview-ready' );
</span></span></pre></div>
<a id="trunksrcwpincludesthemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/theme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/theme.php   2016-11-13 01:29:29 UTC (rev 39208)
+++ trunk/src/wp-includes/theme.php     2016-11-13 02:42:04 UTC (rev 39209)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1500,8 +1500,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $color = false;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        if ( ! $background && ! $color )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $background && ! $color ) {
+               if ( is_customize_preview() ) {
+                       echo '<style type="text/css" id="custom-background-css"></style>';
+               }
</ins><span class="cx" style="display: block; padding: 0 10px">                 return;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        $style = $color ? "background-color: #$color;" : '';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1621,7 +1625,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Fetch the saved Custom CSS content.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Fetch the saved Custom CSS content for rendering.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 4.7.0
</span><span class="cx" style="display: block; padding: 0 10px">  * @access public
</span></span></pre></div>
<a id="trunktestsphpunittestscustomizecustomcsssettingphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/customize/custom-css-setting.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/customize/custom-css-setting.php        2016-11-13 01:29:29 UTC (rev 39208)
+++ trunk/tests/phpunit/tests/customize/custom-css-setting.php  2016-11-13 02:42:04 UTC (rev 39209)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -168,6 +168,95 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Test crud methods on WP_Customize_Custom_CSS_Setting.
+        *
+        * @covers WP_Customize_Custom_CSS_Setting::value()
+        */
+       function test_value_filter() {
+               add_filter( 'customize_value_custom_css', array( $this, 'filter_value' ), 10, 2 );
+               $this->setting->default = '/*default*/';
+               $this->assertEquals( '/*default*//*filtered*/', $this->setting->value() );
+
+               $this->factory()->post->create( array(
+                       'post_title' => $this->setting->stylesheet,
+                       'post_name' => $this->setting->stylesheet,
+                       'post_content' => '/*custom*/',
+                       'post_status' => 'publish',
+                       'post_type' => 'custom_css',
+               ) );
+               $this->assertEquals( '/*custom*//*filtered*/', $this->setting->value() );
+
+               $this->wp_customize->set_post_value( $this->setting->id, '/*overridden*/' );
+               $this->setting->preview();
+               $this->assertEquals( '/*overridden*/', $this->setting->value(), 'Expected value to not be filtered since post value is present.' );
+       }
+
+       /**
+        * Filter value.
+        *
+        * @param string $value                 Value.
+        * @param WP_Customize_Setting $setting Setting.
+        * @return string
+        */
+       function filter_value( $value, $setting ) {
+               $this->assertInstanceOf( 'WP_Customize_Custom_CSS_Setting', $setting );
+               $value .= '/*filtered*/';
+               return $value;
+       }
+
+       /**
+        * Test update filter on WP_Customize_Custom_CSS_Setting.
+        *
+        * @covers WP_Customize_Custom_CSS_Setting::update()
+        */
+       function test_update_filter() {
+               $original_css = 'body { color:red; }';
+               $post_id = $this->factory()->post->create( array(
+                       'post_title' => $this->setting->stylesheet,
+                       'post_name' => $this->setting->stylesheet,
+                       'post_content' => $original_css,
+                       'post_status' => 'publish',
+                       'post_type' => 'custom_css',
+               ) );
+
+               $overridden_css = 'body { color:green; }';
+               $this->wp_customize->set_post_value( $this->setting->id, $overridden_css );
+
+               $post = get_post( $post_id );
+               $original_title = $post->post_title;
+
+               add_filter( 'customize_update_custom_css_post_content_args', array( $this, 'filter_update_post_content_args' ), 10, 3 );
+               $this->setting->save();
+
+               $post = get_post( $post_id );
+               $this->assertEquals( $original_title, $post->post_title );
+               $this->assertContains( $overridden_css, $post->post_content );
+               $this->assertContains( '/* filtered post_content */', $post->post_content );
+               $this->assertContains( '/* filtered post_content_filtered */', $post->post_content_filtered );
+       }
+
+       /**
+        * Filter `customize_update_custom_css_post_content_args`.
+        *
+        * @param array                $args    Post array.
+        * @param string               $css     CSS.
+        * @param WP_Customize_Setting $setting Setting.
+        * @return array Args.
+        */
+       function filter_update_post_content_args( $args, $css, $setting ) {
+               $this->assertInternalType( 'array', $args );
+               $this->assertEqualSets( array( 'post_content', 'post_content_filtered' ), array_keys( $args ) );
+               $this->assertEquals( $css, $args['post_content'] );
+               $this->assertEquals( '', $args['post_content_filtered'] );
+               $this->assertInstanceOf( 'WP_Customize_Custom_CSS_Setting', $setting );
+
+               $args['post_content'] .= '/* filtered post_content */';
+               $args['post_content_filtered'] = '/* filtered post_content_filtered */';
+               $args['post_title'] = 'Ignored';
+               return $args;
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Tests that validation errors are caught appropriately.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * Note that the $validity \WP_Error object must be reset each time
</span></span></pre>
</div>
</div>

</body>
</html>