Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Refactor to match new individual custom CSS stylesheet
  • Loading branch information
glendaviesnz authored and aristath committed Feb 3, 2023
commit d6a2a7b1a5426f06e49ad34a75cfc73475569b1a
26 changes: 23 additions & 3 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -1003,9 +1003,29 @@ 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 ) ) {
$stylesheet .= _wp_array_get( $this->theme_json, array( 'styles', 'css' ) );
return $stylesheet;
}

/**
* Returns the global styles custom css.
*
* @since 6.2.0
*
* @return string
*/
public function get_custom_css() {
// Add the global styles root CSS.
$stylesheet = _wp_array_get( $this->theme_json, array( 'styles', 'css' ), '' );

// Add the global styles block CSS.
if ( isset( $this->theme_json['styles']['blocks'] ) ) {
foreach ( $this->theme_json['styles']['blocks'] as $name => $node ) {
$custom_block_css = _wp_array_get( $this->theme_json, array( 'styles', 'blocks', $name, 'css' ) );
if ( $custom_block_css ) {
$selector = static::$blocks_metadata[ $name ]['selector'];
$stylesheet .= $this->process_blocks_custom_css( $custom_block_css, $selector );
}
}
}

return $stylesheet;
Expand Down
3 changes: 1 addition & 2 deletions src/wp-includes/global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ function wp_get_global_styles( $path = array(), $context = array() ) {
*
* @since 5.9.0
* @since 6.1.0 Added 'base-layout-styles' support.
* @since 6.2.0 Support for custom-css type added.
*
* @param array $types Optional. Types of styles to load.
* It accepts as values 'variables', 'presets', 'styles', 'base-layout-styles'.
Expand Down Expand Up @@ -175,7 +174,7 @@ function wp_get_global_stylesheet( $types = array() ) {
if ( empty( $types ) && ! $supports_theme_json ) {
$types = array( 'variables', 'presets', 'base-layout-styles' );
} elseif ( empty( $types ) ) {
$types = array( 'variables', 'styles', 'presets', 'custom-css' );
$types = array( 'variables', 'styles', 'presets' );
}

/*
Expand Down