From a1d96329631851a9403499c70ea84d448a501c2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Fri, 28 Oct 2022 12:50:33 +0200 Subject: [PATCH] Move gutenberg_get_global_settings to 6.2 compat folder --- .../get-global-styles-and-settings.php | 40 ------------------- .../get-global-styles-and-settings.php | 40 +++++++++++++++++++ 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/lib/compat/wordpress-6.0/get-global-styles-and-settings.php b/lib/compat/wordpress-6.0/get-global-styles-and-settings.php index 5fb715b073ed8..d4f1f9ef03492 100644 --- a/lib/compat/wordpress-6.0/get-global-styles-and-settings.php +++ b/lib/compat/wordpress-6.0/get-global-styles-and-settings.php @@ -5,46 +5,6 @@ * @package gutenberg */ -/** - * 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'; - } - - // TODO: offer a way to clean cache, if neccessary. - static $settings_by_origin = array( - 'default' => null, - 'blocks' => null, - 'theme' => null, - 'custom' => null, - ); - if ( null === $settings_by_origin[ $origin ] ) { - $settings_by_origin[ $origin ] = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( $origin )->get_settings(); - } - - return _wp_array_get( $settings_by_origin[ $origin ], $path, $settings_by_origin[ $origin ] ); -} - /** * Function to get the styles resulting of merging core, theme, and user data. * diff --git a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php index 4dbd9d0ba8bde..0e799f7fd2238 100644 --- a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php +++ b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php @@ -45,3 +45,43 @@ function wp_theme_clean_theme_json_cached_data() { WP_Theme_JSON_Resolver_Gutenberg::clean_cached_data(); } } + +/** + * 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'; + } + + // TODO: offer a way to clean cache, if neccessary. + static $settings_by_origin = array( + 'default' => null, + 'blocks' => null, + 'theme' => null, + 'custom' => null, + ); + if ( null === $settings_by_origin[ $origin ] ) { + $settings_by_origin[ $origin ] = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( $origin )->get_settings(); + } + + return _wp_array_get( $settings_by_origin[ $origin ], $path, $settings_by_origin[ $origin ] ); +}