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. Merges [43882] to trunk. Fixes #45283. git-svn-id: https://develop.svn.wordpress.org/trunk@44241 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
7f326f92a5
commit
8002325c92
@ -358,10 +358,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' );
|
||||
?>
|
||||
|
||||
|
@ -2307,6 +2307,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, '<input ') ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( preg_match( '/\stype=[\'"]hidden[\'"]\s/', $element ) ) {
|
||||
echo $element;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_id; ?>" />
|
||||
<input type="hidden" id="hiddenaction" name="action" value="<?php echo esc_attr( $form_action ); ?>" />
|
||||
@ -2324,4 +2361,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 `<input type="hidden" ... />` 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 );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user