-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Editor Settings: Avoid losing original template keys #1561
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
Editor Settings: Avoid losing original template keys #1561
Conversation
/cc @gziolo |
I don't know this functionalit. @youknowriad, can you help with the review? |
@gziolo apologies. I pinged you since this was editor settings related. |
src/wp-admin/edit-form-blocks.php
Outdated
'' => apply_filters( 'default_page_template_title', __( 'Default template' ), 'rest-api' ), | ||
), | ||
$available_templates | ||
) |
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.
It seems the difference could be that array_merge includes the default template even if not already available in $available_templates
. Do we expect it to be always available?
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.
The array_replace
function also does that. Updated REPL example - https://3v4l.org/sgsQg.
I think I need to swap argument positions so the "Default template" is always the first item in the array.
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.
Ok weird, that replace does that as well.
Now I'm curious what the expected result if ""
key is present from the available_templates
array? Do we expect to just add it if missing or do we expect to replace its label as well? (which would make the position change)
Personally, I'm not familiar with this code to guess the original intent.
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 don't think wp_get_theme()->get_page_templates( get_post( $post->ID ) );
will ever return template with ""
as a key.
My best guess about the "Default template" option is that it represents the state when a template isn't set for page/post, and it defaults to whatever WP resolves in the template hierarchy.
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 to me
Thanks for the review, @youknowriad.
I will push this change in few minutes. |
Thanks for the PR! Merged in https://core.trac.wordpress.org/changeset/51595. |
Changes
array_merge
witharray_replace
. The latter will keep the same numeric keys.Verification example: https://3v4l.org/tlft6
Trac ticket: https://core.trac.wordpress.org/ticket/53898
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.