Customize: Move Custom CSS control `placeholder` help text to setting `default` value.

The `WP_Customize_Custom_CSS_Setting::value()` method now returns the `default` if `wp_get_custom_css()` returns empty.

Props westonruter, afercia, helen.
See #35395.
Fixes #38685.


git-svn-id: https://develop.svn.wordpress.org/trunk@39151 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter 2016-11-07 18:12:28 +00:00
parent c78f002ae6
commit 1207af99d4
3 changed files with 11 additions and 5 deletions

View File

@ -3599,6 +3599,7 @@ final class WP_Customize_Manager {
$custom_css_setting = new WP_Customize_Custom_CSS_Setting( $this, sprintf( 'custom_css[%s]', get_stylesheet() ), array( $custom_css_setting = new WP_Customize_Custom_CSS_Setting( $this, sprintf( 'custom_css[%s]', get_stylesheet() ), array(
'capability' => 'unfiltered_css', 'capability' => 'unfiltered_css',
'default' => sprintf( "/*\n%s\n*/", __( "You can add your own CSS here.\n\nClick the help icon above to learn more." ) ),
) ); ) );
$this->add_setting( $custom_css_setting ); $this->add_setting( $custom_css_setting );
@ -3606,9 +3607,6 @@ final class WP_Customize_Manager {
'type' => 'textarea', 'type' => 'textarea',
'section' => 'custom_css', 'section' => 'custom_css',
'settings' => array( 'default' => $custom_css_setting->id ), 'settings' => array( 'default' => $custom_css_setting->id ),
'input_attrs' => array(
'placeholder' => __( "/*\nYou can add your own CSS here.\n\nClick the help icon above to learn more.\n*/" ),
)
) ); ) );
} }

View File

@ -128,7 +128,11 @@ final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting {
* @return string * @return string
*/ */
public function value() { public function value() {
return wp_get_custom_css( $this->stylesheet ); $value = wp_get_custom_css( $this->stylesheet );
if ( empty( $value ) ) {
$value = $this->default;
}
return $value;
} }
/** /**

View File

@ -101,7 +101,7 @@ class Test_WP_Customize_Custom_CSS_Setting extends WP_UnitTestCase {
} }
/** /**
* Test WP_Customize_Custom_CSS_Setting::update(). * Test crud methods on WP_Customize_Custom_CSS_Setting.
* *
* @covers wp_get_custom_css() * @covers wp_get_custom_css()
* @covers WP_Customize_Custom_CSS_Setting::value() * @covers WP_Customize_Custom_CSS_Setting::value()
@ -109,6 +109,10 @@ class Test_WP_Customize_Custom_CSS_Setting extends WP_UnitTestCase {
* @covers WP_Customize_Custom_CSS_Setting::update() * @covers WP_Customize_Custom_CSS_Setting::update()
*/ */
function test_crud() { function test_crud() {
$this->setting->default = '/* Hello World */';
$this->assertEquals( $this->setting->default, $this->setting->value() );
$original_css = 'body { color: black; }'; $original_css = 'body { color: black; }';
$this->factory()->post->create( array( $this->factory()->post->create( array(
'post_title' => $this->setting->stylesheet, 'post_title' => $this->setting->stylesheet,