Block Editor: Fix meta boxes not showing.
The block editor needs to duplicate the classic meta box behaviour, so it can extract the registered meta boxes, and import them into the block editor. To match the classic editor behaviour as closely as possible, this moves the relevant code from the classic editor, into a new function, so it can be called by both. Merges [43837] from the 5.0 branch to trunk. Props pento, peterwilsoncc. Fixes #45172. Built from https://develop.svn.wordpress.org/trunk@44214 git-svn-id: http://core.svn.wordpress.org/trunk@44044 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
614df6b5cc
commit
ff7b1bfe48
|
@ -243,167 +243,7 @@ $post_type_object = get_post_type_object( $post_type );
|
|||
// All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action).
|
||||
require_once( ABSPATH . 'wp-admin/includes/meta-boxes.php' );
|
||||
|
||||
|
||||
$publish_callback_args = array( '__back_compat_meta_box' => true );
|
||||
if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' != $post->post_status ) {
|
||||
$revisions = wp_get_post_revisions( $post_ID );
|
||||
|
||||
// We should aim to show the revisions meta box only when there are revisions.
|
||||
if ( count( $revisions ) > 1 ) {
|
||||
reset( $revisions ); // Reset pointer for key()
|
||||
$publish_callback_args = array(
|
||||
'revisions_count' => count( $revisions ),
|
||||
'revision_id' => key( $revisions ),
|
||||
'__back_compat_meta_box' => true,
|
||||
);
|
||||
add_meta_box( 'revisionsdiv', __( 'Revisions' ), 'post_revisions_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'attachment' == $post_type ) {
|
||||
wp_enqueue_script( 'image-edit' );
|
||||
wp_enqueue_style( 'imgareaselect' );
|
||||
add_meta_box( 'submitdiv', __( 'Save' ), 'attachment_submit_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
add_action( 'edit_form_after_title', 'edit_form_image_editor' );
|
||||
|
||||
if ( wp_attachment_is( 'audio', $post ) ) {
|
||||
add_meta_box( 'attachment-id3', __( 'Metadata' ), 'attachment_id3_data_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
} else {
|
||||
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core', $publish_callback_args );
|
||||
}
|
||||
|
||||
if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) ) {
|
||||
add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
// all taxonomies
|
||||
foreach ( get_object_taxonomies( $post ) as $tax_name ) {
|
||||
$taxonomy = get_taxonomy( $tax_name );
|
||||
if ( ! $taxonomy->show_ui || false === $taxonomy->meta_box_cb ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$label = $taxonomy->labels->name;
|
||||
|
||||
if ( ! is_taxonomy_hierarchical( $tax_name ) ) {
|
||||
$tax_meta_box_id = 'tagsdiv-' . $tax_name;
|
||||
} else {
|
||||
$tax_meta_box_id = $tax_name . 'div';
|
||||
}
|
||||
|
||||
add_meta_box(
|
||||
$tax_meta_box_id,
|
||||
$label,
|
||||
$taxonomy->meta_box_cb,
|
||||
null,
|
||||
'side',
|
||||
'core',
|
||||
array(
|
||||
'taxonomy' => $tax_name,
|
||||
'__back_compat_meta_box' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( post_type_supports( $post_type, 'page-attributes' ) || count( get_page_templates( $post ) ) > 0 ) {
|
||||
add_meta_box( 'pageparentdiv', $post_type_object->labels->attributes, 'page_attributes_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
if ( $thumbnail_support && current_user_can( 'upload_files' ) ) {
|
||||
add_meta_box( 'postimagediv', esc_html( $post_type_object->labels->featured_image ), 'post_thumbnail_meta_box', null, 'side', 'low', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
if ( post_type_supports( $post_type, 'excerpt' ) ) {
|
||||
add_meta_box( 'postexcerpt', __( 'Excerpt' ), 'post_excerpt_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
if ( post_type_supports( $post_type, 'trackbacks' ) ) {
|
||||
add_meta_box( 'trackbacksdiv', __( 'Send Trackbacks' ), 'post_trackback_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
if ( post_type_supports( $post_type, 'custom-fields' ) ) {
|
||||
add_meta_box( 'postcustom', __( 'Custom Fields' ), 'post_custom_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires in the middle of built-in meta box registration.
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @deprecated 3.7.0 Use 'add_meta_boxes' instead.
|
||||
*
|
||||
* @param WP_Post $post Post object.
|
||||
*/
|
||||
do_action( 'dbx_post_advanced', $post );
|
||||
|
||||
// Allow the Discussion meta box to show up if the post type supports comments,
|
||||
// or if comments or pings are open.
|
||||
if ( comments_open( $post ) || pings_open( $post ) || post_type_supports( $post_type, 'comments' ) ) {
|
||||
add_meta_box( 'commentstatusdiv', __( 'Discussion' ), 'post_comment_status_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
$stati = get_post_stati( array( 'public' => true ) );
|
||||
if ( empty( $stati ) ) {
|
||||
$stati = array( 'publish' );
|
||||
}
|
||||
$stati[] = 'private';
|
||||
|
||||
if ( in_array( get_post_status( $post ), $stati ) ) {
|
||||
// If the post type support comments, or the post has comments, allow the
|
||||
// Comments meta box.
|
||||
if ( comments_open( $post ) || pings_open( $post ) || $post->comment_count > 0 || post_type_supports( $post_type, 'comments' ) ) {
|
||||
add_meta_box( 'commentsdiv', __( 'Comments' ), 'post_comment_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) ) {
|
||||
add_meta_box( 'slugdiv', __( 'Slug' ), 'post_slug_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
if ( post_type_supports( $post_type, 'author' ) && current_user_can( $post_type_object->cap->edit_others_posts ) ) {
|
||||
add_meta_box( 'authordiv', __( 'Author' ), 'post_author_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires after all built-in meta boxes have been added.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $post_type Post type for posts, 'comment' for comments,
|
||||
* 'link' for links.
|
||||
* @param WP_Post|WP_Comment|object $post Post, comment, or link object.
|
||||
*/
|
||||
do_action( 'add_meta_boxes', $post_type, $post );
|
||||
|
||||
/**
|
||||
* Fires after all built-in meta boxes have been added, contextually for the given post type.
|
||||
*
|
||||
* The dynamic portion of the hook, `$post_type`, refers to the post type of the post.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param WP_Post $post Post object.
|
||||
*/
|
||||
do_action( "add_meta_boxes_{$post_type}", $post );
|
||||
|
||||
/**
|
||||
* Fires after meta boxes have been added.
|
||||
*
|
||||
* Fires once for each of the default meta box contexts: normal, advanced, and side.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $post_type Post type for posts, 'dashboard' for dashboard widgets,
|
||||
* 'link' for links.
|
||||
* @param string $context Meta box context. Accepts 'normal', 'advanced', 'side'.
|
||||
* @param WP_Post|string|object $post Post object for posts, empty string for dashboard widgets,
|
||||
* link object for links.
|
||||
*/
|
||||
do_action( 'do_meta_boxes', $post_type, 'normal', $post );
|
||||
/** This action is documented in wp-admin/edit-form-advanced.php */
|
||||
do_action( 'do_meta_boxes', $post_type, 'advanced', $post );
|
||||
/** This action is documented in wp-admin/edit-form-advanced.php */
|
||||
do_action( 'do_meta_boxes', $post_type, 'side', $post );
|
||||
register_and_do_post_meta_boxes( $post );
|
||||
|
||||
add_screen_option(
|
||||
'layout_columns',
|
||||
|
|
|
@ -363,6 +363,14 @@ wp_enqueue_style( 'wp-format-library' );
|
|||
*/
|
||||
do_action( 'enqueue_block_editor_assets' );
|
||||
|
||||
// In order to duplicate classic meta box behaviour, we need to run the classic meta box actions.
|
||||
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' );
|
||||
?>
|
||||
|
||||
|
|
|
@ -195,7 +195,7 @@ endif;
|
|||
|
||||
<div id="postbox-container-2" class="postbox-container">
|
||||
<?php
|
||||
/** This action is documented in wp-admin/edit-form-advanced.php */
|
||||
/** This action is documented in wp-admin/includes/meta-boxes.php */
|
||||
do_action( 'add_meta_boxes', 'comment', $comment );
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,7 +31,7 @@ add_meta_box( 'linktargetdiv', __( 'Target' ), 'link_target_meta_box', null, 'no
|
|||
add_meta_box( 'linkxfndiv', __( 'Link Relationship (XFN)' ), 'link_xfn_meta_box', null, 'normal', 'core' );
|
||||
add_meta_box( 'linkadvanceddiv', __( 'Advanced' ), 'link_advanced_meta_box', null, 'normal', 'core' );
|
||||
|
||||
/** This action is documented in wp-admin/edit-form-advanced.php */
|
||||
/** This action is documented in wp-admin/includes/meta-boxes.php */
|
||||
do_action( 'add_meta_boxes', 'link', $link );
|
||||
|
||||
/**
|
||||
|
@ -43,11 +43,11 @@ do_action( 'add_meta_boxes', 'link', $link );
|
|||
*/
|
||||
do_action( 'add_meta_boxes_link', $link );
|
||||
|
||||
/** This action is documented in wp-admin/edit-form-advanced.php */
|
||||
/** This action is documented in wp-admin/includes/meta-boxes.php */
|
||||
do_action( 'do_meta_boxes', 'link', 'normal', $link );
|
||||
/** This action is documented in wp-admin/edit-form-advanced.php */
|
||||
/** This action is documented in wp-admin/includes/meta-boxes.php */
|
||||
do_action( 'do_meta_boxes', 'link', 'advanced', $link );
|
||||
/** This action is documented in wp-admin/edit-form-advanced.php */
|
||||
/** This action is documented in wp-admin/includes/meta-boxes.php */
|
||||
do_action( 'do_meta_boxes', 'link', 'side', $link );
|
||||
|
||||
add_screen_option(
|
||||
|
|
|
@ -132,10 +132,10 @@ function wp_dashboard_setup() {
|
|||
exit;
|
||||
}
|
||||
|
||||
/** This action is documented in wp-admin/edit-form-advanced.php */
|
||||
/** This action is documented in wp-admin/includes/meta-boxes.php */
|
||||
do_action( 'do_meta_boxes', $screen->id, 'normal', '' );
|
||||
|
||||
/** This action is documented in wp-admin/edit-form-advanced.php */
|
||||
/** This action is documented in wp-admin/includes/meta-boxes.php */
|
||||
do_action( 'do_meta_boxes', $screen->id, 'side', '' );
|
||||
}
|
||||
|
||||
|
|
|
@ -1363,3 +1363,182 @@ function attachment_id3_data_meta_box( $post ) {
|
|||
<?php
|
||||
endforeach;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the default post meta boxes, and runs the `do_meta_boxes` actions.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param WP_Post $post The post object that these meta boxes are being generated for.
|
||||
*/
|
||||
function register_and_do_post_meta_boxes( $post ) {
|
||||
$post_type = $post->post_type;
|
||||
$post_type_object = get_post_type_object( $post_type );
|
||||
|
||||
$thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' );
|
||||
if ( ! $thumbnail_support && 'attachment' === $post_type && $post->post_mime_type ) {
|
||||
if ( wp_attachment_is( 'audio', $post ) ) {
|
||||
$thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' );
|
||||
} elseif ( wp_attachment_is( 'video', $post ) ) {
|
||||
$thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
|
||||
}
|
||||
}
|
||||
|
||||
$publish_callback_args = array( '__back_compat_meta_box' => true );
|
||||
if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' != $post->post_status ) {
|
||||
$revisions = wp_get_post_revisions( $post->ID );
|
||||
|
||||
// We should aim to show the revisions meta box only when there are revisions.
|
||||
if ( count( $revisions ) > 1 ) {
|
||||
reset( $revisions ); // Reset pointer for key()
|
||||
$publish_callback_args = array(
|
||||
'revisions_count' => count( $revisions ),
|
||||
'revision_id' => key( $revisions ),
|
||||
'__back_compat_meta_box' => true,
|
||||
);
|
||||
add_meta_box( 'revisionsdiv', __( 'Revisions' ), 'post_revisions_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'attachment' == $post_type ) {
|
||||
wp_enqueue_script( 'image-edit' );
|
||||
wp_enqueue_style( 'imgareaselect' );
|
||||
add_meta_box( 'submitdiv', __( 'Save' ), 'attachment_submit_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
add_action( 'edit_form_after_title', 'edit_form_image_editor' );
|
||||
|
||||
if ( wp_attachment_is( 'audio', $post ) ) {
|
||||
add_meta_box( 'attachment-id3', __( 'Metadata' ), 'attachment_id3_data_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
} else {
|
||||
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core', $publish_callback_args );
|
||||
}
|
||||
|
||||
if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) ) {
|
||||
add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
// all taxonomies
|
||||
foreach ( get_object_taxonomies( $post ) as $tax_name ) {
|
||||
$taxonomy = get_taxonomy( $tax_name );
|
||||
if ( ! $taxonomy->show_ui || false === $taxonomy->meta_box_cb ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$label = $taxonomy->labels->name;
|
||||
|
||||
if ( ! is_taxonomy_hierarchical( $tax_name ) ) {
|
||||
$tax_meta_box_id = 'tagsdiv-' . $tax_name;
|
||||
} else {
|
||||
$tax_meta_box_id = $tax_name . 'div';
|
||||
}
|
||||
|
||||
add_meta_box(
|
||||
$tax_meta_box_id,
|
||||
$label,
|
||||
$taxonomy->meta_box_cb,
|
||||
null,
|
||||
'side',
|
||||
'core',
|
||||
array(
|
||||
'taxonomy' => $tax_name,
|
||||
'__back_compat_meta_box' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( post_type_supports( $post_type, 'page-attributes' ) || count( get_page_templates( $post ) ) > 0 ) {
|
||||
add_meta_box( 'pageparentdiv', $post_type_object->labels->attributes, 'page_attributes_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
if ( $thumbnail_support && current_user_can( 'upload_files' ) ) {
|
||||
add_meta_box( 'postimagediv', esc_html( $post_type_object->labels->featured_image ), 'post_thumbnail_meta_box', null, 'side', 'low', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
if ( post_type_supports( $post_type, 'excerpt' ) ) {
|
||||
add_meta_box( 'postexcerpt', __( 'Excerpt' ), 'post_excerpt_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
if ( post_type_supports( $post_type, 'trackbacks' ) ) {
|
||||
add_meta_box( 'trackbacksdiv', __( 'Send Trackbacks' ), 'post_trackback_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
if ( post_type_supports( $post_type, 'custom-fields' ) ) {
|
||||
add_meta_box( 'postcustom', __( 'Custom Fields' ), 'post_custom_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires in the middle of built-in meta box registration.
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @deprecated 3.7.0 Use 'add_meta_boxes' instead.
|
||||
*
|
||||
* @param WP_Post $post Post object.
|
||||
*/
|
||||
do_action( 'dbx_post_advanced', $post );
|
||||
|
||||
// Allow the Discussion meta box to show up if the post type supports comments,
|
||||
// or if comments or pings are open.
|
||||
if ( comments_open( $post ) || pings_open( $post ) || post_type_supports( $post_type, 'comments' ) ) {
|
||||
add_meta_box( 'commentstatusdiv', __( 'Discussion' ), 'post_comment_status_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
$stati = get_post_stati( array( 'public' => true ) );
|
||||
if ( empty( $stati ) ) {
|
||||
$stati = array( 'publish' );
|
||||
}
|
||||
$stati[] = 'private';
|
||||
|
||||
if ( in_array( get_post_status( $post ), $stati ) ) {
|
||||
// If the post type support comments, or the post has comments, allow the
|
||||
// Comments meta box.
|
||||
if ( comments_open( $post ) || pings_open( $post ) || $post->comment_count > 0 || post_type_supports( $post_type, 'comments' ) ) {
|
||||
add_meta_box( 'commentsdiv', __( 'Comments' ), 'post_comment_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) ) {
|
||||
add_meta_box( 'slugdiv', __( 'Slug' ), 'post_slug_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
if ( post_type_supports( $post_type, 'author' ) && current_user_can( $post_type_object->cap->edit_others_posts ) ) {
|
||||
add_meta_box( 'authordiv', __( 'Author' ), 'post_author_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires after all built-in meta boxes have been added.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $post_type Post type.
|
||||
* @param WP_Post $post Post object.
|
||||
*/
|
||||
do_action( 'add_meta_boxes', $post_type, $post );
|
||||
|
||||
/**
|
||||
* Fires after all built-in meta boxes have been added, contextually for the given post type.
|
||||
*
|
||||
* The dynamic portion of the hook, `$post_type`, refers to the post type of the post.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param WP_Post $post Post object.
|
||||
*/
|
||||
do_action( "add_meta_boxes_{$post_type}", $post );
|
||||
|
||||
/**
|
||||
* Fires after meta boxes have been added.
|
||||
*
|
||||
* Fires once for each of the default meta box contexts: normal, advanced, and side.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $post_type Post type of the post.
|
||||
* @param string $context string Meta box context.
|
||||
* @param WP_Post $post Post object.
|
||||
*/
|
||||
do_action( 'do_meta_boxes', $post_type, 'normal', $post );
|
||||
/** This action is documented in wp-admin/includes/meta-boxes.php */
|
||||
do_action( 'do_meta_boxes', $post_type, 'advanced', $post );
|
||||
/** This action is documented in wp-admin/includes/meta-boxes.php */
|
||||
do_action( 'do_meta_boxes', $post_type, 'side', $post );
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.1-alpha-44207';
|
||||
$wp_version = '5.1-alpha-44214';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue