From daaf15cb09c5f5f2ce6eedbc28c20a7274505fd9 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Fri, 14 Dec 2018 01:18:38 +0000 Subject: [PATCH] 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 --- wp-admin/edit-form-advanced.php | 46 ++++++++++++++++---------- wp-admin/includes/template.php | 58 +++++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 3 files changed, 88 insertions(+), 18 deletions(-) diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 6be549ad3a..1908f5c5e3 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -244,7 +244,7 @@ $post_type_object = get_post_type_object( $post_type ); 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 ) { $revisions = wp_get_post_revisions( $post_ID ); @@ -252,28 +252,29 @@ if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' != $post->pos if ( count( $revisions ) > 1 ) { reset( $revisions ); // Reset pointer for key() $publish_callback_args = array( - 'revisions_count' => count( $revisions ), - 'revision_id' => key( $revisions ), + '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' ); + 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' ); + 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' ); + 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' ); + add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) ); } // all taxonomies @@ -291,27 +292,38 @@ foreach ( get_object_taxonomies( $post ) as $tax_name ) { $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 ) { - 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' ) ) { - 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' ) ) { - 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' ) ) { - 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' ) ) { - 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, // 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' ); + 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 ) ); @@ -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 // 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' ); + 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' ); + 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' ); + add_meta_box( 'authordiv', __( 'Author' ), 'post_author_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) ); } /** diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 75b92889e7..a1cd160076 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -1136,6 +1136,28 @@ function do_meta_boxes( $screen, $context, $object ) { if ( false == $box || ! $box['title'] ) { 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++; $hidden_class = in_array( $box['id'], $hidden ) ? ' hide-if-js' : ''; echo '
' . "\n"; @@ -1161,6 +1183,42 @@ function do_meta_boxes( $screen, $context, $object ) { echo "{$box['title']}"; echo "\n"; echo '
' . "\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 ) { + ?> +
+

+ {$plugin['Name']}" ); + ?> +

+
+ \n"; echo "
\n"; diff --git a/wp-includes/version.php b/wp-includes/version.php index 80cb519849..d1812099a9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @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.