Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filters to shortcircuit the public API of global styles #36909

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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