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

Update hook's names from global_styles_* to theme_json_* #44159

Merged
merged 1 commit into from
Sep 14, 2022
Merged
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
14 changes: 7 additions & 7 deletions docs/reference-guides/filters/global-styles-filters.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Global Styles Filters

WordPress 6.1 has introduced some server-side filters to hook into the data provided to Global Styles & Settings:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only updates the names of the filters. I'm undecided as to whether we should rename the "Global Styles Filters" page to "Theme.json Filters". Because it's published to the block editor handbook already, renaming it requires asking someone from the meta team to remove the old one. As it is also works fine if we want to add new filters later, so I lean towards maintaining what we have.

WordPress 6.1 has introduced some server-side filters to hook into the `theme.json` data provided at the different data layers:

- `global_styles_default`: hooks into the default data provided by WordPress
- `global_styles_blocks`: hooks into the data provided by the blocks
- `global_styles_theme`: hooks into the data provided by the theme
- `global_styles_user`: hooks into the data provided by the user
- `theme_json_default`: hooks into the default data provided by WordPress
- `theme_json_blocks`: hooks into the data provided by the blocks
- `theme_json_theme`: hooks into the data provided by the theme
- `theme_json_user`: hooks into the data provided by the user

Each filter receives an instance of the `WP_Theme_JSON_Data` class with the data for the respective layer. To provide new data, the filter callback needs to use the `update_with( $new_data )` method, where `$new_data` is a valid `theme.json`-like structure. As with any `theme.json`, the new data needs to declare which `version` of the `theme.json` is using, so it can correctly be migrated to the runtime one, should it be different.

Expand All @@ -14,7 +14,7 @@ _Example:_
This is how to pass a new color palette for the theme and disable the text color UI:

```php
function filter_global_styles_theme( $theme_json ){
function filter_theme_json_theme( $theme_json ){
$new_data = array(
'version' => 2,
'settings' => array(
Expand All @@ -38,5 +38,5 @@ function filter_global_styles_theme( $theme_json ){

return $theme_json->update_with( $new_data );
}
add_filter( 'global_styles_theme', 'filter_global_styles_theme' );
add_filter( 'theme_json_theme', 'filter_theme_json_theme' );
```
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function get_core_data() {
*
* @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data.
*/
$theme_json = apply_filters( 'global_styles_default', new WP_Theme_JSON_Data_Gutenberg( $config, 'default' ) );
$theme_json = apply_filters( 'theme_json_default', new WP_Theme_JSON_Data_Gutenberg( $config, 'default' ) );
$config = $theme_json->get_data();
static::$core = new WP_Theme_JSON_Gutenberg( $config, 'default' );

Expand Down Expand Up @@ -92,7 +92,7 @@ public static function get_user_data() {
*
* @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data.
*/
$theme_json = apply_filters( 'global_styles_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) );
$theme_json = apply_filters( 'theme_json_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) );
$config = $theme_json->get_data();
return new WP_Theme_JSON_Gutenberg( $config, 'custom' );
}
Expand All @@ -114,7 +114,7 @@ public static function get_user_data() {
*
* @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data.
*/
$theme_json = apply_filters( 'global_styles_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) );
$theme_json = apply_filters( 'theme_json_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) );
$config = $theme_json->get_data();
static::$user = new WP_Theme_JSON_Gutenberg( $config, 'custom' );

Expand Down
4 changes: 2 additions & 2 deletions lib/experimental/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function get_theme_data( $deprecated = array(), $settings = array(
*
* @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data.
*/
$theme_json = apply_filters( 'global_styles_theme', new WP_Theme_JSON_Data_Gutenberg( $theme_json_data, 'theme' ) );
$theme_json = apply_filters( 'theme_json_theme', new WP_Theme_JSON_Data_Gutenberg( $theme_json_data, 'theme' ) );
$theme_json_data = $theme_json->get_data();
static::$theme = new WP_Theme_JSON_Gutenberg( $theme_json_data );

Expand Down Expand Up @@ -141,7 +141,7 @@ public static function get_block_data() {
*
* @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data.
*/
$theme_json = apply_filters( 'global_styles_blocks', new WP_Theme_JSON_Data_Gutenberg( $config, 'core' ) );
$theme_json = apply_filters( 'theme_json_blocks', new WP_Theme_JSON_Data_Gutenberg( $config, 'core' ) );
$config = $theme_json->get_data();

// Core here means it's the lower level part of the styles chain.
Expand Down