From cd22d51724755be2d6ad32854ffb260a604ec959 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Fri, 9 Nov 2018 09:06:47 +0000 Subject: [PATCH] Meta Boxes: Add the `block_editor_meta_box_hidden_fields` action. Lacking an appropriate action in the classic editor, plugins that add meta boxes have historically hooked into various actions in order to add hidden input fields. This change also adds backwards compatibility for two of the most common: `edit_form_after_title`, and `edit_form_advanced`. Props pento, danielbachhuber. See #45283. Built from https://develop.svn.wordpress.org/branches/5.0@43882 git-svn-id: http://core.svn.wordpress.org/branches/5.0@43711 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-form-blocks.php | 4 --- wp-admin/includes/post.php | 49 +++++++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/wp-admin/edit-form-blocks.php b/wp-admin/edit-form-blocks.php index 9336c02a36..12608526b9 100644 --- a/wp-admin/edit-form-blocks.php +++ b/wp-admin/edit-form-blocks.php @@ -386,10 +386,6 @@ do_action( 'enqueue_block_editor_assets' ); require_once( ABSPATH . 'wp-admin/includes/meta-boxes.php' ); register_and_do_post_meta_boxes( $post ); -// Some meta boxes hook into the 'edit_form_advanced' filter. -/** This action is documented in wp-admin/edit-form-advanced.php */ -do_action( 'edit_form_advanced', $post ); - require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?> diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index a834c1414d..1ed925fa6a 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -2185,6 +2185,43 @@ function the_block_editor_meta_box_post_form_hidden_fields( $post ) { $current_user = wp_get_current_user(); $user_id = $current_user->ID; wp_nonce_field( $nonce_action ); + + /* + * Some meta boxes hook into these actions to add hidden input fields in the classic post form. For backwards + * compatibility, we can capture the output from these actions, and extract the hidden input fields. + */ + $actions = array( + 'edit_form_after_title', + 'edit_form_advanced', + ); + + foreach ( $actions as $action ) { + ob_start(); + do_action_deprecated( + $action, + array( $post ), + '5.0.0', + 'block_editor_meta_box_hidden_fields', + __( 'This action is still supported in the classic editor, but is deprecated in the block editor.' ) + ); + $classic_output = ob_get_clean(); + + if ( ! $classic_output ) { + continue; + } + + $classic_elements = wp_html_split( $classic_output ); + $hidden_inputs = ''; + foreach( $classic_elements as $element ) { + if ( 0 !== strpos( $element, ' @@ -2202,4 +2239,16 @@ function the_block_editor_meta_box_post_form_hidden_fields( $post ) { wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); // Permalink title nonce. wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); + + /** + * Add hidden input fields to the meta box save form. + * + * Hook into this action to print `` fields, which will be POSTed back to + * the server when meta boxes are saved. + * + * @since 5.0.0 + * + * @params WP_Post $post The post that is being edited. + */ + do_action( 'block_editor_meta_box_hidden_fields', $post ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index d6e4abe3da..6d31f0d1a7 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '5.0-beta3-43881'; +$wp_version = '5.0-beta3-43882'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.