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

Updates theme_json_* filter names with ending *_data #3443

Closed
wants to merge 3 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
10 changes: 5 additions & 5 deletions src/wp-includes/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public static function get_core_data() {
*
* @param WP_Theme_JSON_Data Class to access and update the underlying data.
*/
$theme_json = apply_filters( 'theme_json_default', new WP_Theme_JSON_Data( $config, 'default' ) );
$theme_json = apply_filters( 'wp_theme_json_data_default', new WP_Theme_JSON_Data( $config, 'default' ) );
$config = $theme_json->get_data();
static::$core = new WP_Theme_JSON( $config, 'default' );

Expand Down Expand Up @@ -256,7 +256,7 @@ public static function get_theme_data( $deprecated = array(), $options = array()
*
* @param WP_Theme_JSON_Data Class to access and update the underlying data.
*/
$theme_json = apply_filters( 'theme_json_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) );
$theme_json = apply_filters( 'wp_theme_json_data_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) );
$theme_json_data = $theme_json->get_data();
static::$theme = new WP_Theme_JSON( $theme_json_data );
}
Expand Down Expand Up @@ -357,7 +357,7 @@ public static function get_block_data() {
*
* @param WP_Theme_JSON_Data Class to access and update the underlying data.
*/
$theme_json = apply_filters( 'theme_json_blocks', new WP_Theme_JSON_Data( $config, 'blocks' ) );
$theme_json = apply_filters( 'wp_theme_json_data_blocks', new WP_Theme_JSON_Data( $config, 'blocks' ) );
$config = $theme_json->get_data();

static::$blocks = new WP_Theme_JSON( $config, 'blocks' );
Expand Down Expand Up @@ -490,7 +490,7 @@ public static function get_user_data() {
*
* @param WP_Theme_JSON_Data Class to access and update the underlying data.
*/
$theme_json = apply_filters( 'theme_json_user', new WP_Theme_JSON_Data( $config, 'custom' ) );
$theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data( $config, 'custom' ) );
$config = $theme_json->get_data();
return new WP_Theme_JSON( $config, 'custom' );
}
Expand All @@ -508,7 +508,7 @@ public static function get_user_data() {
}

/** This filter is documented in wp-includes/class-wp-theme-json-resolver.php */
$theme_json = apply_filters( 'theme_json_user', new WP_Theme_JSON_Data( $config, 'custom' ) );
$theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data( $config, 'custom' ) );
$config = $theme_json->get_data();
static::$user = new WP_Theme_JSON( $config, 'custom' );

Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,7 @@ protected static function get_style_nodes( $theme_json, $selectors = array() ) {
*
* @param array $nodes Style nodes with metadata.
*/
return apply_filters( 'theme_json_get_style_nodes', $nodes );
Copy link
Member

Choose a reason for hiding this comment

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

@scruffian @ajlende @draganescu I see that, in Gutenberg land, we name this filter gutenberg_theme_json_style_nodes. Do we need to take any action here? I haven't seen that we prefix the filters depending on environment (wp_ or gutenberg_) in any other case. My understanding is that it's problematic for any consumer that want to use the filter. Though this rationale may have changed, so I've excluded this from WordPress/gutenberg#44940 and can be looked at separately, if necessary.

Copy link

@ajlende ajlende Oct 13, 2022

Choose a reason for hiding this comment

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

Thanks for flagging this @oandregal. I don't see any specific reason for using a different filter in the plugin vs core. I'll open a PR to match this.

EDIT: Opened WordPress/gutenberg#44949

return apply_filters( 'wp_theme_json_get_style_nodes', $nodes );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2429,7 +2429,7 @@ function wp_enqueue_global_styles() {
* This removes the CSS from the global-styles stylesheet and adds it to the inline CSS for each block.
* This filter must be registered before calling wp_get_global_stylesheet();
*/
add_filter( 'theme_json_get_style_nodes', 'wp_filter_out_block_nodes' );
add_filter( 'wp_theme_json_get_style_nodes', 'wp_filter_out_block_nodes' );

$stylesheet = wp_get_global_stylesheet();

Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/theme/wpThemeJsonResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,13 @@ public function test_get_core_data( $should_fire_filter, $core_is_cached, $block
static::$property_blocks_cache->setValue( null, $blocks_cache );
}

$expected_filter_count = did_filter( 'theme_json_default' );
$expected_filter_count = did_filter( 'wp_theme_json_data_default' );
$actual = WP_Theme_JSON_Resolver::get_core_data();
if ( $should_fire_filter ) {
$expected_filter_count++;
}

$this->assertSame( $expected_filter_count, did_filter( 'theme_json_default' ), 'The filter "theme_json_default" should fire the given number of times' );
$this->assertSame( $expected_filter_count, did_filter( 'wp_theme_json_data_default' ), 'The filter "theme_json_default" should fire the given number of times' );
$this->assertInstanceOf( WP_Theme_JSON::class, $actual, 'WP_Theme_JSON_Resolver::get_core_data() should return instance of WP_Theme_JSON' );
$this->assertSame( static::$property_core->getValue(), $actual, 'WP_Theme_JSON_Resolver::$core property should be the same object as returned from WP_Theme_JSON_Resolver::get_core_data()' );
}
Expand Down