- Timestamp:
- 11/13/2016 02:42:04 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/customize/class-wp-customize-custom-css-setting.php
r39185 r39209 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. … … 121 124 122 125 /** 123 * Fetch the value of the setting. 124 * 125 * @since 4.7.0 126 * @access public 126 * Fetch the value of the setting. Will return the previewed value when `preview()` is called. 127 * 128 * @since 4.7.0 129 * @access public 130 * @see WP_Customize_Setting::value() 127 131 * 128 132 * @return string 129 133 */ 130 134 public function value() { 131 $value = wp_get_custom_css( $this->stylesheet ); 135 $id_base = $this->id_data['base']; 136 if ( $this->is_previewed && null !== $this->post_value( null ) ) { 137 return $this->post_value(); 138 } 139 $value = ''; 140 $post = wp_get_custom_css_post( $this->stylesheet ); 141 if ( $post ) { 142 $value = $post->post_content; 143 } 132 144 if ( empty( $value ) ) { 133 145 $value = $this->default; 134 146 } 147 148 /** This filter is documented in wp-includes/class-wp-customize-setting.php */ 149 $value = apply_filters( "customize_value_{$id_base}", $value, $this ); 150 135 151 return $value; 136 152 } … … 227 243 */ 228 244 public function update( $css ) { 245 $setting = $this; 246 247 if ( empty( $css ) ) { 248 $css = ''; 249 } 229 250 230 251 $args = array( 231 'post_content' => $css ? $css : '', 232 'post_title' => $this->stylesheet, 233 'post_name' => sanitize_title( $this->stylesheet ), 234 'post_type' => 'custom_css', 235 'post_status' => 'publish', 252 'post_content' => $css, 253 'post_content_filtered' => '', 254 ); 255 256 /** 257 * Filters the `post_content` and `post_content_filtered` args for a `custom_css` post being updated. 258 * 259 * This filter can be used by plugin that offer CSS pre-processors, to store the original 260 * pre-processed CSS in `post_content_filtered` and then store processed CSS in `post_content`. 261 * When used in this way, the `post_content_filtered` should be supplied as the setting value 262 * instead of `post_content` via a the `customize_value_custom_css` filter, for example: 263 * 264 * <code> 265 * add_filter( 'customize_value_custom_css', function( $value, $setting ) { 266 * $post = wp_get_custom_css_post( $setting->stylesheet ); 267 * if ( $post && ! empty( $post->post_content_filtered ) ) { 268 * $css = $post->post_content_filtered; 269 * } 270 * return $css; 271 * }, 10, 2 ); 272 * </code> 273 * 274 * @since 4.7.0 275 * @param array $args { 276 * Content post args (unslashed) for `wp_update_post()`/`wp_insert_post()`. 277 * 278 * @type string $post_content CSS. 279 * @type string $post_content_filtered Pre-processed CSS. Normally empty string. 280 * } 281 * @param string $css Original CSS being updated. 282 * @param WP_Customize_Custom_CSS_Setting $setting Custom CSS Setting. 283 */ 284 $args = apply_filters( 'customize_update_custom_css_post_content_args', $args, $css, $setting ); 285 $args = wp_array_slice_assoc( $args, array( 'post_content', 'post_content_filtered' ) ); 286 287 $args = array_merge( 288 $args, 289 array( 290 'post_title' => $this->stylesheet, 291 'post_name' => sanitize_title( $this->stylesheet ), 292 'post_type' => 'custom_css', 293 'post_status' => 'publish', 294 ) 236 295 ); 237 296
Note: See TracChangeset
for help on using the changeset viewer.