-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 registered_block_type action, register clearing Theme JSON cache to fix global styles issue #3392
Add registered_block_type action, register clearing Theme JSON cache to fix global styles issue #3392
Changes from 6 commits
02e2600
2e1c4a8
2002af5
953f969
76fdfe7
5782aa3
a7b7021
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,15 @@ public function register( $name, $args = array() ) { | |
|
||
$this->registered_block_types[ $name ] = $block_type; | ||
|
||
/** | ||
* Fires after a block type is registered. | ||
* | ||
* @since 6.1.0 | ||
* | ||
* @param WP_Block_Type|false $block_type The registered block type on success, or false on failure. | ||
*/ | ||
do_action( 'registered_block_type', $block_type ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not completely sure of what the best naming convention is, but I see some actions use past tense and others use something like 'after_register_block_type' or 'post_register_block_type'. It would be interesting to know if there's a preference! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Same, I'd be curious to hear what folks think! In this case, I borrowed the naming convention from |
||
|
||
return $block_type; | ||
} | ||
|
||
|
@@ -126,6 +135,15 @@ public function unregister( $name ) { | |
$unregistered_block_type = $this->registered_block_types[ $name ]; | ||
unset( $this->registered_block_types[ $name ] ); | ||
|
||
/** | ||
* Fires after a block type is unregistered. | ||
* | ||
* @since 6.1.0 | ||
* | ||
* @param WP_Block_Type|false $block_type The unregistered block type on success, or false on failure. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here about this being incorrect, it looks like it only triggers the action on successful unregistering. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same with the other hook, I've updated this to remove reference to |
||
*/ | ||
do_action( 'unregistered_block_type', $unregistered_block_type ); | ||
|
||
return $unregistered_block_type; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,6 +147,16 @@ function wp_clean_themes_cache( $clear_update_cache = true ) { | |
} | ||
} | ||
|
||
/** | ||
* Clears the cache held by WP_Theme_JSON and WP_Theme_JSON_Resolver classes. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be worth adding more documentation if this is a public function. I'm thinking along the lines of a brief detailing of the side effects calling this function will have. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I've added an extra line here to indicate what the function does. I found it hard to capture in a single sentence without falling into the trap of describing the particular use case with |
||
* | ||
* @since 6.1.0 | ||
*/ | ||
function wp_clean_theme_json_cache() { | ||
WP_Theme_JSON::clean_cached_data(); | ||
WP_Theme_JSON_Resolver::clean_cached_data(); | ||
} | ||
|
||
/** | ||
* Whether a child theme is in use. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can see this won't be called on failure as the function returns early. It seems fine to only call the action on success though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something else that came to mind is that 'Fires after a block type is registered.' might not be specific enough. It might be worth mentioning that it's specifically when a block is registered with the WP_Block_Type_Registry class.
The reason I'm thinking this is that there's the JavaScript
registerBlockType
function, and so documentation readers might get confused about the timing of this action.Same would apply for the unregister action too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated both of the hooks to remove
|false
and the reference to failure, and updated the description to flagwith the WP_Block_Type_Registry class.