Make WordPress Core


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:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • 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.