Meta Boxes: Add `__back_compat_meta_box` and `__block_editor_compatible_meta_box` flags to meta boxes.

When meta boxes are registered, they can use the `__back_compat_meta_box` and `__block_editor_compatible_meta_box` flags, to show whether this registration just exists for if the classic editor is loaded, and whether this meta box is compatible with the block editor.

When a meta box marks itself as incompatible with the block editor, and `WP_DEBUG` is enabled, a warning will show inside that meta box in the classic editor.

As all core meta boxes have been recreated in the block editor, they can be marked with the `__back_compat_meta_box` flag.

Merges [43779] from the 5.0 branch to trunk.

See #45112.


Built from https://develop.svn.wordpress.org/trunk@44132


git-svn-id: http://core.svn.wordpress.org/trunk@43962 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2018-12-14 01:18:38 +00:00
parent a119d4561e
commit daaf15cb09
3 changed files with 88 additions and 18 deletions

View File

@ -244,7 +244,7 @@ $post_type_object = get_post_type_object( $post_type );
require_once( ABSPATH . 'wp-admin/includes/meta-boxes.php' ); require_once( ABSPATH . 'wp-admin/includes/meta-boxes.php' );
$publish_callback_args = null; $publish_callback_args = array( '__back_compat_meta_box' => true );
if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' != $post->post_status ) { if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' != $post->post_status ) {
$revisions = wp_get_post_revisions( $post_ID ); $revisions = wp_get_post_revisions( $post_ID );
@ -254,26 +254,27 @@ if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' != $post->pos
$publish_callback_args = array( $publish_callback_args = array(
'revisions_count' => count( $revisions ), 'revisions_count' => count( $revisions ),
'revision_id' => key( $revisions ), 'revision_id' => key( $revisions ),
'__back_compat_meta_box' => true,
); );
add_meta_box( 'revisionsdiv', __( 'Revisions' ), 'post_revisions_meta_box', null, 'normal', 'core' ); add_meta_box( 'revisionsdiv', __( 'Revisions' ), 'post_revisions_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
} }
} }
if ( 'attachment' == $post_type ) { if ( 'attachment' == $post_type ) {
wp_enqueue_script( 'image-edit' ); wp_enqueue_script( 'image-edit' );
wp_enqueue_style( 'imgareaselect' ); wp_enqueue_style( 'imgareaselect' );
add_meta_box( 'submitdiv', __( 'Save' ), 'attachment_submit_meta_box', null, 'side', 'core' ); 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' ); add_action( 'edit_form_after_title', 'edit_form_image_editor' );
if ( wp_attachment_is( 'audio', $post ) ) { if ( wp_attachment_is( 'audio', $post ) ) {
add_meta_box( 'attachment-id3', __( 'Metadata' ), 'attachment_id3_data_meta_box', null, 'normal', 'core' ); add_meta_box( 'attachment-id3', __( 'Metadata' ), 'attachment_id3_data_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
} }
} else { } else {
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core', $publish_callback_args ); 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' ) ) { 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' ); add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
} }
// all taxonomies // all taxonomies
@ -291,27 +292,38 @@ foreach ( get_object_taxonomies( $post ) as $tax_name ) {
$tax_meta_box_id = $tax_name . 'div'; $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 ) ); 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 ) { 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' ); 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' ) ) { 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' ); 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' ) ) { if ( post_type_supports( $post_type, 'excerpt' ) ) {
add_meta_box( 'postexcerpt', __( 'Excerpt' ), 'post_excerpt_meta_box', null, 'normal', 'core' ); 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' ) ) { if ( post_type_supports( $post_type, 'trackbacks' ) ) {
add_meta_box( 'trackbacksdiv', __( 'Send Trackbacks' ), 'post_trackback_meta_box', null, 'normal', 'core' ); 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' ) ) { if ( post_type_supports( $post_type, 'custom-fields' ) ) {
add_meta_box( 'postcustom', __( 'Custom Fields' ), 'post_custom_meta_box', null, 'normal', 'core' ); add_meta_box( 'postcustom', __( 'Custom Fields' ), 'post_custom_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
} }
/** /**
@ -327,7 +339,7 @@ do_action( 'dbx_post_advanced', $post );
// Allow the Discussion meta box to show up if the post type supports comments, // Allow the Discussion meta box to show up if the post type supports comments,
// or if comments or pings are open. // or if comments or pings are open.
if ( comments_open( $post ) || pings_open( $post ) || post_type_supports( $post_type, 'comments' ) ) { 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' ); 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 ) ); $stati = get_post_stati( array( 'public' => true ) );
@ -340,16 +352,16 @@ if ( in_array( get_post_status( $post ), $stati ) ) {
// If the post type support comments, or the post has comments, allow the // If the post type support comments, or the post has comments, allow the
// Comments meta box. // Comments meta box.
if ( comments_open( $post ) || pings_open( $post ) || $post->comment_count > 0 || post_type_supports( $post_type, 'comments' ) ) { 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' ); 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 ) ) ) { 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' ); 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 ) ) { 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' ); add_meta_box( 'authordiv', __( 'Author' ), 'post_author_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
} }
/** /**

View File

@ -1136,6 +1136,28 @@ function do_meta_boxes( $screen, $context, $object ) {
if ( false == $box || ! $box['title'] ) { if ( false == $box || ! $box['title'] ) {
continue; continue;
} }
// Don't show boxes in the block editor, if they're just here for back compat.
if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) {
continue;
}
// Don't show boxes in the block editor that aren't compatible with the block editor.
if ( $screen->is_block_editor() && isset( $box['args']['__block_editor_compatible_meta_box'] ) && ! $box['args']['__block_editor_compatible_meta_box'] ) {
continue;
}
$block_compatible = true;
if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) {
$block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box'];
unset( $box['args']['__block_editor_compatible_meta_box'] );
}
if ( isset( $box['args']['__back_compat_meta_box'] ) ) {
$block_compatible |= (bool) $box['args']['__back_compat_meta_box'];
unset( $box['args']['__back_compat_meta_box'] );
}
$i++; $i++;
$hidden_class = in_array( $box['id'], $hidden ) ? ' hide-if-js' : ''; $hidden_class = in_array( $box['id'], $hidden ) ? ' hide-if-js' : '';
echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes( $box['id'], $page ) . $hidden_class . '" ' . '>' . "\n"; echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes( $box['id'], $page ) . $hidden_class . '" ' . '>' . "\n";
@ -1161,6 +1183,42 @@ function do_meta_boxes( $screen, $context, $object ) {
echo "<span>{$box['title']}</span>"; echo "<span>{$box['title']}</span>";
echo "</h2>\n"; echo "</h2>\n";
echo '<div class="inside">' . "\n"; echo '<div class="inside">' . "\n";
if ( WP_DEBUG && ! $screen->is_block_editor() && ! isset( $_GET['meta-box-loader'] ) ) {
if ( is_array( $box['callback'] ) ) {
$reflection = new ReflectionMethod( $box['callback'][0], $box['callback'][1] );
} else {
$reflection = new ReflectionFunction( $box['callback'] );
}
// Don't show an error if it's an internal PHP function.
if ( ! $reflection->isInternal() ) {
// Only show errors if the meta box was registered by a plugin.
$filename = $reflection->getFileName();
if ( strpos( $filename, WP_PLUGIN_DIR ) === 0 ) {
$filename = str_replace( WP_PLUGIN_DIR, '', $filename );
$filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename );
$plugins = get_plugins();
foreach ( $plugins as $name => $plugin ) {
if ( strpos( $name, $filename ) === 0 ) {
?>
<div class="error inline">
<p>
<?php
/* translators: %s: the name of the plugin that generated this meta box. */
printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "<strong>{$plugin['Name']}</strong>" );
?>
</p>
</div>
<?php
}
}
}
}
}
call_user_func( $box['callback'], $object, $box ); call_user_func( $box['callback'], $object, $box );
echo "</div>\n"; echo "</div>\n";
echo "</div>\n"; echo "</div>\n";

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.1-alpha-44131'; $wp_version = '5.1-alpha-44132';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.