Script Loader: Load block support styles in the head for block themes.
The dynamic block styles for layout and elements should be loaded in the head for block themes. While that should also be the case for classic themes, the current mechanism we use (render_block) does not allow us to do that, hence, this PR doesn't change anything for them and will be loaded the body. Props oandregal, youknowriad, wpsoul. Fixes #55148. Built from https://develop.svn.wordpress.org/trunk@52741 git-svn-id: http://core.svn.wordpress.org/trunk@52330 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
a04ccd9c90
commit
a73446f6ed
|
@ -46,7 +46,7 @@ function wp_render_elements_support( $block_content, $block ) {
|
||||||
}
|
}
|
||||||
$link_color_declaration = esc_html( safecss_filter_attr( "color: $link_color" ) );
|
$link_color_declaration = esc_html( safecss_filter_attr( "color: $link_color" ) );
|
||||||
|
|
||||||
$style = "<style>.$class_name a{" . $link_color_declaration . ";}</style>\n";
|
$style = ".$class_name a{" . $link_color_declaration . ';}';
|
||||||
|
|
||||||
// Like the layout hook this assumes the hook only applies to blocks with a single wrapper.
|
// Like the layout hook this assumes the hook only applies to blocks with a single wrapper.
|
||||||
// Retrieve the opening tag of the first HTML element.
|
// Retrieve the opening tag of the first HTML element.
|
||||||
|
@ -68,17 +68,7 @@ function wp_render_elements_support( $block_content, $block ) {
|
||||||
$content = substr_replace( $block_content, ' class="' . $class_name . '"', $first_element_offset + strlen( $first_element ) - 1, 0 );
|
$content = substr_replace( $block_content, ' class="' . $class_name . '"', $first_element_offset + strlen( $first_element ) - 1, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
wp_enqueue_block_support( $style );
|
||||||
* Ideally styles should be loaded in the head, but blocks may be parsed
|
|
||||||
* after that, so loading in the footer for now.
|
|
||||||
* See https://core.trac.wordpress.org/ticket/53494.
|
|
||||||
*/
|
|
||||||
add_action(
|
|
||||||
'wp_footer',
|
|
||||||
static function () use ( $style ) {
|
|
||||||
echo $style;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,17 +175,7 @@ function wp_render_layout_support_flag( $block_content, $block ) {
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
wp_enqueue_block_support( $style );
|
||||||
* Ideally styles should be loaded in the head, but blocks may be parsed
|
|
||||||
* after that, so loading in the footer for now.
|
|
||||||
* See https://core.trac.wordpress.org/ticket/53494.
|
|
||||||
*/
|
|
||||||
add_action(
|
|
||||||
'wp_footer',
|
|
||||||
static function () use ( $style ) {
|
|
||||||
echo '<style>' . $style . '</style>';
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1332,3 +1332,29 @@ function _wp_multiple_block_styles( $metadata ) {
|
||||||
return $metadata;
|
return $metadata;
|
||||||
}
|
}
|
||||||
add_filter( 'block_type_metadata', '_wp_multiple_block_styles' );
|
add_filter( 'block_type_metadata', '_wp_multiple_block_styles' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function takes care of adding inline styles
|
||||||
|
* in the proper place, depending on the theme in use.
|
||||||
|
*
|
||||||
|
* For block themes, it's loaded in the head.
|
||||||
|
* For classic ones, it's loaded in the body
|
||||||
|
* because the wp_head action (and wp_enqueue_scripts)
|
||||||
|
* happens before the render_block.
|
||||||
|
*
|
||||||
|
* See https://core.trac.wordpress.org/ticket/53494.
|
||||||
|
*
|
||||||
|
* @param string $style String containing the CSS styles to be added.
|
||||||
|
*/
|
||||||
|
function wp_enqueue_block_support( $style ) {
|
||||||
|
$action_hook_name = 'wp_footer';
|
||||||
|
if ( wp_is_block_theme() ) {
|
||||||
|
$action_hook_name = 'wp_enqueue_scripts';
|
||||||
|
}
|
||||||
|
add_action(
|
||||||
|
$action_hook_name,
|
||||||
|
function () use ( $style ) {
|
||||||
|
echo "<style>$style</style>\n";
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.0-alpha-52740';
|
$wp_version = '6.0-alpha-52741';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue