mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-04 20:54:29 +00:00
Editor: Fix bug where it was not possible to style custom block elements in theme.json.
This changeset resolves a bug where WordPress would only allow HTML elements within core's own blocks to be styled in `theme.json`. Prior to this change, any `theme.json` rules applying to elements in custom blocks were ignored. With this fix it is now possible to style third-party block elements in `theme.json`. Props flixos90, azaozz, costdev, glendaviesnz, spacedmonkey, oandregal. Fixes #57868. git-svn-id: https://develop.svn.wordpress.org/trunk@56254 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -73,6 +73,13 @@
|
||||
"my/third-party-block": {
|
||||
"color": {
|
||||
"background": "hotpink"
|
||||
},
|
||||
"elements": {
|
||||
"cite": {
|
||||
"color": {
|
||||
"text": "white"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -139,6 +139,88 @@ class Tests_Theme_WpAddGlobalStylesForBlocks extends WP_Theme_UnitTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 57868
|
||||
*/
|
||||
public function test_third_party_blocks_inline_styles_for_elements_get_rendered_when_per_block() {
|
||||
$this->set_up_third_party_block();
|
||||
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
|
||||
|
||||
wp_register_style( 'global-styles', false, array(), true, true );
|
||||
wp_enqueue_style( 'global-styles' );
|
||||
wp_add_global_styles_for_blocks();
|
||||
|
||||
$actual = get_echo( 'wp_print_styles' );
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'.wp-block-my-third-party-block cite{color: white;}',
|
||||
$actual
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 57868
|
||||
*/
|
||||
public function test_third_party_blocks_inline_styles_for_elements_get_rendered() {
|
||||
wp_register_style( 'global-styles', false, array(), true, true );
|
||||
wp_enqueue_style( 'global-styles' );
|
||||
wp_add_global_styles_for_blocks();
|
||||
|
||||
$actual = get_echo( 'wp_print_styles' );
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'.wp-block-my-third-party-block cite{color: white;}',
|
||||
$actual
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 57868
|
||||
*
|
||||
* @dataProvider data_wp_get_block_name_from_theme_json_path
|
||||
*
|
||||
* @param array $path An array of keys describing the path to a property in theme.json.
|
||||
* @param string $expected The expected block name.
|
||||
*/
|
||||
public function test_wp_get_block_name_from_theme_json_path( $path, $expected ) {
|
||||
$block_name = wp_get_block_name_from_theme_json_path( $path );
|
||||
$this->assertSame( $expected, $block_name );
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function data_wp_get_block_name_from_theme_json_path() {
|
||||
return array(
|
||||
'core block styles' => array(
|
||||
array( 'styles', 'blocks', 'core/navigation' ),
|
||||
'core/navigation',
|
||||
),
|
||||
'core block element styles' => array(
|
||||
array( 'styles', 'blocks', 'core/navigation', 'elements', 'link' ),
|
||||
'core/navigation',
|
||||
),
|
||||
'custom block styles' => array(
|
||||
array( 'styles', 'blocks', 'my/third-party-block' ),
|
||||
'my/third-party-block',
|
||||
),
|
||||
'custom block element styles' => array(
|
||||
array( 'styles', 'blocks', 'my/third-party-block', 'elements', 'cite' ),
|
||||
'my/third-party-block',
|
||||
),
|
||||
'custom block wrong format' => array(
|
||||
array( 'styles', 'my/third-party-block' ),
|
||||
'',
|
||||
),
|
||||
'invalid path but works for BC' => array(
|
||||
array( 'something', 'core/image' ),
|
||||
'core/image',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
private function set_up_third_party_block() {
|
||||
switch_theme( 'block-theme' );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user