From cf100a22e52d52bedcc9ecd021d872e6eb84d51b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 17 Feb 2022 11:35:22 +0100 Subject: [PATCH] New settings (works in WordPress 5.9) Rename wp_get_global_settings to gutenberg_get_global_settings. In WordPress 5.9 the wp_* function is already defined, so we can't override them. It's calling the existing WP_Theme_JSON classes in WordPress core so it won't pick up the plugin modification. In the plugin, to make sure these changes work fine in 5.9 as well, we need to use the gutenberg_* function instead. --- lib/block-supports/layout.php | 4 +- .../get-global-styles-and-settings.php | 57 +++++++++---------- lib/global-styles.php | 2 +- 3 files changed, 29 insertions(+), 34 deletions(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index 93c530f5814ff..0d2b4d8420221 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -138,8 +138,8 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { return $block_content; } - $block_gap = wp_get_global_settings( array( 'spacing', 'blockGap' ) ); - $default_layout = wp_get_global_settings( array( 'layout' ) ); + $block_gap = gutenberg_get_global_settings( array( 'spacing', 'blockGap' ) ); + $default_layout = gutenberg_get_global_settings( array( 'layout' ) ); $has_block_gap_support = isset( $block_gap ) ? null !== $block_gap : false; $default_block_layout = _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() ); $used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $default_block_layout; diff --git a/lib/compat/wordpress-5.9/get-global-styles-and-settings.php b/lib/compat/wordpress-5.9/get-global-styles-and-settings.php index 0ac1456bd2e42..e66eb7925364f 100644 --- a/lib/compat/wordpress-5.9/get-global-styles-and-settings.php +++ b/lib/compat/wordpress-5.9/get-global-styles-and-settings.php @@ -5,38 +5,33 @@ * @package gutenberg */ -if ( ! function_exists( 'wp_get_global_settings' ) ) { - /** - * Function to get the settings resulting of merging core, theme, and user data. - * - * @param array $path Path to the specific setting to retrieve. Optional. - * If empty, will return all settings. - * @param array $context { - * Metadata to know where to retrieve the $path from. Optional. - * - * @type string $block_name Which block to retrieve the settings from. - * If empty, it'll return the settings for the global context. - * @type string $origin Which origin to take data from. - * Valid values are 'all' (core, theme, and user) or 'base' (core and theme). - * If empty or unknown, 'all' is used. - * } - * - * @return array The settings to retrieve. - */ - function wp_get_global_settings( $path = array(), $context = array() ) { - if ( ! empty( $context['block_name'] ) ) { - $path = array_merge( array( 'blocks', $context['block_name'] ), $path ); - } - - $origin = 'custom'; - if ( isset( $context['origin'] ) && 'base' === $context['origin'] ) { - $origin = 'theme'; - } - - $settings = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( $origin )->get_settings(); - - return _wp_array_get( $settings, $path, $settings ); +/** + * Function to get the settings resulting of merging core, theme, and user data. + * + * @param array $path Path to the specific setting to retrieve. Optional. + * If empty, will return all settings. + * @param array $context { + * Metadata to know where to retrieve the $path from. Optional. + * + * @type string $block_name Which block to retrieve the settings from. + * If empty, it'll return the settings for the global context. + * @type string $origin Which origin to take data from. + * Valid values are 'all' (core, theme, and user) or 'base' (core and theme). + * If empty or unknown, 'all' is used. + * } + * + * @return array The settings to retrieve. + */ +function gutenberg_get_global_settings( $path = array(), $context = array() ) { + if ( ! empty( $context['block_name'] ) ) { + $path = array_merge( array( 'blocks', $context['block_name'] ), $path ); + } + $origin = 'custom'; + if ( isset( $context['origin'] ) && 'base' === $context['origin'] ) { + $origin = 'theme'; } + $settings = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( $origin )->get_settings(); + return _wp_array_get( $settings, $path, $settings ); } if ( ! function_exists( 'wp_get_global_styles' ) ) { diff --git a/lib/global-styles.php b/lib/global-styles.php index a54373288421a..ec2a3b45c03a7 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -83,7 +83,7 @@ function_exists( 'gutenberg_is_edit_site_page' ) && } // Copied from get_block_editor_settings() at wordpress-develop/block-editor.php. - $settings['__experimentalFeatures'] = wp_get_global_settings(); + $settings['__experimentalFeatures'] = gutenberg_get_global_settings(); if ( isset( $settings['__experimentalFeatures']['color']['palette'] ) ) { $colors_by_origin = $settings['__experimentalFeatures']['color']['palette'];