Editor: Backport Elements API updates.
This commit backports the original PRs from Gutenberg repository: * [https://github.com/WordPress/gutenberg/pull/40260 #40260 Add support for button elements to theme.json] * [https://github.com/WordPress/gutenberg/pull/40889 #40889 Theme Json: Don't output double selectors for elements inside blocks] * [https://github.com/WordPress/gutenberg/pull/41140 #41140 Global Styles: Add support for caption elements] * [https://github.com/WordPress/gutenberg/pull/41160 #41160 Global Styles: Load block CSS conditionally] * [https://github.com/WordPress/gutenberg/pull/41240 #41240 Global Styles: Button Element: update button element selector] * [https://github.com/WordPress/gutenberg/pull/41335 #41335 Duotone: Fix CSS Selectors rendered by theme.json duotone/filter settings for blocks on public pages] * [https://github.com/WordPress/gutenberg/pull/41446 #41446 Block styles: Account for style block nodes that have no name] * [https://github.com/WordPress/gutenberg/pull/41696 #41696 Global Styles: Allow references to values in other locations in the tree] * [https://github.com/WordPress/gutenberg/pull/41753 #41753 Elements: Add an API make it easier to get class names] * [https://github.com/WordPress/gutenberg/pull/41786 #41786 Support pseudo selectors on elements in theme json] * [https://github.com/WordPress/gutenberg/pull/41822 #41822 Elements: Button - Fix element selectors] * [https://github.com/WordPress/gutenberg/pull/41981 #41981 Global Styles: Add support for heading elements] * [https://github.com/WordPress/gutenberg/pull/42072 #42072 Fix link element hover bleeding into button element default styles] * [https://github.com/WordPress/gutenberg/pull/42096 #42096 Add visited to link element allowed pseudo selector list] * [https://github.com/WordPress/gutenberg/pull/42669 #42669 Link elements: Add a :where selector to the :not to lower specificity] * [https://github.com/WordPress/gutenberg/pull/42776 #42776 Theme JSON: Add a static $blocks_metadata data definition to the Gutenberg instance of WP_Theme_JSON] * [https://github.com/WordPress/gutenberg/pull/43088 #43088 Pseudo elements supports on button elements] * [https://github.com/WordPress/gutenberg/pull/43167 #43167 Theme_JSON: Use existing append_to_selector for pseudo elements] * [https://github.com/WordPress/gutenberg/pull/43988 #43988 Styles API: Fixed selectors for nested elements] Props onemaggie, bernhard-reiter, cbravobernal, mmaattiiaass, scruffian, andraganescu, dpcalhoun, get_dave, Mamaduka, SergeyBiryukov. See #56467. Built from https://develop.svn.wordpress.org/trunk@54118 git-svn-id: http://core.svn.wordpress.org/trunk@53677 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -192,3 +192,45 @@ function wp_get_global_styles_svg_filters() {
|
||||
|
||||
return $svgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds global style rules to the inline style for each block.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*/
|
||||
function wp_add_global_styles_for_blocks() {
|
||||
$tree = WP_Theme_JSON_Resolver::get_merged_data();
|
||||
$block_nodes = $tree->get_styles_block_nodes();
|
||||
foreach ( $block_nodes as $metadata ) {
|
||||
$block_css = $tree->get_styles_for_block( $metadata );
|
||||
|
||||
if ( isset( $metadata['name'] ) ) {
|
||||
$block_name = str_replace( 'core/', '', $metadata['name'] );
|
||||
/*
|
||||
* These block styles are added on block_render.
|
||||
* This hooks inline CSS to them so that they are loaded conditionally
|
||||
* based on whether or not the block is used on the page.
|
||||
*/
|
||||
wp_add_inline_style( 'wp-block-' . $block_name, $block_css );
|
||||
}
|
||||
|
||||
// The likes of block element styles from theme.json do not have $metadata['name'] set.
|
||||
if ( ! isset( $metadata['name'] ) && ! empty( $metadata['path'] ) ) {
|
||||
$result = array_values(
|
||||
array_filter(
|
||||
$metadata['path'],
|
||||
function ( $item ) {
|
||||
if ( strpos( $item, 'core/' ) !== false ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
)
|
||||
);
|
||||
if ( isset( $result[0] ) ) {
|
||||
$block_name = str_replace( 'core/', '', $result[0] );
|
||||
wp_add_inline_style( 'wp-block-' . $block_name, $block_css );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user