Skip to content

Conversation

@ellatrix
Copy link
Member

What?

Closes https://core.trac.wordpress.org/ticket/62755#comment:11

  • It's possible that get_queried_object does not return a post. We should double check that it's a post before getting the slug. This doesn't actually fix anything, but it would be good practice.
  • When adding the template from the queried post, make sure it's actually in the array of requested slugs. If it's not, the sorting will log a warning.

Why?

Avoid PHP warnings.

How?

Testing Instructions

Testing Instructions for Keyboard

Screenshots or screencast

Before After

@ellatrix ellatrix added Backport to WP 6.9 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta [Type] Bug An existing feature does not function as intended labels Oct 27, 2025
@ellatrix ellatrix force-pushed the fix/template-activation-undefined-array-key branch from d27e2f5 to e39f21d Compare October 27, 2025 20:30
@github-actions
Copy link

github-actions bot commented Oct 27, 2025

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: ellatrix <[email protected]>
Co-authored-by: Mamaduka <[email protected]>

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

@github-actions
Copy link

github-actions bot commented Oct 27, 2025

Flaky tests detected in 9c900ee.
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/18902483125
📝 Reported issues:

$object = get_queried_object();
$specific_template = $object ? get_page_template_slug( $object ) : null;
$object_id = get_queried_object_id();
$specific_template = $object_id && get_post( $object_id ) ? get_page_template_slug( $object_id ) : null;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$specific_template = $object_id && get_post( $object_id ) ? get_page_template_slug( $object_id ) : null;
$specific_template = $object_id ? get_page_template_slug( $object_id ) : null;

The get_page_template_slug also performs a get_post check and bails early. See: https://developer.wordpress.org/reference/functions/get_page_template_slug/

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh nice. Perhaps safer to pass an ID instead of a whole queried object though?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. ID is probably safer in this case

pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Oct 28, 2025
Developed in #10425.
See https://core.trac.wordpress.org/ticket/62755.

* Rename new endpoints, WordPress/gutenberg#72700.
* Remove fake post type for registered templates, WordPress/gutenberg#72674.
* Remove the ability to deactivate registered templates, WordPress/gutenberg#72636,
* Fix undefined array key PHP warning, WordPress/gutenberg#72729.
* Add migration logic (to be refined), see https://core.trac.wordpress.org/ticket/64133 and #10418.

Fixes #62755.
Props ellatrix, priethor.

git-svn-id: https://develop.svn.wordpress.org/trunk@61078 602fd350-edb4-49c9-b593-d223f7449a82
@ellatrix ellatrix force-pushed the fix/template-activation-undefined-array-key branch from e39f21d to 9c900ee Compare October 29, 2025 09:02
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Thanks, @ellatrix!

@ellatrix ellatrix merged commit 10260b9 into trunk Oct 29, 2025
35 checks passed
@ellatrix ellatrix deleted the fix/template-activation-undefined-array-key branch October 29, 2025 13:25
@github-actions github-actions bot added this to the Gutenberg 22.0 milestone Oct 29, 2025
@github-actions github-actions bot removed the Backport to WP 6.9 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Oct 29, 2025
gutenbergplugin pushed a commit that referenced this pull request Oct 29, 2025
@github-actions github-actions bot added the Backported to WP Core Pull request that has been successfully merged into WP Core label Oct 29, 2025
@github-actions
Copy link

I just cherry-picked this PR to the wp/6.9 branch to get it included in the next release: 0bf76a7

@bph bph added the [Feature] Templates API Related to API powering block template functionality in the Site Editor label Oct 30, 2025
ellatrix added a commit that referenced this pull request Nov 5, 2025
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] Templates API Related to API powering block template functionality in the Site Editor [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants