From 83af27a42182cfc60cc3ed86b5ab74b4442c55e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Tue, 29 Nov 2022 12:51:39 +0100 Subject: [PATCH] Deprecate old methods to clear the cache --- lib/compat/wordpress-6.2/default-filters.php | 12 +++++------ .../get-global-styles-and-settings.php | 20 +++++++++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/compat/wordpress-6.2/default-filters.php b/lib/compat/wordpress-6.2/default-filters.php index 94cfc343e414d..4698ead7f9bc3 100644 --- a/lib/compat/wordpress-6.2/default-filters.php +++ b/lib/compat/wordpress-6.2/default-filters.php @@ -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' ); 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 78e82981ee31a..727b7893ccc28 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 @@ -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' ); } } @@ -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' ); } /** @@ -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: