diff --git a/docs/designers-developers/developers/backward-compatibility/deprecations.md b/docs/designers-developers/developers/backward-compatibility/deprecations.md
index b3a007565f0c8..f2ce4c1ee8d2f 100644
--- a/docs/designers-developers/developers/backward-compatibility/deprecations.md
+++ b/docs/designers-developers/developers/backward-compatibility/deprecations.md
@@ -44,6 +44,18 @@ The Gutenberg project's deprecation policy is intended to support backward compa
- The PHP function `gutenberg_check_if_classic_needs_warning_about_blocks` has been removed.
- The PHP function `gutenberg_warn_classic_about_blocks` has been removed.
- The PHP function `gutenberg_show_privacy_policy_help_text` has been removed.
+- The PHP function `gutenberg_common_scripts_and_styles` has been removed. Use [`wp_common_block_scripts_and_styles`](https://developer.wordpress.org/reference/functions/wp_common_block_scripts_and_styles/) instead.
+- The PHP function `gutenberg_enqueue_registered_block_scripts_and_styles` has been removed. Use [`wp_enqueue_registered_block_scripts_and_styles`](https://developer.wordpress.org/reference/functions/wp_enqueue_registered_block_scripts_and_styles/) instead.
+- The PHP function `gutenberg_meta_box_save` has been removed.
+- The PHP function `gutenberg_meta_box_save_redirect` has been removed.
+- The PHP function `gutenberg_filter_meta_boxes` has been removed.
+- The PHP function `gutenberg_intercept_meta_box_render` has been removed.
+- The PHP function `gutenberg_override_meta_box_callback` has been removed.
+- The PHP function `gutenberg_show_meta_box_warning` has been removed.
+- The PHP function `the_gutenberg_metaboxes` has been removed. Use [`the_block_editor_meta_boxes`](https://developer.wordpress.org/reference/functions/the_block_editor_meta_boxes/) instead.
+- The PHP function `gutenberg_meta_box_post_form_hidden_fields` has been removed. Use [`the_block_editor_meta_box_post_form_hidden_fields`](https://developer.wordpress.org/reference/functions/the_block_editor_meta_box_post_form_hidden_fields/) instead.
+- The PHP function `gutenberg_toggle_custom_fields` has been removed.
+- The PHP function `gutenberg_collect_meta_box_data` has been removed. Use [`register_and_do_post_meta_boxes`](https://developer.wordpress.org/reference/functions/register_and_do_post_meta_boxes/) instead.
## 4.5.0
- `Dropdown.refresh()` has been deprecated as the contained `Popover` is now automatically refreshed.
diff --git a/gutenberg.php b/gutenberg.php
index 09d759a64c488..f91df4b918597 100644
--- a/gutenberg.php
+++ b/gutenberg.php
@@ -52,8 +52,8 @@ function the_gutenberg_project() {
labels->edit_item ); ?>
-
-
+
+
is_block_editor( true );
+
add_action( 'admin_enqueue_scripts', 'gutenberg_editor_scripts_and_styles' );
add_filter( 'screen_options_show_screen', '__return_false' );
add_filter( 'admin_body_class', 'gutenberg_add_admin_body_class' );
@@ -237,7 +246,7 @@ function gutenberg_init( $return, $post ) {
* includes/meta-boxes is typically loaded from edit-form-advanced.php.
*/
require_once ABSPATH . 'wp-admin/includes/meta-boxes.php';
- gutenberg_collect_meta_box_data();
+ register_and_do_post_meta_boxes( $post );
require_once ABSPATH . 'wp-admin/admin-header.php';
the_gutenberg_project();
diff --git a/lib/client-assets.php b/lib/client-assets.php
index 15ffc18d86516..c90cb8a05a8ff 100644
--- a/lib/client-assets.php
+++ b/lib/client-assets.php
@@ -721,72 +721,26 @@ function gutenberg_prepare_blocks_for_js() {
* are loaded last.
*
* @since 0.4.0
+ * @deprecated 5.0.0 wp_common_block_scripts_and_styles
*/
function gutenberg_common_scripts_and_styles() {
- if ( ! is_gutenberg_page() && is_admin() ) {
- return;
- }
-
- // Enqueue basic styles built out of Gutenberg through `npm build`.
- wp_enqueue_style( 'wp-block-library' );
-
- /*
- * Enqueue block styles built through plugins. This lives in a separate
- * action for a couple of reasons: (1) we want to load these assets
- * (usually stylesheets) in *both* frontend and editor contexts, and (2)
- * one day we may need to be smarter about whether assets are included
- * based on whether blocks are actually present on the page.
- */
+ _deprecated_function( __FUNCTION__, '5.0.0', 'wp_common_block_scripts_and_styles' );
- /**
- * Fires after enqueuing block assets for both editor and front-end.
- *
- * Call `add_action` on any hook before 'wp_enqueue_scripts'.
- *
- * In the function call you supply, simply use `wp_enqueue_script` and
- * `wp_enqueue_style` to add your functionality to the Gutenberg editor.
- *
- * @since 0.4.0
- */
- do_action( 'enqueue_block_assets' );
+ wp_common_block_scripts_and_styles();
}
-add_action( 'wp_enqueue_scripts', 'gutenberg_common_scripts_and_styles' );
-add_action( 'admin_enqueue_scripts', 'gutenberg_common_scripts_and_styles' );
/**
* Enqueues registered block scripts and styles, depending on current rendered
* context (only enqueuing editor scripts while in context of the editor).
*
* @since 2.0.0
+ * @deprecated 5.0.0 wp_enqueue_registered_block_scripts_and_styles
*/
function gutenberg_enqueue_registered_block_scripts_and_styles() {
- $is_editor = ( 'enqueue_block_editor_assets' === current_action() );
+ _deprecated_function( __FUNCTION__, '5.0.0', 'wp_enqueue_registered_block_scripts_and_styles' );
- $block_registry = WP_Block_Type_Registry::get_instance();
- foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
- // Front-end styles.
- if ( ! empty( $block_type->style ) ) {
- wp_enqueue_style( $block_type->style );
- }
-
- // Front-end script.
- if ( ! empty( $block_type->script ) ) {
- wp_enqueue_script( $block_type->script );
- }
-
- // Editor styles.
- if ( $is_editor && ! empty( $block_type->editor_style ) ) {
- wp_enqueue_style( $block_type->editor_style );
- }
-
- // Editor script.
- if ( $is_editor && ! empty( $block_type->editor_script ) ) {
- wp_enqueue_script( $block_type->editor_script );
- }
- }
+ wp_enqueue_registered_block_scripts_and_styles();
}
-add_action( 'enqueue_block_assets', 'gutenberg_enqueue_registered_block_scripts_and_styles' );
-add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_registered_block_scripts_and_styles' );
/**
* Assigns a default editor template with a default block by post format, if
@@ -1074,10 +1028,10 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
$meta_box_url = admin_url( 'post.php' );
$meta_box_url = add_query_arg(
array(
- 'post' => $post->ID,
- 'action' => 'edit',
- 'classic-editor' => true,
- 'meta_box' => true,
+ 'post' => $post->ID,
+ 'action' => 'edit',
+ 'meta-box-loader' => true,
+ '_wpnonce' => wp_create_nonce( 'meta-box-loader' ),
),
$meta_box_url
);
@@ -1277,7 +1231,7 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
$init_script = << true,
- 'action' => 'edit',
- 'classic-editor' => true,
- 'post' => $post_id,
- ),
- admin_url( 'post.php' )
- );
- }
+function gutenberg_meta_box_save_redirect( $location ) {
+ _deprecated_function( __FUNCTION__, '5.0.0' );
return $location;
}
-add_filter( 'redirect_post_location', 'gutenberg_meta_box_save_redirect', 10, 2 );
-
/**
* Filter out core meta boxes as well as the post thumbnail.
*
* @since 1.5.0
+ * @deprecated 5.0.0
*
* @param array $meta_boxes Meta box data.
* @return array Meta box data without core meta boxes.
*/
function gutenberg_filter_meta_boxes( $meta_boxes ) {
- $core_side_meta_boxes = array(
- 'submitdiv',
- 'formatdiv',
- 'pageparentdiv',
- 'postimagediv',
- );
-
- $custom_taxonomies = get_taxonomies(
- array(
- 'show_ui' => true,
- ),
- 'objects'
- );
-
- // Following the same logic as meta box generation in:
- // https://github.com/WordPress/wordpress-develop/blob/c896326/src/wp-admin/edit-form-advanced.php#L288-L292.
- foreach ( $custom_taxonomies as $custom_taxonomy ) {
- $core_side_meta_boxes [] = $custom_taxonomy->hierarchical ?
- $custom_taxonomy->name . 'div' :
- 'tagsdiv-' . $custom_taxonomy->name;
- }
-
- $core_normal_meta_boxes = array(
- 'revisionsdiv',
- 'postexcerpt',
- 'trackbacksdiv',
- 'commentstatusdiv',
- 'commentsdiv',
- 'slugdiv',
- 'authordiv',
- );
-
- // Whether or not to load the 'postcustom' meta box is stored as a user meta
- // field so that we're not always loading its assets.
- $enable_custom_fields = (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true );
- if ( ! $enable_custom_fields ) {
- $core_normal_meta_boxes[] = 'postcustom';
- }
-
- $taxonomy_callbacks_to_unset = array(
- 'post_tags_meta_box',
- 'post_categories_meta_box',
- );
-
- foreach ( $meta_boxes as $page => $contexts ) {
- foreach ( $contexts as $context => $priorities ) {
- foreach ( $priorities as $priority => $boxes ) {
- foreach ( $boxes as $name => $data ) {
- if ( 'normal' === $context && in_array( $name, $core_normal_meta_boxes ) ) {
- unset( $meta_boxes[ $page ][ $context ][ $priority ][ $name ] );
- } elseif ( 'side' === $context && in_array( $name, $core_side_meta_boxes ) ) {
- unset( $meta_boxes[ $page ][ $context ][ $priority ][ $name ] );
- }
- // Filter out any taxonomies as Gutenberg already provides JS alternative.
- if ( isset( $data['callback'] ) && in_array( $data['callback'], $taxonomy_callbacks_to_unset ) ) {
- unset( $meta_boxes[ $page ][ $context ][ $priority ][ $name ] );
- }
- // Filter out meta boxes that are just registered for back compat.
- if ( isset( $data['args']['__back_compat_meta_box'] ) && $data['args']['__back_compat_meta_box'] ) {
- unset( $meta_boxes[ $page ][ $context ][ $priority ][ $name ] );
- }
- }
- }
- }
- }
+ _deprecated_function( __FUNCTION__, '5.0.0' );
return $meta_boxes;
}
-add_filter( 'filter_gutenberg_meta_boxes', 'gutenberg_filter_meta_boxes' );
-
/**
* Go through the global metaboxes, and override the render callback, so we can trigger our warning if needed.
*
* @since 1.8.0
+ * @deprecated 5.0.0
*/
function gutenberg_intercept_meta_box_render() {
- global $wp_meta_boxes;
-
- foreach ( $wp_meta_boxes as $post_type => $contexts ) {
- foreach ( $contexts as $context => $priorities ) {
- foreach ( $priorities as $priority => $boxes ) {
- foreach ( $boxes as $id => $box ) {
- if ( ! is_array( $box ) ) {
- continue;
- }
- if ( ! is_array( $wp_meta_boxes[ $post_type ][ $context ][ $priority ][ $id ]['args'] ) ) {
- $wp_meta_boxes[ $post_type ][ $context ][ $priority ][ $id ]['args'] = array();
- }
- if ( ! isset( $wp_meta_boxes[ $post_type ][ $context ][ $priority ][ $id ]['args']['__original_callback'] ) ) {
- $wp_meta_boxes[ $post_type ][ $context ][ $priority ][ $id ]['args']['__original_callback'] = $box['callback'];
- $wp_meta_boxes[ $post_type ][ $context ][ $priority ][ $id ]['callback'] = 'gutenberg_override_meta_box_callback';
- }
- }
- }
- }
- }
+ _deprecated_function( __FUNCTION__, '5.0.0' );
}
-add_action( 'submitpost_box', 'gutenberg_intercept_meta_box_render' );
-add_action( 'submitpage_box', 'gutenberg_intercept_meta_box_render' );
-add_action( 'edit_page_form', 'gutenberg_intercept_meta_box_render' );
-add_action( 'edit_form_advanced', 'gutenberg_intercept_meta_box_render' );
/**
* Check if this metabox only exists for back compat purposes, show a warning if it doesn't.
*
* @since 1.8.0
- *
- * @param mixed $object The object being operated on, on this screen.
- * @param array $box The current meta box definition.
+ * @deprecated 5.0.0
*/
-function gutenberg_override_meta_box_callback( $object, $box ) {
- $callback = $box['args']['__original_callback'];
- unset( $box['args']['__original_callback'] );
-
- $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'] );
- }
-
- if ( ! $block_compatible ) {
- gutenberg_show_meta_box_warning( $callback );
- }
-
- call_user_func( $callback, $object, $box );
+function gutenberg_override_meta_box_callback() {
+ _deprecated_function( __FUNCTION__, '5.0.0' );
}
/**
* Display a warning in the metabox that the current plugin is causing the fallback to the old editor.
*
* @since 1.8.0
- *
- * @param callable $callback The function that a plugin has defined to render a meta box.
+ * @deprecated 5.0.0
*/
-function gutenberg_show_meta_box_warning( $callback ) {
- // Only show the warning when WP_DEBUG is enabled.
- if ( ! WP_DEBUG ) {
- return;
- }
-
- // Don't show in the Gutenberg meta box UI.
- if ( ! isset( $_REQUEST['classic-editor'] ) ) {
- return;
- }
-
- try {
- if ( is_array( $callback ) ) {
- $reflection = new ReflectionMethod( $callback[0], $callback[1] );
- } else {
- $reflection = new ReflectionFunction( $callback );
- }
- } catch ( ReflectionException $exception ) {
- // We could not properly reflect on the callable, so we abort here.
- return;
- }
-
- if ( $reflection->isInternal() ) {
- return;
- }
-
- $filename = $reflection->getFileName();
- if ( strpos( $filename, WP_PLUGIN_DIR ) !== 0 ) {
- return;
- }
-
- $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 ) {
- ?>
-
-
-
-
-
-
-
-
-
-
-
- id ][ $location ][ $priority ] ) ) {
- $meta_boxes = (array) $wp_meta_boxes[ $current_screen->id ][ $location ][ $priority ];
- foreach ( $meta_boxes as $meta_box ) {
- if ( false == $meta_box || ! $meta_box['title'] ) {
- continue;
- }
-
- $meta_boxes_per_location[ $location ][] = array(
- 'id' => $meta_box['id'],
- 'title' => $meta_box['title'],
- );
- }
- }
- }
- }
+ _deprecated_function( __FUNCTION__, '5.0.0', 'the_block_editor_meta_boxes' );
- /**
- * Sadly we probably can not add this data directly into editor settings.
- *
- * ACF and other meta boxes need admin_head to fire for meta box registry.
- * admin_head fires after admin_enqueue_scripts which is where we create our
- * editor instance. If a cleaner solution can be imagined, please change
- * this, and try to get this data to load directly into the editor settings.
- */
- $script = 'window._wpLoadGutenbergEditor.then( function() {
- wp.data.dispatch( \'core/edit-post\' ).setAvailableMetaBoxesPerLocation( ' . wp_json_encode( $meta_boxes_per_location ) . ' );
- } );';
-
- wp_add_inline_script( 'wp-edit-post', $script );
-
- /**
- * When `wp-edit-post` is output in the ``, the inline script needs to be manually printed. Otherwise,
- * metaboxes will not display because inline scripts for `wp-edit-post` will not be printed again after this point.
- *
- * @see https://github.com/WordPress/gutenberg/issues/6963
- */
- if ( wp_script_is( 'wp-edit-post', 'done' ) ) {
- printf( "\n", trim( $script ) );
- }
-
- /**
- * If the 'postcustom' meta box is enabled, then we need to perform some
- * extra initialization on it.
- */
- $enable_custom_fields = (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true );
- if ( $enable_custom_fields ) {
- $script = "( function( $ ) {
- if ( $('#postcustom').length ) {
- $( '#the-list' ).wpList( {
- addBefore: function( s ) {
- s.data += '&post_id=$post->ID';
- return s;
- },
- addAfter: function() {
- $('table#list-table').show();
- }
- });
- }
- } )( jQuery );";
-
- wp_enqueue_script( 'wp-lists' );
- wp_add_inline_script( 'wp-lists', $script );
- }
-
- // Reset meta box data.
- $wp_meta_boxes = $_original_meta_boxes;
+ the_block_editor_meta_boxes();
}
/**
* Renders the hidden form required for the meta boxes form.
*
- * @param WP_Post $post Current post object.
- *
* @since 1.8.0
+ * @deprecated 5.0.0 the_block_editor_meta_box_post_form_hidden_fields
*/
-function gutenberg_meta_box_post_form_hidden_fields( $post ) {
- $form_extra = '';
- if ( 'auto-draft' === $post->post_status ) {
- $form_extra .= "";
- }
- $form_action = 'editpost';
- $nonce_action = 'update-post_' . $post->ID;
- $form_extra .= "";
- $referer = wp_get_referer();
- $current_user = wp_get_current_user();
- $user_id = $current_user->ID;
- wp_nonce_field( $nonce_action );
- ?>
-
-
-
-
-
-
-
-
+function gutenberg_meta_box_post_form_hidden_fields() {
+ _deprecated_function( __FUNCTION__, '5.0.0', 'the_block_editor_meta_box_post_form_hidden_fields' );
- post_type;
-
- if ( ! gutenberg_can_edit_post( $post->ID ) ) {
- return;
- }
- } else {
- // Eventually add handling for creating new posts of different types in Gutenberg.
- }
- $post_type = $post->post_type;
- $post_type_object = get_post_type_object( $post_type );
-
- if ( ! gutenberg_can_edit_post_type( $post_type ) ) {
- return;
- }
-
- // Disable hidden metaboxes because there's no UI to toggle visibility.
- add_filter( 'hidden_meta_boxes', '__return_empty_array' );
-
- $thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' );
- if ( ! $thumbnail_support && 'attachment' === $post_type && $post->post_mime_type ) {
- if ( wp_attachment_is( 'audio', $post ) ) {
- $thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' );
- } elseif ( wp_attachment_is( 'video', $post ) ) {
- $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
- }
- }
-
- /*
- * WIP: Collect and send information needed to render meta boxes.
- * From wp-admin/edit-form-advanced.php
- * Relevant code there:
- * do_action( 'do_meta_boxes', $post_type, {'normal','advanced','side'}, $post );
- * do_meta_boxes( $post_type, 'side', $post );
- * do_meta_boxes( null, 'normal', $post );
- * do_meta_boxes( null, 'advanced', $post );
- */
- $publish_callback_args = null;
- if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' !== $post->post_status ) {
- $revisions = wp_get_post_revisions( $post->ID );
-
- // We should aim to show the revisions meta box only when there are revisions.
- if ( count( $revisions ) > 1 ) {
- reset( $revisions ); // Reset pointer for key().
- $publish_callback_args = array(
- 'revisions_count' => count( $revisions ),
- 'revision_id' => key( $revisions ),
- );
- add_meta_box( 'revisionsdiv', __( 'Revisions', 'gutenberg' ), 'post_revisions_meta_box', $screen, 'normal', 'core' );
- }
- }
-
- if ( 'attachment' == $post_type ) {
- wp_enqueue_script( 'image-edit' );
- wp_enqueue_style( 'imgareaselect' );
- add_meta_box( 'submitdiv', __( 'Save', 'gutenberg' ), 'attachment_submit_meta_box', $screen, 'side', 'core' );
- add_action( 'edit_form_after_title', 'edit_form_image_editor' );
-
- if ( wp_attachment_is( 'audio', $post ) ) {
- add_meta_box( 'attachment-id3', __( 'Metadata', 'gutenberg' ), 'attachment_id3_data_meta_box', $screen, 'normal', 'core' );
- }
- } else {
- add_meta_box( 'submitdiv', __( 'Publish', 'gutenberg' ), 'post_submit_meta_box', $screen, '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', 'gutenberg' ), 'post_format_meta_box', $screen, 'side', 'core' );
- }
-
- // All taxonomies.
- foreach ( get_object_taxonomies( $post ) as $tax_name ) {
- $taxonomy = get_taxonomy( $tax_name );
- if ( ! $taxonomy->show_ui || false === $taxonomy->meta_box_cb ) {
- continue;
- }
-
- $label = $taxonomy->labels->name;
-
- if ( ! is_taxonomy_hierarchical( $tax_name ) ) {
- $tax_meta_box_id = 'tagsdiv-' . $tax_name;
- } else {
- $tax_meta_box_id = $tax_name . 'div';
- }
-
- add_meta_box( $tax_meta_box_id, $label, $taxonomy->meta_box_cb, $screen, 'side', 'core', array( 'taxonomy' => $tax_name ) );
- }
-
- 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', $screen, 'side', 'core' );
- }
-
- if ( $thumbnail_support && current_user_can( 'upload_files' ) ) {
- add_meta_box( 'postimagediv', esc_html( $post_type_object->labels->featured_image ), 'post_thumbnail_meta_box', $screen, 'side', 'low' );
- }
-
- if ( post_type_supports( $post_type, 'excerpt' ) ) {
- add_meta_box( 'postexcerpt', __( 'Excerpt', 'gutenberg' ), 'post_excerpt_meta_box', $screen, 'normal', 'core' );
- }
-
- if ( post_type_supports( $post_type, 'trackbacks' ) ) {
- add_meta_box( 'trackbacksdiv', __( 'Send Trackbacks', 'gutenberg' ), 'post_trackback_meta_box', $screen, 'normal', 'core' );
- }
-
- if ( post_type_supports( $post_type, 'custom-fields' ) ) {
- add_meta_box( 'postcustom', __( 'Custom Fields', 'gutenberg' ), 'post_custom_meta_box', $screen, 'normal', 'core' );
- }
-
- /**
- * Fires in the middle of built-in meta box registration.
- *
- * @since 2.1.0
- * @deprecated 3.7.0 Use 'add_meta_boxes' instead.
- *
- * @param WP_Post $post Post object.
- */
- 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', 'gutenberg' ), 'post_comment_status_meta_box', $screen, 'normal', 'core' );
- }
-
- $stati = get_post_stati( array( 'public' => true ) );
- if ( empty( $stati ) ) {
- $stati = array( 'publish' );
- }
- $stati[] = 'private';
-
- 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', 'gutenberg' ), 'post_comment_meta_box', $screen, 'normal', 'core' );
- }
- }
-
- if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) ) {
- add_meta_box( 'slugdiv', __( 'Slug', 'gutenberg' ), 'post_slug_meta_box', $screen, 'normal', 'core' );
- }
-
- if ( post_type_supports( $post_type, 'author' ) && current_user_can( $post_type_object->cap->edit_others_posts ) ) {
- add_meta_box( 'authordiv', __( 'Author', 'gutenberg' ), 'post_author_meta_box', $screen, 'normal', 'core' );
- }
-
- // Run the hooks for adding meta boxes for a specific post type.
- do_action( 'add_meta_boxes', $post_type, $post );
- do_action( "add_meta_boxes_{$post_type}", $post );
-
- // Set up meta box locations.
- $locations = array( 'normal', 'advanced', 'side' );
-
- // Foreach location run the hooks meta boxes are potentially registered on.
- foreach ( $locations as $location ) {
- do_action(
- 'do_meta_boxes',
- $screen,
- $location,
- $post
- );
- }
- do_action( 'edit_form_advanced', $post );
-
- // Copy meta box state.
- $_meta_boxes_copy = $wp_meta_boxes;
-
- /**
- * Documented in lib/meta-box-partial-page.php
- *
- * @param array $wp_meta_boxes Global meta box state.
- */
- $_meta_boxes_copy = apply_filters( 'filter_gutenberg_meta_boxes', $_meta_boxes_copy );
-
- // Redirect to classic editor if a meta box is incompatible.
- foreach ( $locations as $location ) {
- if ( ! isset( $_meta_boxes_copy[ $post->post_type ][ $location ] ) ) {
- continue;
- }
- // Check if we have a meta box that has declared itself incompatible with the block editor.
- foreach ( $_meta_boxes_copy[ $post->post_type ][ $location ] as $boxes ) {
- foreach ( $boxes as $box ) {
- /*
- * If __block_editor_compatible_meta_box is declared as a false-y value,
- * the meta box is not compatible with the block editor.
- */
- if ( is_array( $box['args'] )
- && isset( $box['args']['__block_editor_compatible_meta_box'] )
- && ! $box['args']['__block_editor_compatible_meta_box'] ) {
- $incompatible_meta_box = true;
- ?>
-
- meta_boxes = array(
- 'post' => array(
- 'normal' => array(
- 'core' => array(
- 'revisionsdiv' => array(
- 'id' => 'revisionsdiv',
- 'title' => 'Revisions',
- 'callback' => 'post_revisions_meta_box',
- 'args' => null,
- ),
- 'postexcerpt' => array(
- 'id' => 'postexcerpt',
- 'title' => 'Excerpt',
- 'callback' => 'post_excerpt_meta_box',
- 'args' => null,
- ),
- 'trackbacksdiv' => array(
- 'id' => 'trackbacksdiv',
- 'title' => 'Send Trackbacks',
- 'callback' => 'post_trackback_meta_box',
- 'args' => null,
- ),
- 'postcustom' => array(
- 'id' => 'postcustom',
- 'title' => 'Custom Fields',
- 'callback' => 'post_custom_meta_box',
- 'args' => null,
- ),
- 'commentstatusdiv' => array(
- 'id' => 'commentstatusdiv',
- 'title' => 'Discussion',
- 'callback' => 'post_comment_status_meta_box',
- 'args' => null,
- ),
- 'commentsdiv' => array(
- 'id' => 'commentsdiv',
- 'title' => 'Comments',
- 'callback' => 'post_comment_meta_box',
- 'args' => null,
- ),
- 'slugdiv' => array(
- 'id' => 'slugdiv',
- 'title' => 'Slug',
- 'callback' => 'post_slug_meta_box',
- 'args' => null,
- ),
- 'authordiv' => array(
- 'id' => 'authordiv',
- 'title' => 'Author',
- 'callback' => 'post_author_meta_box',
- 'args' => null,
- ),
- ),
- 'low' => array(),
- 'high' => array(),
- ),
- 'side' => array(
- 'core' => array(
- 'submitdiv' => array(
- 'id' => 'submitdiv',
- 'title' => 'Submit',
- 'callback' => 'post_submit_meta_box',
- 'args' => null,
- ),
- 'formatdiv' => array(
- 'id' => 'formatdiv',
- 'title' => 'Format',
- 'callback' => 'post_format_meta_box',
- 'args' => null,
- ),
- 'categorydiv' => array(
- 'id' => 'categorydiv',
- 'title' => 'Categories',
- 'callback' => 'post_categories_meta_box',
- 'args' => null,
- ),
- 'tagsdiv-post_tag' => array(
- 'id' => 'tagsdiv-post_tag',
- 'title' => 'Tags',
- 'callback' => 'post_tags_meta_box',
- 'args' => null,
- ),
- 'postimagediv' => array(
- 'id' => 'postimagediv',
- 'title' => 'Featured Image',
- 'callback' => 'post_image_meta_box',
- 'args' => null,
- ),
- ),
- 'low' => array(),
- ),
- ),
- );
- }
-
- /**
- * Test filtering of meta box data.
- */
- public function test_gutenberg_filter_meta_boxes() {
- $meta_boxes = $this->meta_boxes;
- // Add in a meta box.
- $meta_boxes['post']['normal']['high']['some-meta-box'] = array( 'meta-box-stuff' );
-
- $expected_meta_boxes = $this->meta_boxes;
- // We expect to remove only core meta boxes.
- $expected_meta_boxes['post']['normal']['core'] = array();
- $expected_meta_boxes['post']['side']['core'] = array();
- $expected_meta_boxes['post']['normal']['high']['some-meta-box'] = array( 'meta-box-stuff' );
-
- $actual = gutenberg_filter_meta_boxes( $meta_boxes );
- $expected = $expected_meta_boxes;
-
- $this->assertEquals( $expected, $actual );
- }
-
- /**
- * Test filtering back compat meta boxes
- */
- public function test_gutenberg_filter_back_compat_meta_boxes() {
- $meta_boxes = $this->meta_boxes;
-
- // Add in a back compat meta box.
- $meta_boxes['post']['normal']['high']['some-meta-box'] = array(
- 'id' => 'some-meta-box',
- 'title' => 'Some Meta Box',
- 'callback' => 'some_meta_box',
- 'args' => array(
- '__back_compat_meta_box' => true,
- ),
- );
-
- // Add in a normal meta box.
- $meta_boxes['post']['normal']['high']['some-other-meta-box'] = array( 'other-meta-box-stuff' );
-
- $expected_meta_boxes = $this->meta_boxes;
- // We expect to remove only core meta boxes.
- $expected_meta_boxes['post']['normal']['core'] = array();
- $expected_meta_boxes['post']['side']['core'] = array();
- $expected_meta_boxes['post']['normal']['high']['some-other-meta-box'] = array( 'other-meta-box-stuff' );
-
- $actual = gutenberg_filter_meta_boxes( $meta_boxes );
- $expected = $expected_meta_boxes;
-
- $this->assertEquals( $expected, $actual );
- }
-
- /**
- * Test filtering of meta box data with taxonomy meta boxes.
- *
- * By default Gutenberg will provide a much enhanced JavaScript alternative
- * to the meta boxes using the standard category and tags meta box callbacks.
- */
- public function test_gutenberg_filter_meta_boxes_for_taxonomies() {
- $meta_boxes = $this->meta_boxes;
- // Add in a meta box.
- $meta_boxes['post']['normal']['high']['my-cool-tax'] = array( 'callback' => 'post_tags_meta_box' );
- $meta_boxes['post']['normal']['high']['my-cool-hierarchical-tax'] = array( 'callback' => 'post_categories_meta_box' );
-
- $expected_meta_boxes = $this->meta_boxes;
- // We expect to remove only core meta boxes.
- $expected_meta_boxes['post']['normal']['core'] = array();
- $expected_meta_boxes['post']['side']['core'] = array();
- // We expect the high location to be empty even though we have registered meta boxes.
- $expected_meta_boxes['post']['normal']['high'] = array();
-
- $actual = gutenberg_filter_meta_boxes( $meta_boxes );
- $expected = $expected_meta_boxes;
-
- $this->assertEquals( $expected, $actual );
- }
-
- /**
- * Test that a removed meta box remains empty after gutenberg_intercept_meta_box_render() fires.
- */
- public function test_gutenberg_intercept_meta_box_render_skips_empty_boxes() {
- global $wp_meta_boxes;
-
- add_meta_box( 'test-intercept-box', 'Test Intercept box', '__return_empty_string', 'post', 'side', 'default' );
- remove_meta_box( 'test-intercept-box', 'post', 'side' );
-
- gutenberg_intercept_meta_box_render();
-
- $this->assertFalse( $wp_meta_boxes['post']['side']['default']['test-intercept-box'] );
- }
-}