Opened 6 years ago
Closed 6 years ago
#45282 closed defect (bug) (fixed)
Block Editor: Don't show the Custom Fields meta box option if the meta box has been removed
Reported by: | pento | Owned by: | |
---|---|---|---|
Milestone: | 5.0 | Priority: | normal |
Severity: | normal | Version: | 5.0 |
Component: | Editor | Keywords: | has-patch fixed-5.0 |
Focuses: | Cc: |
Description (last modified by )
Some plugins remove the Custom Fields meta box, overriding whether the CPT has set the postcustom
feature.
When this is the case, the block editor Options dialog shouldn't show an option to display the Custom Fields meta box.
Related: GB11386.
Attachments (1)
Change History (14)
#2
@
6 years ago
45282.diff also fixes a bug where any meta box flagged to show in the block editor (eg, __back_compat_meta_box
is set to false
) would be hidden if they were hidden in the classic editor, regardless of their block editor display setting.
#3
@
6 years ago
Nice! I think 45282.diff is the right approach, and it works well in my testing.
To test this, I:
- Created a new post.
- Ran
wp.data.select( 'core/editor' ).getEditorSettings().enableCustomFields
in the console. It wasfalse
. - Ran
document.getElementById( 'toggle-custom-fields-form' ).submit()
in the console to toggle the custom fields setting. - Ran
wp.data.select( 'core/editor' ).getEditorSettings().enableCustomFields
again. It wastrue
this time. - Installed, activated, and set up the ACF plugin which I know deregisters the
postcustom
meta box. - Created another post.
- Ran
wp.data.select( 'core/editor' ).getEditorSettings().enableCustomFields
again. It was nowundefined
.
The code looks good. Some comments:
- It wasn't clear to me at first that
wp.editPost.initializeEditor()
was enqueued after theblock_editor_settings
filter had triggered. Could we move$init_script
's declaration inedit-form-blocks.php:335
closer to where it is used inedit-form-blocks.php:395
? - Instead of setting
$editor_settings['enableCustomFields']
inedit-form-blocks.php:300
and then later unsetting it inedit-form-blocks.php:382
, I think it would be clearer if we conditionally setenableCustomFields
in the one place after the meta box hook triggers. We do this for other editor settings e.g.autosave
,colors
,fontSizes
. - What does the change in
templates.php:1079
do?
#5
@
6 years ago
$hidden_class = ( ! $screen->is_block_editor() && in_array( $box['id'], $hidden ) ) ? ' hide-if-js' : '';
to me it looks like this implicitly solves #45285
#7
@
6 years ago
Thanks for the review, @noisysocks!
- Good catch, done!
- We can't move it, unfortunately.
$wp_meta_boxes
will be altered whenregister_and_do_post_meta_boxes()
is run, so we need to check for thepostcustom
meta box after that. Howeverregister_and_do_post_meta_boxes()
needs to be run as late as possible, to ensure meta boxes have been registered.
45282.diff removes the
enableCustomFields
setting from the editor settings, based on whether the Custom Fields meta box exists or not.It can be tested with this snippet:
This patch requires changes in the relevant
@wordpress
package to hide the option whenenableCustomFields
is undefined.