Skip to content

Commit

Permalink
Port global styles code to lib/compat/wordpress-5.9: css custom pro…
Browse files Browse the repository at this point in the history
…perties (#37334)
  • Loading branch information
oandregal authored Dec 14, 2021
1 parent 6b6b51e commit 8d9f385
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
20 changes: 20 additions & 0 deletions lib/compat/wordpress-5.9/global-styles-css-custom-properties.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Loads the CSS Custom Properties in use by Global Styles.
*
* @package Gutenberg
*/

// This has been ported as part of default-filters.php.
if ( ! function_exists( 'wp_enqueue_global_styles_css_custom_properties' ) ) {
/**
* Function to enqueue the CSS Custom Properties
* coming from theme.json.
*/
function wp_enqueue_global_styles_css_custom_properties() {
wp_register_style( 'global-styles-css-custom-properties', false, array(), true, true );
wp_add_inline_style( 'global-styles-css-custom-properties', wp_get_global_stylesheet( array( 'variables' ) ) );
wp_enqueue_style( 'global-styles-css-custom-properties' );
}
add_filter( 'enqueue_block_editor_assets', 'wp_enqueue_global_styles_css_custom_properties' );
}
12 changes: 0 additions & 12 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,6 @@ function gutenberg_global_styles_include_support_for_wp_variables( $allow_css, $
return ! ! preg_match( '/^var\(--wp-[a-zA-Z0-9\-]+\)$/', trim( $parts[1] ) );
}

/**
* Function to enqueue the CSS Custom Properties
* coming from theme.json.
*/
function gutenberg_load_css_custom_properties() {
wp_register_style( 'global-styles-css-custom-properties', false, array(), true, true );
wp_add_inline_style( 'global-styles-css-custom-properties', wp_get_global_stylesheet( array( 'variables' ) ) );
wp_enqueue_style( 'global-styles-css-custom-properties' );
}

// The else clause can be removed when plugin support requires WordPress 5.8.0+.
if ( function_exists( 'get_block_editor_settings' ) ) {
add_filter( 'block_editor_settings_all', 'gutenberg_experimental_global_styles_settings', PHP_INT_MAX );
Expand All @@ -289,5 +279,3 @@ function gutenberg_load_css_custom_properties() {
add_filter( 'force_filtered_html_on_import', 'gutenberg_global_styles_force_filtered_html_on_import_filter', 999 );
add_filter( 'safecss_filter_attr_allow_css', 'gutenberg_global_styles_include_support_for_wp_variables', 10, 2 );
// This filter needs to be executed last.

add_filter( 'enqueue_block_editor_assets', 'gutenberg_load_css_custom_properties' );
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-5.9/get-global-styles-and-settings.php';
require __DIR__ . '/compat/wordpress-5.9/json-file-decode.php';
require __DIR__ . '/compat/wordpress-5.9/translate-settings-using-i18n-schema.php';
require __DIR__ . '/compat/wordpress-5.9/global-styles-css-custom-properties.php';
require __DIR__ . '/compat/wordpress-5.9/class-gutenberg-block-template.php';
require __DIR__ . '/compat/wordpress-5.9/templates.php';
require __DIR__ . '/compat/wordpress-5.9/template-parts.php';
Expand Down

0 comments on commit 8d9f385

Please sign in to comment.