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

Theme JSON classes: Ensure cache is cleared after Template Part block variations are registered #3352

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
9 changes: 9 additions & 0 deletions src/wp-includes/blocks/template-part.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ function build_template_part_block_instance_variations() {
),
);
}

/*
* Clear Theme JSON block cache so that subsequent block registrations are
* respected when it is next accessed. This is required because `get_block_templates`
* has a side effect of caching the list of currently registered blocks.
*/
WP_Theme_JSON_Resolver::clean_cached_data();
WP_Theme_JSON::clean_cached_data();

return $variations;
}

Expand Down
9 changes: 9 additions & 0 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,15 @@ class WP_Theme_JSON {
'typography' => 'typography',
);

/**
* Cleans the cached data so it can be recalculated.
*
* @since 6.1.0
*/
public static function clean_cached_data() {
static::$blocks_metadata = null;
}

/**
* Returns a class name by an element name.
*
Expand Down