-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Template activation: allow empty array to be set #72011
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
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. |
| // To do: figure out why the REST API deletes the option when | ||
| // it's set to an empty object. That would trigger the migration | ||
| // function, which will make all templates in the database active. | ||
| activeTemplates.__preventCollapse = 0; |
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.
This no longer seems needed either. We'll see if the tests pass.
|
Size Change: +127 B (+0.01%) Total Size: 1.96 MB
ℹ️ View Unchanged
|
a2678c9 to
67679c1
Compare
67679c1 to
dbfe960
Compare
| ); | ||
|
|
||
| if ( registeredTemplateWithSlug ) { | ||
| return registeredTemplateWithSlug.id; |
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'm reverting what I did in https://github.com/WordPress/gutenberg/pull/72049/files#diff-166c46de8d08a1bf4740eae54f4a8fa2296684af9f318ec0baa31f248a9c44be, which was wrong. We shouldn't try to resolve a template for this slug. We should check the list of templates we have, and due to the changes we need to check both registered and user templates. In the long term we should really add a way to query the endpoint by slug.
This reverts commit dbfe960.
|
Flaky tests detected in 8cff955. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18312666400
|
| array( | ||
| 'type' => 'object', | ||
| // Do not set the default value to an empty array! For some reason | ||
| // that will prevent the option from being set to an empty 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.
I'm guessing it's like the "block defaults", when the value you want to set equals the default value it's not persisted at all.
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.
Right, I thought it would only affect the return value in case the option didn't exist.
|
Thanks Riad |
mcsf
left a comment
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 feel out my depth on some of the details, like the auto-drafting, etc. But LGTM on the main thing.
| add_action( 'init', 'gutenberg_migrate_existing_templates' ); | ||
| function gutenberg_migrate_existing_templates() { | ||
| $active_templates = get_option( 'active_templates' ); | ||
| $active_templates = get_option( 'active_templates', false ); |
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.
FYI, false is already the default value for that argument.
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.
Yeah, I saw, but I wanted to be explicit so it's clearly relating to the condition below
|
I just cherry-picked this PR to the release/21.8 branch to get it included in the next release: c0131bc |
What?
I ran into this issue while demoing the features to @bph and @justintadlock. I had wiped the template option + trashed all my templates. This allows the migration to kick in, but since I had no templates to migrate, it tried to set the
active_templatesoption to an empty array. This failed, it seems because the default value of the option is an empty array, and this kept the migration function running until I created my first template, which it then activated. Any following templates that I created would not get activated because filling the option would stop the migration function.Why?
See above.
How?
We need
update_optionto work with an empty array. Debugging reveals thatregister_settingwas preventing that, in particular thedefault, probably because it thought the option is already an empty array.Additionally, some e2e tests started breaking because the first template created was automatically activating these tests, creating false positives.
Testing Instructions
Go through the steps above: delete all templates and the
active_templatesoption in the database. Now duplicate one of the theme templates. Check the front-end to make sure that the template was not immediately activated by itself.Testing Instructions for Keyboard
Screenshots or screencast