From 9ae37dbc4fe971f27fb7650526204a3c07290a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Fri, 26 Nov 2021 12:17:18 +0100 Subject: [PATCH] Adds filters to shortcircuit the GS public API By doing this, we allow both the Gutenberg plugin and any 3rd party to change the behavior of these functions. This is useful specially for Gutenberg, where we may need to introduce future changes so we need a way to hook into the core functions. It's inspired by the pre_render_block filter. --- .../get-global-styles-and-settings.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 01a17f07b74268..0968edf2b1e571 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 @@ -24,6 +24,11 @@ * @return array The settings to retrieve. */ function wp_get_global_settings( $path = array(), $context = array() ) { + $pre_global_settings = apply_filters( 'pre_wp_get_global_settings', null, $path, $context ); + if ( null !== $pre_global_settings ) { + return $pre_global_settings; + } + if ( ! empty( $context['block_name'] ) ) { $path = array_merge( array( 'blocks', $context['block_name'] ), $path ); } @@ -58,6 +63,11 @@ function wp_get_global_settings( $path = array(), $context = array() ) { * @return array The styles to retrieve. */ function wp_get_global_styles( $path = array(), $context = array() ) { + $pre_global_styles = apply_filters( 'pre_wp_get_global_styles', null, $path, $context ); + if ( null !== $pre_global_styles ) { + return $pre_global_styles; + } + if ( ! empty( $context['block_name'] ) ) { $path = array_merge( array( 'blocks', $context['block_name'] ), $path ); } @@ -85,6 +95,11 @@ function wp_get_global_styles( $path = array(), $context = array() ) { * @return string Stylesheet. */ function wp_get_global_stylesheet( $types = array() ) { + $pre_global_stylesheet = apply_filters( 'pre_wp_get_global_stylesheet', null, $types ); + if ( null !== $pre_global_stylesheet ) { + return $pre_global_stylesheet; + } + // Return cached value if it can be used and exists. // It's cached by theme to make sure that theme switching clears the cache. $can_use_cached = (