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

Fix GitHub Actions failure due to duplicate functions #44052

Merged
merged 3 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
70 changes: 36 additions & 34 deletions lib/compat/wordpress-6.1/get-global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,46 @@
* @package gutenberg
*/

/**
* Adds global style rules to the inline style for each block.
*/
function wp_add_global_styles_for_blocks() {
$tree = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data();
$block_nodes = $tree->get_styles_block_nodes();
foreach ( $block_nodes as $metadata ) {
$block_css = $tree->get_styles_for_block( $metadata );
if ( ! function_exists( 'wp_add_global_styles_for_blocks' ) ) {
/**
* Adds global style rules to the inline style for each block.
*/
function wp_add_global_styles_for_blocks() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking whether or not the core wp_add_global_styles_for_blocks exists, should we instead rename the function to gutenberg_add_global_styles_for_blocks so that in the plugin, we're always calling the Gutenberg version? This would make it similar to the function lower down in this file (gutenberg_get_global_stylesheet).

$tree = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data();
$block_nodes = $tree->get_styles_block_nodes();
foreach ( $block_nodes as $metadata ) {
$block_css = $tree->get_styles_for_block( $metadata );

if ( ! wp_should_load_separate_core_block_assets() ) {
wp_add_inline_style( 'global-styles', $block_css );
continue;
}
if ( ! wp_should_load_separate_core_block_assets() ) {
wp_add_inline_style( 'global-styles', $block_css );
continue;
}

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 );
}
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 ( str_contains( $item, 'core/' ) ) {
return true;
// 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 ( str_contains( $item, 'core/' ) ) {
return true;
}
return false;
}
return false;
}
)
);
if ( isset( $result[0] ) ) {
$block_name = str_replace( 'core/', '', $result[0] );
wp_add_inline_style( 'wp-block-' . $block_name, $block_css );
)
);
if ( isset( $result[0] ) ) {
$block_name = str_replace( 'core/', '', $result[0] );
wp_add_inline_style( 'wp-block-' . $block_name, $block_css );
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/compat/wordpress-6.1/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ function gutenberg_enqueue_global_styles() {
wp_enqueue_style( 'global-styles' );

// add each block as an inline css.
wp_add_global_styles_for_blocks();
if ( ! function_exists( 'wp_add_global_styles_for_blocks' ) ) {
wp_add_global_styles_for_blocks();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check appears to call the function only if it doesn't exist.

Instead, should we use a gutenberg prefixed version of the function?

}

remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
Expand Down