diff --git a/lib/compat/wordpress-6.2/default-filters.php b/lib/compat/wordpress-6.2/default-filters.php index 94cfc343e414d5..4698ead7f9bc30 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 78e82981ee31a2..727b7893ccc284 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: