-
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
Allow custom fields to be hidden when enableCustomFields is null #33912
Conversation
Thanks so much @mreishus for the outstanding bug report, PR, and description of the issue! I tested this PR (along with making the change in core, and the provided plugin), and it works as described. I looked into this a little bit, and I’m wondering if instead of changing what core passes, if it would be possible to change the default to @youknowriad do you remember any context on why the default for On a related note, I noticed that if the last item in the “Additional” section is removed, it leaves the header with no options, so that might some something to look into as well (maybe in a separate PR?): |
I created a PR using that approach here: #33931 If we go with that method, let me know so I can cancel my WP.org changes. Changing the default to undefined won't help if WP.org starts sending a null. :) |
152d7cf
to
890b984
Compare
I don't remember much tbh, I think that PR was just a refactoring PR separating the "editor" package from the "block-editor" one. That said, packages like "block-editor" and "editor" can be seen as WP independent meaning the default value in the JS store could be different from the one that is provided by WP's backend and that's fine. |
@youknowriad Thanks for the context re: the PR! I'm sorry, I don't think I completely understand what you mean on the suggestion. Do you mean you think it's fine to move to |
I was just saying that it's fine if the default value for the block-editor package (default.js file) is different from the default that is sent from the backend when calling For the fix about this particular issue, I honestly don't know what's best. Looking at the check, I do wonder why |
#33931 looks like the right fix to me. We could perhaps make this clearer by replacing |
890b984
to
1d0dabb
Compare
Closing this one since we went with the alternate approach: #33931 |
Allow custom fields to be hidden when enableCustomFields is null
Scope of Problem
This is a coordination problem between WordPress and Gutenberg and requires changes on both sides. I have patches for both.
Problem
When using a plugin to disable Custom Fields in the post editor, WordPress attempts to change
$editor_settings
to tell Gutenberg not to render the Custom Fields settings toggle in a preferences modal. However, Gutenberg is listening for a value that is impossible to send in PHP, and the settings toggle remains visible even when the feature itself is disabled.This change tells Gutenberg to listen for an additional value to turn off the setting (
null
). It must be applied in conjunction with a WordPress change to send that value (Currently, it usesunset()
to not send a value, which mean Gutenberg's state defaults apply).Alternative Approach
Here is a different approach for the same problem: #33931 This changes the default value to
undefined
, which allows WP.org's currentunset()
to work without any changes needed on that side.Steps to Reproduce
Have a WordPress.org installation.
Create
wp-content/plugins/disable-custom-fields.php
unset( $editor_settings['enableCustomFields'] );
always runs.Expected to see: The entire "Custom Settings" option does not appear, because
$editor_settings['enableCustomFields']
is unset by this core code.Actually see: A toggle that does nothing after turning it on, because a plugin is disabling the option from working.
The "Custom Fields" settings is designed to be hidden by an editor setting set in WP.org core PHP code, however it cannot be hidden, due to these factors:
Therefore, to hide the "Custom Fields" setting, it wants an undefined to be sent in
getEditorSettings().enableCustomFields
, but it is impossible to send one.Description
How has this been tested?
cp wp-includes/js/dist/edit-post.js wp-includes/js/dist/edit-post.min.js
wp-includes/js/dist/edit-post.min.js
wp-admin/edit-form-blocks.php
.Screenshots
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).