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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced Panels: Add support for the 'Custom Fields' meta box #11084

Merged
merged 9 commits into from Nov 2, 2018

Conversation

@noisysocks
Member

noisysocks commented Oct 26, 2018

Closes #3228.

custom-fields

Adds an option which allows the user to enable the existing 'postcustom' meta box included in WordPress.

I've implemented this using the super hacky approach described in #10676 (comment) 馃槑

The benefits of this approach are that:

  • We can reuse the existing 'postcustom' meta box.
  • The 'postcustom' assets aren't loaded unless the option is enabled.

The downsides are that:

  • We have to store the option on the server (e.g. using a site option).
  • The editor has to be reloaded when the option changes, which is pretty jarring.
@youknowriad

This makes sense unless we have REST API support for custom fields which I don't really expect it to come in 5.0 (or later?)

I'm adding some reviewers more familiar with the PHP side of things.

@youknowriad youknowriad requested review from aduth, danielbachhuber and pento Oct 26, 2018

@danielbachhuber

Looking good! Few things to address.

Show resolved Hide resolved lib/meta-box-partial-page.php Outdated
Show resolved Hide resolved lib/meta-box-partial-page.php Outdated
Show resolved Hide resolved ...s/edit-post/src/components/options-modal/options/enable-custom-fields.js Outdated
@@ -1573,14 +1573,27 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
'maxUploadFileSize' => $max_upload_size,

This comment has been minimized.

@danielbachhuber

danielbachhuber Oct 26, 2018

Member

It works!

image

Should I be seeing that error message though?

This comment has been minimized.

@youknowriad

youknowriad Oct 26, 2018

Contributor

I saw the error mentioned for other meta boxes elsewhere. I wonder if it's a more generic bug in 5.0?

This comment has been minimized.

@noisysocks

noisysocks Oct 29, 2018

Member

How did you get this error?

This comment has been minimized.

@pento

pento Oct 29, 2018

Member

It's a bug in 5.0, fixed now.

Show resolved Hide resolved lib/meta-box-partial-page.php
@noisysocks

This comment has been minimized.

Member

noisysocks commented Oct 29, 2018

Noting to myself that since this touches the PHP we'll need to bring over these changes to the 5.0 branch.

Feedback has been addressed 馃檪

@noisysocks noisysocks requested a review from talldan Oct 31, 2018

@noisysocks

This comment has been minimized.

Member

noisysocks commented Oct 31, 2018

How do we feel about this? Would like to get it into the 5.0 RC.

@talldan

I had a look at the front-end side of things. The changes seem to be pretty minor there. Looks good to me - seems mergeable if the backend changes also look acceptable.

@websupporter

This comment has been minimized.

websupporter commented Nov 1, 2018

How does this approach take into account a custom post type where custom-fields are not supported, like for example

add_action('init', function() {
        remove_post_type_support( 'post', 'custom-fields' );
});

I would expect the option to not show up in the first place, but from a quick view into the code, I can't see a toggle for that.

In the classic editor, when I go to the screen options, the "Custom Fields"-option disappears when the support has been removed.

noisysocks added some commits Oct 26, 2018

Advanced Panels: Add support for the 'Custom Fields' meta box
- Adds an option which allows the user to enable the existing
  'postcustom' meta box included in WordPress.
- Don't load the 'postcustom' assets when the option is disabled.
- Stores the option as a site option.
- Reload the editor when the option is changed.
Fix E2E tests
The 'Enable Tips' checkbox is obscured by the first Tip now that the
Options modal is taller. Work around this by only testing that tips can
be re-enabled.
Custom Fields: Remove unnecessary jQuery selector
We can simply interpolate $post->ID when initializing Custom Fields,
rather than selecting from the #post_ID hidden field.
Custom Fields: Use user meta field instead of site option
By using `get_user_meta()` instead of `get_option()`, the Custom Fields
setting won't affect other users.
Custom Fields: Use hidden <form> instead of redirect
Trigger the toggle_custom_fields action using a hidden <form> so that
the action is triggered by a POST request rather than a GET request.

@noisysocks noisysocks force-pushed the try/custom-fields-meta-box branch 2 times, most recently from 292485a to c01629c Nov 2, 2018

@noisysocks noisysocks force-pushed the try/custom-fields-meta-box branch from c01629c to 6368b56 Nov 2, 2018

@noisysocks

This comment has been minimized.

Member

noisysocks commented Nov 2, 2018

Thanks all. I've responded to feedback and fixed the problem where Custom Fields would display in post types that don't support postcustom.

One issue I've noticed: when the Advanced Custom Fields plugin is enabled, the Custom Fields toggle is displayed even though it doesn't do anything. This is because the ACF plugin removes postcustom from the list of registered meta boxes. I don't think it's a blocker for this PR. Likely the fix is that ACF, when enabled, will have to mark the post type as not supporting custom-fields.

@noisysocks noisysocks added this to the 4.3 milestone Nov 2, 2018

@talldan

talldan approved these changes Nov 2, 2018

Yep, it's undergone a lot of reviews and feedback looks all addressed 馃憤

@noisysocks

This comment has been minimized.

Member

noisysocks commented Nov 2, 2018

馃檲

@noisysocks noisysocks merged commit e30f36f into master Nov 2, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@noisysocks noisysocks deleted the try/custom-fields-meta-box branch Nov 2, 2018

@noisysocks

This comment has been minimized.

Member

noisysocks commented Nov 2, 2018

One issue I've noticed: when the Advanced Custom Fields plugin is enabled, the Custom Fields toggle is displayed even though it doesn't do anything. This is because the ACF plugin removes postcustom from the list of registered meta boxes. I don't think it's a blocker for this PR. Likely the fix is that ACF, when enabled, will have to mark the post type as not supporting custom-fields.

Created a follow-up issue for this here: #11386

@noisysocks

This comment has been minimized.

Member

noisysocks commented Nov 2, 2018

Lastly, created a ticket to remind ourselves to copy over the necessary PHP changes to Core: https://core.trac.wordpress.org/ticket/45257

antpb added a commit to antpb/gutenberg that referenced this pull request Nov 5, 2018

Advanced Panels: Add support for the 'Custom Fields' meta box (WordPr鈥
鈥ss#11084)

* Advanced Panels: Add support for the 'Custom Fields' meta box

- Adds an option which allows the user to enable the existing
  'postcustom' meta box included in WordPress.
- Don't load the 'postcustom' assets when the option is disabled.
- Stores the option as a site option.
- Reload the editor when the option is changed.

* Fix E2E tests

The 'Enable Tips' checkbox is obscured by the first Tip now that the
Options modal is taller. Work around this by only testing that tips can
be re-enabled.

* Custom Fields: Remove unnecessary jQuery selector

We can simply interpolate $post->ID when initializing Custom Fields,
rather than selecting from the #post_ID hidden field.

* Custom Fields: Use user meta field instead of site option

By using `get_user_meta()` instead of `get_option()`, the Custom Fields
setting won't affect other users.

* Custom Fields: Kill the process after redirecting

* Custom Fields: Use hidden <form> instead of redirect

Trigger the toggle_custom_fields action using a hidden <form> so that
the action is triggered by a POST request rather than a GET request.

* Custom Fields: Move meta box options into their own component

* Custom Fields: Rename isEnabled 鈫 isChecked

* Custom Fields: Only show option if custom fields are supported

@andergmartins andergmartins referenced this pull request Nov 13, 2018

Open

Add support for Gutenberg #296

1 of 2 tasks complete

grey-rsi pushed a commit to OnTheGoSystems/gutenberg that referenced this pull request Nov 22, 2018

Advanced Panels: Add support for the 'Custom Fields' meta box (WordPr鈥
鈥ss#11084)

* Advanced Panels: Add support for the 'Custom Fields' meta box

- Adds an option which allows the user to enable the existing
  'postcustom' meta box included in WordPress.
- Don't load the 'postcustom' assets when the option is disabled.
- Stores the option as a site option.
- Reload the editor when the option is changed.

* Fix E2E tests

The 'Enable Tips' checkbox is obscured by the first Tip now that the
Options modal is taller. Work around this by only testing that tips can
be re-enabled.

* Custom Fields: Remove unnecessary jQuery selector

We can simply interpolate $post->ID when initializing Custom Fields,
rather than selecting from the #post_ID hidden field.

* Custom Fields: Use user meta field instead of site option

By using `get_user_meta()` instead of `get_option()`, the Custom Fields
setting won't affect other users.

* Custom Fields: Kill the process after redirecting

* Custom Fields: Use hidden <form> instead of redirect

Trigger the toggle_custom_fields action using a hidden <form> so that
the action is triggered by a POST request rather than a GET request.

* Custom Fields: Move meta box options into their own component

* Custom Fields: Rename isEnabled 鈫 isChecked

* Custom Fields: Only show option if custom fields are supported
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment