[wp-trac] [WordPress Trac] #53883: Custom Fields Toggle cannot be turned off
WordPress Trac
noreply at wordpress.org
Thu Aug 5 19:28:50 UTC 2021
#53883: Custom Fields Toggle cannot be turned off
--------------------------+-----------------------------
Reporter: mreishus | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version: 5.8
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
== Scope Note
**This is a coordination problem between WordPress and Gutenberg and
requires changes on both sides.** I have patches for both that I will be
submitting shortly.
== Summary
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.
== Steps to reproduce
1. Have a clean WordPress.org installation
2. Create {{{wp-content/plugins/disable-custom-fields.php}}}
{{{
<?php
/**
* Plugin Name: Disable Custom Fields
* Plugin URI: http://www.mywebsite.com/disable-custom-fields
* Description: Disable Custom Fields
* Version: 1.0
* Author: Your Name
* Author URI: http://www.mywebsite.com
*/
add_action( 'add_meta_boxes', 'plugin_disable_custom_fields', 1 );
function plugin_disable_custom_fields() {
remove_post_type_support( get_post_type(), 'custom-fields' );
}
add_action( 'do_meta_boxes', 'plugin_meta_boxes', 10, 2 );
function plugin_meta_boxes( $page, $context ) {
remove_meta_box( 'postcustom', get_post_type(), 'normal' );
}
}}}
3. Visit /wp-admin and activate this plugin.
4. Visit post editor on WordPress.org site. With this plugin enabled,
[https://github.com/WordPress/WordPress/blob/9a4280c75f7bf76062b61207e3ecdb3a0e0f298e
/wp-admin/edit-form-blocks.php#L260 this if condition] will always
trigger, and the
[https://github.com/WordPress/WordPress/blob/9a4280c75f7bf76062b61207e3ecdb3a0e0f298e
/wp-admin/edit-form-blocks.php#L261 unset(
$editor_settings['enableCustomFields'] );] always runs.
5. Click the three dots menu in the top right.
6. Click "preferences" at the bottom. Screenshot: [[Image( https://user-
images.githubusercontent.com/937354/128374126-c22ad772-d02f-4df4-9c4b-
bb9be3748a71.png )]]
7. A modal appears. Click panels on the left.
8. Turn on "Custom Fields". Screenshot: [[Image( https://user-
images.githubusercontent.com/937354/128374210-5d7311eb-6073-4ffa-
8fd5-6754ac3c5aa3.png )]]
9. See message asking to enable and reload, click the button. Screenshot:
[[Image( https://user-images.githubusercontent.com/937354/128374223
-df55a53c-b4ae-4261-b664-b256ee202d28.png )]]
10. Page reloads
11. Re-visit the custom fields setting, see that it is turned off.
Expected to see: The entire "Custom Settings" option does not appear,
because {{{$editor_settings['enableCustomFields']}}} is unset by this core
code.
== Coordination between WordPress and Gutenberg
* Gutenberg hides the option, but only if {{{enableCustomFields}}} is set
to {{{undefined}}} in JavaScript.
[https://github.com/WordPress/gutenberg/blob/333668e7149a1f3f2a39810372ecb11422fe4f7c/packages
/edit-post/src/components/preferences-modal/meta-boxes-section.js#L57-L58
Code link 1],
[https://github.com/WordPress/gutenberg/blob/333668e7149a1f3f2a39810372ecb11422fe4f7c/packages
/edit-post/src/components/preferences-modal/meta-boxes-section.js#L31-L32
Code link 2].
* PHP cannot set {{{$editor_settings['enableCustomFields']}}} equal to
{{{undefined}}}, because {{{undefined}}} is not a value in PHP. It can set
to {{{true}}}, {{{false}}}, {{{null}}}, or decline to set the value at
all, but none of these options work.
* **{{{true}}}, {{{false}}}, {{{null}}}** - All fail because they are
not {{{=== undefined}}} in javascript.
* **Using {{{unset()}}} to not send the value at all** - This is what
the code currently does. It fails because when gutenberg sees no value is
sent, it
[https://github.com/WordPress/gutenberg/blob/333668e7149a1f3f2a39810372ecb11422fe4f7c/packages/editor/src/store/defaults.js#L30
uses its default settings system to set it to false], which is also not
{{{=== undefined}}}.
* Therefore, Gutenberg wants {{{$editor_settings['enableCustomFields'] ===
undefined}}} in order to hide the toggle, but that value is impossible to
send.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53883>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list