Make WordPress Core

Changeset 44132


Ignore:
Timestamp:
12/14/2018 01:17:57 AM (8 years ago)
Author:
pento
Message:

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.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

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

    r43571 r44132  
    245245
    246246
    247 $publish_callback_args = null;
     247$publish_callback_args = array( '__back_compat_meta_box' => true );
    248248if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' != $post->post_status ) {
    249249        $revisions = wp_get_post_revisions( $post_ID );
    … …  
    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}
    … …  
    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 {
    … …  
    274275
    275276if ( 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
    … …  
    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
    297309if ( 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
    301313if ( $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
    305317if ( 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
    309321if ( 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
    313325if ( 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
    … …  
    328340// or if comments or pings are open.
    329341if ( 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
    … …  
    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
    347359if ( ! ( '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
    351363if ( 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
  • trunk/src/wp-admin/includes/template.php

    r43976 r44132  
    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' : '';
    … …  
    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";
Note: See TracChangeset for help on using the changeset viewer.