mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-09 15:14:37 +00:00
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
This commit is contained in:
@@ -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 '<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 "</h2>\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 );
|
||||
echo "</div>\n";
|
||||
echo "</div>\n";
|
||||
|
||||
Reference in New Issue
Block a user