Skip to content

Commit

Permalink
Adds filters to shortcircuit the GS public API
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
oandregal committed Nov 26, 2021
1 parent 75078c8 commit 9ae37db
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/compat/wordpress-5.9/get-global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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 = (
Expand Down

0 comments on commit 9ae37db

Please sign in to comment.