-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix: Return result from wp_register_block_template function #66102
Fix: Return result from wp_register_block_template function #66102
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @AnmolVerma404! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
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.
Thanks for fixing this, @AnmolVerma404! Code changes looks good and it's testing well. I would only make a change to the testing step code snippet to something like this:
add_action(
'init',
function () {
$template = wp_register_block_template(
'gutenberg//plugin-template',
array(
'title' => 'Plugin Template',
'description' => 'A template registered by a plugin.',
'content' => '<!-- wp:template-part {"slug":"header","tagName":"header"} /--><!-- wp:group {"tagName":"main","layout":{"inherit":true}} --><main class="wp-block-group"><!-- wp:paragraph --><p>This is a plugin-registered template.</p><!-- /wp:paragraph --></main><!-- /wp:group -->',
)
);
print_r( $template );
add_action(
'category_template_hierarchy',
function () {
return array( 'plugin-template' );
}
);
}
);
And then add a step to verify the template object is correctly printed on the screen.
Besides that, LGTM. 🙂
@Aljullu , I've added the changes to the testing code snippet in the PR description ✅ |
Thanks for updating the testing steps, @AnmolVerma404! @kevin940726 I see you added the "Backport to WP 6.7" label, but this specific code only exists in Gutenberg, not in WP core, so my understanding is that no porting is needed, right? Please let me know if I'm missing something. |
Hmm yeah! Sorry for holding this. Any idea why the original PR was backported though? I'll remove the label for now to unblock this. |
No worries, @kevin940726! The original PR was renaming a couple of functions to remove the Given that this PR only modifies the deprecated functions, it only needs to be in Gutenberg and can't be ported to WP core. Hope it makes sense! I will go ahead and merge it for now. |
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.
Looks good, thanks!
…ate function (WordPress#66102) Co-authored-by: AnmolVerma404 <anmolverma404@git.wordpress.org> Co-authored-by: Aljullu <aljullu@git.wordpress.org> Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
What?
Why?
wp_register_block_template
is deprecated, and the legacy code that makes use of the return result might break, as no result is being returned. That's why it is necessary to return the result here.How?
register_block_template
.Testing Instructions
[Reffering example from #65958 PR]
wp_register_block_template
and utilize the return result, it will work as expected.print_r( $template )
statement should be visible on any page of the site. It should return aWP_Block_Template or WP_Error
object.