-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Render "normal" metaboxes created by Advanced Custom Fields #2251
Conversation
Lots of unshippable hacks here. See TODO comments.
Can you elaborate on what breaks if we're just rendering by
Two thoughts:
Seems also this might tie into: What needs to happen to meta boxes after a save occurs? Currently plugins will expect a full page reload any time the post is saved. Might be able to recreate this with said metabox endpoint. I believe this was mentioned by @westonruter previously.
Another thing we'll probably want is to prevent rerenders on the |
I haven't seen anything break yet specifically due to that reason, but it seems likely that something will / maybe not the best approach.
Yep, I think this would be best addressed with an endpoint that simulates a
👍 |
How about rather than rendering it inline you render some form of data preview and then when editing the block it would open a modal with the meta box inside of it. |
Codecov Report
@@ Coverage Diff @@
## master #2251 +/- ##
==========================================
- Coverage 26.51% 24.15% -2.37%
==========================================
Files 158 144 -14
Lines 4853 4484 -369
Branches 816 763 -53
==========================================
- Hits 1287 1083 -204
+ Misses 3013 2870 -143
+ Partials 553 531 -22
Continue to review full report at Codecov.
|
In the last couple of commits I've added the beginning of a metaboxes API endpoint. Unfortunately this is impossible to do from within a plugin. Here is the debug log from a sample request to the endpoint:
It shows that:
Potential next steps:
|
I cannot believe you went into this adventure without knowing how to make it work. One decision from the top, and now you have to fix this mess. |
Nobody knows "how to make it work" yet, getting to "knowing more" is the whole point of this experimentation process. Let's let the people that over time have the highest probability of figuring the (massively complex) details out (such as @nylen) do their work in peace. |
I love when you core persons experiment, and seek new ways. I mean it, no joke here. |
@StaggerLeee A pull request is not an appropriate venue for venting your frustrations with the direction or status of the project, and should be reserved for constructive feedback to the proposed implementation. Ideas, requirements, or discussion is better suited for related issues (#952) or weekly editor chats in Core WordPress Slack. |
To use this hit the `wp-admin/post.php?post=ID&action=edit&metabox=some-location`. This will currently render the metaboxes for the base set of meta boxes. Adds and iframe as well to pull these in from endpoint.
2344599
to
03a7414
Compare
^ The latest commit by @BE-Webdesign is a much cleaner and more workable approach to fetching metabox data than either of the two I've tried. We discussed a little bit yesterday and it is basically working for some of the Yoast metaboxes. I would recommend reworking metabox support around it instead. |
I will not have time for the foreseeable future to continue work on this but the last commit essentially adds an "endpoint" of sorts to |
Superseded by #2804. |
This PR is an initial exploration of rendering PHP metaboxes in the Gutenberg editor. See #952.
A fairly basic metabox configuration added by the Advanced Custom Fields plugin looks like this in the wp-admin editor:
This PR renders the HTML for this field group in the Gutenberg editor. It does not attempt to handle saving, JavaScript attached to the field boxes, or any number of other things that can and will go wrong when attempting to implement this feature.
Here's what it looks like currently:
Technical details
As noted in the PHP comments, Advanced Custom Fields adds its metaboxes by registering a hook against
admin_enqueue_scripts
. This hook verifies that the current page load is eitherpost.php
orpost-new.php
, and if so, adds anadmin_head
action which callsadd_meta_box
. WP core does itsdo_meta_boxes
calls shortly after that action, inedit-form-advanced.php
.This PR works by modifying the
$pagenow
variable during the appropriate portion of the Gutenberg page load so that Advanced Custom Fields will register its metaboxes and inject its scripts.This is not even close to an acceptable approach. It is already having a lot of unintended side effects. For example, it doesn't seem to be breaking the Gutenberg editor when using Advanced Custom Fields, but here are the console errors that result from this "unorthodox" loading process:
Also, the way this PR renders the metabox HTML is unacceptable because any malformed markup will probably completely break the React app, and any scripts that expect to manipulate the traditional editor page structure will fail and probably break things along the way.
From the extensive modification of the WP load process needed to get this initial example working, and from the resulting issues, it's clear that we will need to create an API endpoint to render and return metabox HTML. This API endpoint would then be called in a separate request after the Gutenberg editor has loaded, where it can do whatever horrible things it wants to the WP load process.
To avoid concerns about rendering unfiltered HTML inside a React app, we had previously discussed rendering metaboxes in a separate element not managed by React. We can try this next; however, based on the number and type of errors I am already seeing, and the likely difficulties in managing the load-save lifecycle of the metabox content, I'm skeptical that it will work well.