Skip to content

Commit

Permalink
Deprecate old methods to clear the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Nov 29, 2022
1 parent cf99597 commit 83af27a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/compat/wordpress-6.2/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* @package gutenberg
*/

add_action( 'start_previewing_theme', 'gutenberg_get_global_stylesheet_clean_cache' );
add_action( 'start_previewing_theme', 'wp_theme_has_theme_json_clean_cache' );
add_action( 'start_previewing_theme', array( 'WP_Theme_JSON_Resolver_Gutenberg', 'clean_cached_data' ) );
add_action( 'switch_theme', 'gutenberg_get_global_stylesheet_clean_cache' );
add_action( 'switch_theme', 'wp_theme_has_theme_json_clean_cache' );
add_action( 'switch_theme', array( 'WP_Theme_JSON_Resolver_Gutenberg', 'clean_cached_data' ) );
/**
* When backporting to core, the existing filters hooked to WP_Theme_JSON_Resolver::clean_cached_data()
* need to be removed.
*/
add_action( 'start_previewing_theme', '_gutenberg_clean_theme_json_caches' );
add_action( 'switch_theme', '_gutenberg_clean_theme_json_caches' );
20 changes: 18 additions & 2 deletions lib/compat/wordpress-6.2/get-global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ function wp_theme_has_theme_json() {
if ( ! function_exists( 'wp_theme_has_theme_json_clean_cache' ) ) {
/**
* Function to clean the cache used by wp_theme_has_theme_json method.
*
* Not to backport to core. Delete it instead.
*/
function wp_theme_has_theme_json_clean_cache() {
wp_cache_delete( 'wp_theme_has_theme_json', 'theme_json' );
_deprecated_function( __METHOD__, '14.7' );
}
}

Expand Down Expand Up @@ -136,9 +138,11 @@ function gutenberg_get_global_stylesheet( $types = array() ) {

/**
* Clean the cache used by the `gutenberg_get_global_stylesheet` function.
*
* Not to backport to core. Delete it instead.
*/
function gutenberg_get_global_stylesheet_clean_cache() {
wp_cache_delete( 'gutenberg_get_global_stylesheet', 'theme_json' );
_deprecated_function( __METHOD__, '14.7' );
}

/**
Expand Down Expand Up @@ -180,6 +184,18 @@ function gutenberg_get_global_settings( $path = array(), $context = array() ) {
return _wp_array_get( $settings, $path, $settings );
}

/**
* Private function to clean the caches used by gutenberg_get_global_settings method.
*
* @access private
*/
function _gutenberg_clean_theme_json_caches() {
wp_cache_delete( 'wp_theme_has_theme_json', 'theme_json' );
wp_cache_delete( 'gutenberg_get_global_stylesheet', 'theme_json' );
wp_cache_delete( 'gutenberg_get_global_settings_theme', 'theme_json' );
WP_Theme_JSON_Resolver_Gutenberg::clean_cached_data();
}

/**
* Tell the cache mechanisms not to persist theme.json data across requests.
* The data stored under this cache group:
Expand Down

0 comments on commit 83af27a

Please sign in to comment.