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 global styles PHP filters #27509

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion lib/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,17 @@ public static function get_merged_data( $theme_support_data = array(), $origin =
$result->merge( self::get_user_data() );
}

return $result;
/**
* Return merged data.
*
* @param array $theme_support_data Existing block editor settings.
* @param string $origin The source of data the consumer wants.
* Valid values are 'core', 'theme', 'user'.
* Default is 'user'.
*
* @return WP_Theme_JSON
*/
return apply_filters( 'global_styles_get_data', $result, $theme_support_data, $origin );
}

/**
Expand Down
16 changes: 13 additions & 3 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* the corresponding stylesheet.
*
* @param WP_Theme_JSON $tree Input tree.
* @param string $type Type of stylesheet we want accepts 'all', 'block_styles', and 'css_variables'.
* @param string $type Type of stylesheet we want. Accepts 'all', 'block_styles', and 'css_variables'.
*
* @return string Stylesheet.
*/
Expand All @@ -28,7 +28,8 @@ function gutenberg_experimental_global_styles_get_stylesheet( $tree, $type = 'al
// Check if we have the styles already cached.
$cached = get_transient( 'global_styles' );
if ( $cached ) {
return $cached;
/* This filter is documented in lib/global-styles.php */
return apply_filters( 'global_styles_get_stylesheet', $cached, $type, $tree );
}
}

Expand All @@ -49,7 +50,16 @@ function gutenberg_experimental_global_styles_get_stylesheet( $tree, $type = 'al
set_transient( 'global_styles', $stylesheet, MINUTE_IN_SECONDS );
}

return $stylesheet;
/**
* Filter generated styles.
*
* @param string $stylesheet The generated styles.
* @param string $type Type of stylesheet we want. Accepts 'all', 'block_styles', and 'css_variables'.
* @param WP_Theme_JSON $tree Input tree.
*
* @return string
*/
return apply_filters( 'global_styles_get_stylesheet', $stylesheet, $type, $tree );
}

/**
Expand Down