Skip to content

Commit

Permalink
Move gutenberg_get_global_settings to 6.2 compat folder
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Oct 28, 2022
1 parent b06e6c5 commit a1d9632
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
40 changes: 0 additions & 40 deletions lib/compat/wordpress-6.0/get-global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
40 changes: 40 additions & 0 deletions lib/compat/wordpress-6.2/get-global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] );
}

0 comments on commit a1d9632

Please sign in to comment.