呈现元框表单所需的隐藏表单。
原型
the_block_editor_meta_box_post_form_hidden_fields( WP_Post $post )
参数
$post
(WP_Post)
(Required)
当前的帖子对象。
源文件
路径:wp-admin/includes/post.php
<?php
...
function the_block_editor_meta_box_post_form_hidden_fields( $post ) {
$form_extra = '';
if ( 'auto-draft' === $post->post_status ) {
$form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />";
}
$form_action = 'editpost';
$nonce_action = 'update-post_' . $post->ID;
$form_extra .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr( $post->ID ) . "' />";
$referer = wp_get_referer();
$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 ); ?>" />
<input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr( $form_action ); ?>" />
<input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr( $post->post_type ); ?>" />
<input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr( $post->post_status ); ?>" />
<input type="hidden" id="referredby" name="referredby" value="<?php echo $referer ? esc_url( $referer ) : ''; ?>" />
<?php
if ( 'draft' !== get_post_status( $post ) ) {
wp_original_referer_field( true, 'previous' );
}
echo $form_extra;
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
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 );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/the_block_editor_meta_box_post_form_hidden_fields/