Skip to content

Commit

Permalink
Update custom CSS handling to be consistent with block global styles.
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Jul 9, 2024
1 parent ebe6f5a commit fe13f3b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/wp-includes/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex
* entered by users does not break other global styles.
*/
$global_styles[] = array(
'css' => wp_get_global_styles_custom_css(),
'css' => wp_get_global_stylesheet( array( 'custom-css' ) ),
'__unstableType' => 'user',
'isGlobalStyles' => true,
);
Expand Down
12 changes: 12 additions & 0 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,12 @@ public function get_stylesheet( $types = array( 'variables', 'styles', 'presets'
$stylesheet .= $this->get_preset_classes( $setting_nodes, $origins );
}

// Load the custom CSS last so it has the highest specificity.
if ( in_array( 'custom-css', $types, true ) ) {
// Add the global styles root CSS.
$stylesheet .= _wp_array_get( $this->theme_json, array( 'styles', 'css' ) );
}

return $stylesheet;
}

Expand Down Expand Up @@ -2692,6 +2698,7 @@ private static function get_block_nodes( $theme_json, $selectors = array(), $opt
'duotone' => $duotone_selector,
'features' => $feature_selectors,
'variations' => $variation_selectors,
'css' => $selector,
);

if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'] ) ) {
Expand Down Expand Up @@ -2913,6 +2920,11 @@ static function ( $pseudo_selector ) use ( $selector ) {
$block_rules .= $this->process_blocks_custom_css( $node['css'], $selector );
}

// 7. Generate and append any custom CSS rules.
if ( isset( $node['css'] ) ) {
$block_rules .= $this->process_blocks_custom_css( $node['css'], $selector );
}

return $block_rules;
}

Expand Down
3 changes: 0 additions & 3 deletions src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,6 @@
add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
add_action( 'wp_footer', 'wp_enqueue_global_styles', 1 );

// Global styles custom CSS.
add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles_custom_css' );

// Block supports, and other styles parsed and stored in the Style Engine.
add_action( 'wp_enqueue_scripts', 'wp_enqueue_stored_styles' );
add_action( 'wp_footer', 'wp_enqueue_stored_styles', 1 );
Expand Down
12 changes: 12 additions & 0 deletions src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,18 @@ function wp_enqueue_global_styles() {

$stylesheet = wp_get_global_stylesheet();

/*
* Dequeue the Customizer's custom CSS
* and add it before the global styles custom CSS.
*/
remove_action( 'wp_head', 'wp_custom_css_cb', 101 );
// Get the custom CSS from the Customizer and add it to the global stylesheet.
$custom_css = wp_get_custom_css();
$stylesheet .= $custom_css;

// Add the global styles custom CSS at the end.
$stylesheet .= wp_get_global_stylesheet( array( 'custom-css' ) );

if ( empty( $stylesheet ) ) {
return;
}
Expand Down

0 comments on commit fe13f3b

Please sign in to comment.