Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block theme: Test custom CSS behaviour #8025

Draft
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -1497,12 +1497,10 @@ protected function process_blocks_custom_css( $css, $selector ) {
* Returns the global styles custom CSS.
*
* @since 6.2.0
* @deprecated 6.7.0 Use {@see 'get_stylesheet'} instead.
*
* @return string The global styles custom CSS.
*/
public function get_custom_css() {
_deprecated_function( __METHOD__, '6.7.0', 'get_stylesheet' );
// Add the global styles root CSS.
$stylesheet = isset( $this->theme_json['styles']['css'] ) ? $this->theme_json['styles']['css'] : '';

Expand Down
24 changes: 24 additions & 0 deletions tests/phpunit/tests/theme/wpThemeJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -6119,4 +6119,28 @@ public function test_opt_in_to_block_style_variations() {

$this->assertSame( $expected, $button_variations );
}

public function test_custom_css_behaviour() {
$theme_json = new WP_Theme_JSON(
array(
'version' => WP_Theme_JSON::LATEST_SCHEMA,
'styles' => array(
'css' => 'body {color:purple;}',
'blocks' => array(
'core/paragraph' => array(
'css' => 'color:red;',
),
),
),
)
);

$custom_css = 'body {color:purple;}';
$block_custom_css = ':root :where(p){color:red;}';

// get_custom_css() should return both CSS.
$this->assertSame( $custom_css . $block_custom_css, $theme_json->get_custom_css() );
// Per #6750, The get_stylesheet() returns only $custom_css.
$this->assertSame( $custom_css . $block_custom_css, $theme_json->get_stylesheet( array( 'custom-css' ) ) );
}
}
Loading