From d45ba69f9f6d5fd3ab594009aa3c865799f5fac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Mon, 22 Nov 2021 12:24:40 +0100 Subject: [PATCH] Update global styles public API (#36610) --- .../get-global-styles-and-settings.php | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) 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 4e43ed9cba899..532e97325055a 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 @@ -8,25 +8,28 @@ /** * 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 string $block_name Which block to retrieve the settings from. Optional - * If empty, it'll return the settings for the global context. - * @param string $origin Which origin to take data from. Optional. - * It can be 'all' (core, theme, and user) or 'base' (core and theme). - * If empty or unknown, 'all' is used. + * @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(), $block_name = '', $origin = 'all' ) { - if ( '' !== $block_name ) { - $path = array_merge( array( 'blocks', $block_name ), $path ); +function gutenberg_get_global_settings( $path = array(), $context = array() ) { + if ( ! empty( $context['block_name'] ) ) { + $path = array_merge( array( 'blocks', $context['block_name'] ), $path ); } - if ( 'base' === $origin ) { + $origin = 'user'; + if ( isset( $context['origin'] ) && 'base' === $context['origin'] ) { $origin = 'theme'; - } else { - $origin = 'user'; } $settings = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( $origin )->get_settings(); @@ -37,25 +40,28 @@ function gutenberg_get_global_settings( $path = array(), $block_name = '', $orig /** * Function to get the styles resulting of merging core, theme, and user data. * - * @param array $path Path to the specific style to retrieve. Optional. - * If empty, will return all styles. - * @param string $block_name Which block to retrieve the styles from. Optional. - * If empty, it'll return the styles for the global context. - * @param string $origin Which origin to take data from. Optional. - * It can be 'all' (core, theme, and user) or 'base' (core and theme). - * If empty or unknown, 'all' is used. + * @param array $path Path to the specific style to retrieve. Optional. + * If empty, will return all styles. + * @param array $context { + * Metadata to know where to retrieve the $path from. Optional. + * + * @type string $block_name Which block to retrieve the styles from. + * If empty, it'll return the styles 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 styles to retrieve. */ -function gutenberg_get_global_styles( $path = array(), $block_name = '', $origin = 'all' ) { - if ( '' !== $block_name ) { - $path = array_merge( array( 'blocks', $block_name ), $path ); +function gutenberg_get_global_styles( $path = array(), $context = array() ) { + if ( ! empty( $context['block_name'] ) ) { + $path = array_merge( array( 'blocks', $context['block_name'] ), $path ); } - if ( 'base' === $origin ) { + $origin = 'user'; + if ( isset( $context['origin'] ) && 'base' === $context['origin'] ) { $origin = 'theme'; - } else { - $origin = 'user'; } $styles = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( $origin )->get_raw_data()['styles'];