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

Rename wp_register_block_template() to register_block_template() #65958

Conversation

Aljullu
Copy link
Contributor

@Aljullu Aljullu commented Oct 8, 2024

What?

As discussed in #61577, we want to remove the wp_ prefix from wp_register_block_template() and wp_unregister_block_template().

Backport PR in core: WordPress/wordpress-develop#7543.

Why?

To keep it consistent with other functions like register_block_type, register_block_pattern and register_block_style.

How?

This PR directly replaces the old functions with the new ones, it doesn't deprecate them. Given that they were not shipped in WordPress core my understanding is that we don't need to keep backwards compatibility. But please, correct me if I'm wrong.

Testing Instructions

  1. Add this code to an existing plugin or in a code snippet using the Code Snippets plugin:
add_action(
	'init',
	function () {
		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 -->',
			)
		);
		add_action(
			'category_template_hierarchy',
			function () {
				return array( 'plugin-template' );
			}
		);
	}
);
  1. Go to a post category in the frontend (ie: /category/test-category/) and verify the Plugin Template contents are rendered.
  2. Go to Appearance > Editor > Templates and verify the Plugin Template appears with the correct title and description.
  3. Make some edits to the template. Verify they are applied in the frontend.
  4. Revert the edits and verify edits are reverted in the frontend as well.
  5. Edit the previous code snippet adding these lines:
		unregister_block_template( 'gutenberg//plugin-template' );
  1. Verify the template no longer appears under Appearance > Editor > Templates and going to a post category in the frontend doesn't render it either.

@Aljullu Aljullu added the [Feature] Extensibility The ability to extend blocks or the editing experience label Oct 8, 2024
@Aljullu Aljullu self-assigned this Oct 8, 2024
Copy link

github-actions bot commented Oct 8, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Aljullu <aljullu@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: ndiego <ndiego@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

github-actions bot commented Oct 8, 2024

Flaky tests detected in f942c09.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11244989720
📝 Reported issues:

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@youknowriad
Copy link
Contributor

Any concerns @peterwilsoncc @ndiego

@youknowriad youknowriad added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Oct 9, 2024
@ndiego
Copy link
Member

ndiego commented Oct 9, 2024

Any concerns @peterwilsoncc @ndiego

Not on my end, as I would consider this fixing a "bug" in the original implementation, but I have alerted the other 6.7 release leads in WP Slack and will follow up when there is a consensus.

@getdave
Copy link
Contributor

getdave commented Oct 9, 2024

I'd consider this fixing a bug 👍

@getdave getdave added the [Type] Bug An existing feature does not function as intended label Oct 9, 2024
@ndiego
Copy link
Member

ndiego commented Oct 9, 2024

I'd consider this fixing a bug 👍

Given the 👍 on this comment above. I have no concerns moving forward.

As an aside, this change will be highlighted in the What's new for developers article later this week on the Developer Blog.

@getdave
Copy link
Contributor

getdave commented Oct 9, 2024

According to the docs we will also need to raise a Core PR to manually back port these changes to WP Core. cc @kevin940726 for confidence check.

@getdave getdave added the Needs PHP backport Needs PHP backport to Core label Oct 9, 2024
@Aljullu
Copy link
Contributor Author

Aljullu commented Oct 9, 2024

According to the docs we will also need to raise a Core PR to manually back port these changes to WP Core. cc @kevin940726 for confidence check.

The WP core backport PR is this one: WordPress/wordpress-develop#7543. Sorry I forgot to add the link in the PR description. 😅

@youknowriad youknowriad merged commit fc62bf6 into trunk Oct 9, 2024
75 of 76 checks passed
@youknowriad youknowriad deleted the update/wp_register_block_template-to-register_block_template branch October 9, 2024 17:44
@github-actions github-actions bot added this to the Gutenberg 19.5 milestone Oct 9, 2024
@github-actions github-actions bot removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Oct 9, 2024
gutenbergplugin pushed a commit that referenced this pull request Oct 9, 2024
)

Co-authored-by: Aljullu <aljullu@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: ndiego <ndiego@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>
@github-actions github-actions bot added the Backported to WP Core Pull request that has been successfully merged into WP Core label Oct 9, 2024
Copy link

github-actions bot commented Oct 9, 2024

I just cherry-picked this PR to the wp/6.7 branch to get it included in the next release: ffb2e13

@ndiego ndiego mentioned this pull request Oct 10, 2024
karthick-murugan pushed a commit to karthick-murugan/gutenberg that referenced this pull request Nov 13, 2024
…dPress#65958)

Co-authored-by: Aljullu <aljullu@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: ndiego <ndiego@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported to WP Core Pull request that has been successfully merged into WP Core [Feature] Extensibility The ability to extend blocks or the editing experience Needs PHP backport Needs PHP backport to Core [Type] Bug An existing feature does not function as intended
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants