Skip to content

Commit 23efeb4

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@44132 602fd350-edb4-49c9-b593-d223f7449a82
1 parent cb0b292 commit 23efeb4

2 files changed

Lines changed: 87 additions & 17 deletions

File tree

src/wp-admin/edit-form-advanced.php

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -244,36 +244,37 @@
244244
require_once( ABSPATH . 'wp-admin/includes/meta-boxes.php' );
245245

246246

247-
$publish_callback_args = null;
247+
$publish_callback_args = array( '__back_compat_meta_box' => true );
248248
if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' != $post->post_status ) {
249249
$revisions = wp_get_post_revisions( $post_ID );
250250

251251
// We should aim to show the revisions meta box only when there are revisions.
252252
if ( count( $revisions ) > 1 ) {
253253
reset( $revisions ); // Reset pointer for key()
254254
$publish_callback_args = array(
255-
'revisions_count' => count( $revisions ),
256-
'revision_id' => key( $revisions ),
255+
'revisions_count' => count( $revisions ),
256+
'revision_id' => key( $revisions ),
257+
'__back_compat_meta_box' => true,
257258
);
258-
add_meta_box( 'revisionsdiv', __( 'Revisions' ), 'post_revisions_meta_box', null, 'normal', 'core' );
259+
add_meta_box( 'revisionsdiv', __( 'Revisions' ), 'post_revisions_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
259260
}
260261
}
261262

262263
if ( 'attachment' == $post_type ) {
263264
wp_enqueue_script( 'image-edit' );
264265
wp_enqueue_style( 'imgareaselect' );
265-
add_meta_box( 'submitdiv', __( 'Save' ), 'attachment_submit_meta_box', null, 'side', 'core' );
266+
add_meta_box( 'submitdiv', __( 'Save' ), 'attachment_submit_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
266267
add_action( 'edit_form_after_title', 'edit_form_image_editor' );
267268

268269
if ( wp_attachment_is( 'audio', $post ) ) {
269-
add_meta_box( 'attachment-id3', __( 'Metadata' ), 'attachment_id3_data_meta_box', null, 'normal', 'core' );
270+
add_meta_box( 'attachment-id3', __( 'Metadata' ), 'attachment_id3_data_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
270271
}
271272
} else {
272273
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core', $publish_callback_args );
273274
}
274275

275276
if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) ) {
276-
add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core' );
277+
add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
277278
}
278279

279280
// all taxonomies
@@ -291,27 +292,38 @@
291292
$tax_meta_box_id = $tax_name . 'div';
292293
}
293294

294-
add_meta_box( $tax_meta_box_id, $label, $taxonomy->meta_box_cb, null, 'side', 'core', array( 'taxonomy' => $tax_name ) );
295+
add_meta_box(
296+
$tax_meta_box_id,
297+
$label,
298+
$taxonomy->meta_box_cb,
299+
null,
300+
'side',
301+
'core',
302+
array(
303+
'taxonomy' => $tax_name,
304+
'__back_compat_meta_box' => true,
305+
)
306+
);
295307
}
296308

297309
if ( post_type_supports( $post_type, 'page-attributes' ) || count( get_page_templates( $post ) ) > 0 ) {
298-
add_meta_box( 'pageparentdiv', $post_type_object->labels->attributes, 'page_attributes_meta_box', null, 'side', 'core' );
310+
add_meta_box( 'pageparentdiv', $post_type_object->labels->attributes, 'page_attributes_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
299311
}
300312

301313
if ( $thumbnail_support && current_user_can( 'upload_files' ) ) {
302-
add_meta_box( 'postimagediv', esc_html( $post_type_object->labels->featured_image ), 'post_thumbnail_meta_box', null, 'side', 'low' );
314+
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 ) );
303315
}
304316

305317
if ( post_type_supports( $post_type, 'excerpt' ) ) {
306-
add_meta_box( 'postexcerpt', __( 'Excerpt' ), 'post_excerpt_meta_box', null, 'normal', 'core' );
318+
add_meta_box( 'postexcerpt', __( 'Excerpt' ), 'post_excerpt_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
307319
}
308320

309321
if ( post_type_supports( $post_type, 'trackbacks' ) ) {
310-
add_meta_box( 'trackbacksdiv', __( 'Send Trackbacks' ), 'post_trackback_meta_box', null, 'normal', 'core' );
322+
add_meta_box( 'trackbacksdiv', __( 'Send Trackbacks' ), 'post_trackback_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
311323
}
312324

313325
if ( post_type_supports( $post_type, 'custom-fields' ) ) {
314-
add_meta_box( 'postcustom', __( 'Custom Fields' ), 'post_custom_meta_box', null, 'normal', 'core' );
326+
add_meta_box( 'postcustom', __( 'Custom Fields' ), 'post_custom_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
315327
}
316328

317329
/**
@@ -327,7 +339,7 @@
327339
// Allow the Discussion meta box to show up if the post type supports comments,
328340
// or if comments or pings are open.
329341
if ( comments_open( $post ) || pings_open( $post ) || post_type_supports( $post_type, 'comments' ) ) {
330-
add_meta_box( 'commentstatusdiv', __( 'Discussion' ), 'post_comment_status_meta_box', null, 'normal', 'core' );
342+
add_meta_box( 'commentstatusdiv', __( 'Discussion' ), 'post_comment_status_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
331343
}
332344

333345
$stati = get_post_stati( array( 'public' => true ) );
@@ -340,16 +352,16 @@
340352
// If the post type support comments, or the post has comments, allow the
341353
// Comments meta box.
342354
if ( comments_open( $post ) || pings_open( $post ) || $post->comment_count > 0 || post_type_supports( $post_type, 'comments' ) ) {
343-
add_meta_box( 'commentsdiv', __( 'Comments' ), 'post_comment_meta_box', null, 'normal', 'core' );
355+
add_meta_box( 'commentsdiv', __( 'Comments' ), 'post_comment_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
344356
}
345357
}
346358

347359
if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) ) {
348-
add_meta_box( 'slugdiv', __( 'Slug' ), 'post_slug_meta_box', null, 'normal', 'core' );
360+
add_meta_box( 'slugdiv', __( 'Slug' ), 'post_slug_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
349361
}
350362

351363
if ( post_type_supports( $post_type, 'author' ) && current_user_can( $post_type_object->cap->edit_others_posts ) ) {
352-
add_meta_box( 'authordiv', __( 'Author' ), 'post_author_meta_box', null, 'normal', 'core' );
364+
add_meta_box( 'authordiv', __( 'Author' ), 'post_author_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
353365
}
354366

355367
/**

src/wp-admin/includes/template.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,28 @@ function do_meta_boxes( $screen, $context, $object ) {
11361136
if ( false == $box || ! $box['title'] ) {
11371137
continue;
11381138
}
1139+
1140+
// Don't show boxes in the block editor, if they're just here for back compat.
1141+
if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) {
1142+
continue;
1143+
}
1144+
1145+
// Don't show boxes in the block editor that aren't compatible with the block editor.
1146+
if ( $screen->is_block_editor() && isset( $box['args']['__block_editor_compatible_meta_box'] ) && ! $box['args']['__block_editor_compatible_meta_box'] ) {
1147+
continue;
1148+
}
1149+
1150+
$block_compatible = true;
1151+
if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) {
1152+
$block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box'];
1153+
unset( $box['args']['__block_editor_compatible_meta_box'] );
1154+
}
1155+
1156+
if ( isset( $box['args']['__back_compat_meta_box'] ) ) {
1157+
$block_compatible |= (bool) $box['args']['__back_compat_meta_box'];
1158+
unset( $box['args']['__back_compat_meta_box'] );
1159+
}
1160+
11391161
$i++;
11401162
$hidden_class = in_array( $box['id'], $hidden ) ? ' hide-if-js' : '';
11411163
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 ) {
11611183
echo "<span>{$box['title']}</span>";
11621184
echo "</h2>\n";
11631185
echo '<div class="inside">' . "\n";
1186+
1187+
if ( WP_DEBUG && ! $screen->is_block_editor() && ! isset( $_GET['meta-box-loader'] ) ) {
1188+
if ( is_array( $box['callback'] ) ) {
1189+
$reflection = new ReflectionMethod( $box['callback'][0], $box['callback'][1] );
1190+
} else {
1191+
$reflection = new ReflectionFunction( $box['callback'] );
1192+
}
1193+
1194+
// Don't show an error if it's an internal PHP function.
1195+
if ( ! $reflection->isInternal() ) {
1196+
1197+
// Only show errors if the meta box was registered by a plugin.
1198+
$filename = $reflection->getFileName();
1199+
if ( strpos( $filename, WP_PLUGIN_DIR ) === 0 ) {
1200+
$filename = str_replace( WP_PLUGIN_DIR, '', $filename );
1201+
$filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename );
1202+
1203+
$plugins = get_plugins();
1204+
foreach ( $plugins as $name => $plugin ) {
1205+
if ( strpos( $name, $filename ) === 0 ) {
1206+
?>
1207+
<div class="error inline">
1208+
<p>
1209+
<?php
1210+
/* translators: %s: the name of the plugin that generated this meta box. */
1211+
printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "<strong>{$plugin['Name']}</strong>" );
1212+
?>
1213+
</p>
1214+
</div>
1215+
<?php
1216+
}
1217+
}
1218+
}
1219+
}
1220+
}
1221+
11641222
call_user_func( $box['callback'], $object, $box );
11651223
echo "</div>\n";
11661224
echo "</div>\n";

0 commit comments

Comments
 (0)