Opened 7 years ago
Closed 7 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: |
|
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
@
7 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
@
7 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().enableCustomFieldsin 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().enableCustomFieldsagain. It wastruethis time. - Installed, activated, and set up the ACF plugin which I know deregisters the
postcustommeta box. - Created another post.
- Ran
wp.data.select( 'core/editor' ).getEditorSettings().enableCustomFieldsagain. 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_settingsfilter had triggered. Could we move$init_script's declaration inedit-form-blocks.php:335closer to where it is used inedit-form-blocks.php:395? - Instead of setting
$editor_settings['enableCustomFields']inedit-form-blocks.php:300and then later unsetting it inedit-form-blocks.php:382, I think it would be clearer if we conditionally setenableCustomFieldsin 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 inNever mind, didn't see your comment!templates.php:1079do?
#5
@
7 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
@
7 years ago
Thanks for the review, @noisysocks!
- Good catch, done!
- We can't move it, unfortunately.
$wp_meta_boxeswill be altered whenregister_and_do_post_meta_boxes()is run, so we need to check for thepostcustommeta 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
enableCustomFieldssetting 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
@wordpresspackage to hide the option whenenableCustomFieldsis undefined.