[wp-trac] [WordPress Trac] #45283: Meta Boxes: Add an action for plugins to print hidden inputs in the meta box form

WordPress Trac noreply at wordpress.org
Mon Nov 12 04:31:43 UTC 2018


#45283: Meta Boxes: Add an action for plugins to print hidden inputs in the meta
box form
---------------------------------+-----------------------
 Reporter:  pento                |       Owner:  pento
     Type:  defect (bug)         |      Status:  assigned
 Priority:  normal               |   Milestone:  5.0
Component:  Editor               |     Version:  5.0
 Severity:  normal               |  Resolution:
 Keywords:  has-patch fixed-5.0  |     Focuses:
---------------------------------+-----------------------

Comment (by elliotcondon):

 Good work adding in support for the `edit_form_after_title` action.

 Can we consider removing the "input only" restrictions here and allow
 plugins (like ACF) to output more than hidden input fields?

 ACF uses this action to render another metabox area ("acf_after_title"), a
 `<style id="acf-style">` element and also a `<div id="acf-form-data>`
 element surrounding the input fields.

 If this restriction is in place to prevent a potential error in 3rd party
 code, may I make an alternative suggestion:

 Instead of calling the `edit_form_after_title` and `edit_form_advanced`
 actions within the `.metabox-base-form` element, consider calling them
 later in a separate **visible** wrapping form element. For example: `<form
 id="classic-actions" class="classic-js">`

 This would require some extra JS to include/serialize in the AJAX request
 which I have a neat solution for too.

 Instead of manually looping over the registered metaboxes and appending
 their data to `formData`, why not use a simple classname to target
 "classic elements" and include them in the serialization. With jQuery,
 this could be done in 1 line of code:
 `var formData = $('form.classic-js').serialize();`

 The beauty of this lies in it's simplicity. Adding this classname to all
 the metaboxes / `#classic-actions` would allow them to be serialized
 together with minimal code.

 The end result is a more seamless transition to the new edit screen
 allowing PHP plugins like ACF and Yoast to continue working fully until we
 move over to blocks completely.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45283#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list