diff --git a/docs/designers-developers/developers/backward-compatibility/deprecations.md b/docs/designers-developers/developers/backward-compatibility/deprecations.md
index 966b33d77cafe2..2a0bd05cd0dd2f 100644
--- a/docs/designers-developers/developers/backward-compatibility/deprecations.md
+++ b/docs/designers-developers/developers/backward-compatibility/deprecations.md
@@ -67,6 +67,13 @@ The Gutenberg project's deprecation policy is intended to support backward compa
- `window._wpLoadGutenbergEditor` has been removed. Use `window._wpLoadBlockEditor` instead. Note: This is a private API, not intended for public use. It may be removed in the future.
- The PHP function `gutenberg_get_script_polyfill` has been removed. Use [`wp_get_script_polyfill`](https://developer.wordpress.org/reference/functions/wp_get_script_polyfill/) instead.
- The PHP function `gutenberg_add_admin_body_class` has been removed. Use the `.block-editor-page` class selector in your stylesheets if you need to scope styles to the block editor screen.
+- The PHP function `gutenberg_init` has been removed.
+- The PHP function `is_gutenberg_page` has been removed. Use [`WP_Screen::is_block_editor`](https://developer.wordpress.org/reference/classes/wp_screen/is_block_editor/) instead.
+- The PHP function `the_gutenberg_project` has been removed.
+- The PHP function `gutenberg_default_post_format_template` has been removed.
+- The PHP function `gutenberg_get_available_image_sizes` has been removed.
+- The PHP function `gutenberg_get_autosave_newer_than_post_save` has been removed.
+- The PHP function `gutenberg_default_post_format_template` has been removed.
## 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 db7f70d1cab95d..909d2952f1a6ca 100644
--- a/gutenberg.php
+++ b/gutenberg.php
@@ -21,32 +21,11 @@
* The main entry point for the Gutenberg editor. Renders the editor on the
* wp-admin page for the plugin.
*
- * The gutenberg and gutenberg__editor classNames are left for backward compatibility.
- *
* @since 0.1.0
+ * @deprecated 5.2.0
*/
function the_gutenberg_project() {
- global $post_type_object;
- ?>
-
-
-
labels->edit_item ); ?>
-
-
-
-
-
- base !== 'post' ) {
- return false;
- }
-
- if ( ! use_block_editor_for_post( $post ) ) {
- return false;
- }
-
- return true;
+ return get_current_screen()->is_block_editor();
}
/**
@@ -182,8 +142,6 @@ function gutenberg_pre_init() {
}
require_once dirname( __FILE__ ) . '/lib/load.php';
-
- add_filter( 'replace_editor', 'gutenberg_init', 10, 2 );
}
/**
@@ -191,46 +149,12 @@ function gutenberg_pre_init() {
*
* Load API functions, register scripts and actions, etc.
*
- * @param bool $return Whether to replace the editor. Used in the `replace_editor` filter.
- * @param object $post The post to edit or an auto-draft.
- * @return bool Whether Gutenberg was initialized.
+ * @deprecated 5.2.0
+ *
+ * @return bool Whether Gutenberg was initialized.
*/
-function gutenberg_init( $return, $post ) {
- if ( true === $return && current_filter() === 'replace_editor' ) {
- return $return;
- }
-
- if ( ! is_gutenberg_page() ) {
- return false;
- }
+function gutenberg_init() {
+ _deprecated_function( __FUNCTION__, '5.2.0' );
- // Instruct WordPress that this is the block editor. Without this, a call
- // to `is_block_editor()` would yield `false` while editing a post with
- // Gutenberg.
- //
- // [TODO]: This is temporary so long as Gutenberg is implemented to use
- // `replace_editor`, rather than allow `edit-form-blocks.php` from core to
- // take effect, where this would otherwise be assigned.
- get_current_screen()->is_block_editor( true );
-
- add_action( 'admin_enqueue_scripts', 'gutenberg_editor_scripts_and_styles' );
- add_filter( 'screen_options_show_screen', '__return_false' );
-
- /*
- * Remove the emoji script as it is incompatible with both React and any
- * contenteditable fields.
- */
- remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
-
- /*
- * Ensure meta box functions are available to third-party code;
- * includes/meta-boxes is typically loaded from edit-form-advanced.php.
- */
- require_once ABSPATH . 'wp-admin/includes/meta-boxes.php';
- register_and_do_post_meta_boxes( $post );
-
- require_once ABSPATH . 'wp-admin/admin-header.php';
- the_gutenberg_project();
-
- return true;
+ return get_current_screen()->is_block_editor();
}
diff --git a/lib/client-assets.php b/lib/client-assets.php
index dc9fff22a83868..c416bb2164f4d6 100644
--- a/lib/client-assets.php
+++ b/lib/client-assets.php
@@ -200,27 +200,6 @@ function gutenberg_register_scripts_and_styles() {
// Editor Styles.
// This empty stylesheet is defined to ensure backward compatibility.
gutenberg_override_style( 'wp-blocks', false );
- $fonts_url = '';
-
- /*
- * Translators: Use this to specify the proper Google Font name and variants
- * to load that is supported by your language. Do not translate.
- * Set to 'off' to disable loading.
- */
- $font_family = _x( 'Noto Serif:400,400i,700,700i', 'Google Font Name and Variants', 'gutenberg' );
- if ( 'off' !== $font_family ) {
- $query_args = array(
- 'family' => urlencode( $font_family ),
- );
- $fonts_url = esc_url_raw( add_query_arg( $query_args, 'https://fonts.googleapis.com/css' ) );
- }
-
- gutenberg_override_style(
- 'wp-editor-font',
- $fonts_url,
- array(),
- null
- );
gutenberg_override_style(
'wp-editor',
@@ -439,67 +418,29 @@ function gutenberg_register_vendor_script( $handle, $src, $deps = array() ) {
* Assigns a default editor template with a default block by post format, if
* not otherwise assigned for a new post of type "post".
*
- * @param array $settings Default editor settings.
- * @param WP_Post $post Post being edited.
+ * @deprecated 5.2.0
+ *
+ * @param array $settings Default editor settings.
*
* @return array Filtered block editor settings.
*/
-function gutenberg_default_post_format_template( $settings, $post ) {
- // Only assign template for new posts without explicitly assigned template.
- $is_new_post = 'auto-draft' === $post->post_status;
- if ( $is_new_post && ! isset( $settings['template'] ) && 'post' === $post->post_type ) {
- switch ( get_post_format() ) {
- case 'audio':
- $default_block_name = 'core/audio';
- break;
- case 'gallery':
- $default_block_name = 'core/gallery';
- break;
- case 'image':
- $default_block_name = 'core/image';
- break;
- case 'quote':
- $default_block_name = 'core/quote';
- break;
- case 'video':
- $default_block_name = 'core/video';
- break;
- }
-
- if ( isset( $default_block_name ) ) {
- $settings['template'] = array( array( $default_block_name ) );
- }
- }
+function gutenberg_default_post_format_template( $settings ) {
+ _deprecated_function( __FUNCTION__, '5.2.0' );
return $settings;
}
-add_filter( 'block_editor_settings', 'gutenberg_default_post_format_template', 10, 2 );
/**
* Retrieve a stored autosave that is newer than the post save.
*
* Deletes autosaves that are older than the post save.
*
- * @param WP_Post $post Post object.
+ * @deprecated 5.2.0
+ *
* @return WP_Post|boolean The post autosave. False if none found.
*/
-function gutenberg_get_autosave_newer_than_post_save( $post ) {
- // Add autosave data if it is newer and changed.
- $autosave = wp_get_post_autosave( $post->ID );
-
- if ( ! $autosave ) {
- return false;
- }
-
- // Check if the autosave is newer than the current post.
- if (
- mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false )
- ) {
- return $autosave;
- }
-
- // If the autosave isn't newer, remove it.
- wp_delete_post_revision( $autosave->ID );
+function gutenberg_get_autosave_newer_than_post_save() {
+ _deprecated_function( __FUNCTION__, '5.2.0' );
return false;
}
@@ -519,28 +460,14 @@ function gutenberg_load_locale_data() {
/**
* Retrieve The available image sizes for a post
*
+ * @deprecated 5.2.0
+ *
* @return array
*/
function gutenberg_get_available_image_sizes() {
- $size_names = apply_filters(
- 'image_size_names_choose',
- array(
- 'thumbnail' => __( 'Thumbnail', 'gutenberg' ),
- 'medium' => __( 'Medium', 'gutenberg' ),
- 'large' => __( 'Large', 'gutenberg' ),
- 'full' => __( 'Full Size', 'gutenberg' ),
- )
- );
-
- $all_sizes = array();
- foreach ( $size_names as $size_slug => $size_name ) {
- $all_sizes[] = array(
- 'slug' => $size_slug,
- 'name' => $size_name,
- );
- }
+ _deprecated_function( __FUNCTION__, '5.2.0' );
- return $all_sizes;
+ return array();
}
/**
@@ -611,369 +538,21 @@ function gutenberg_extend_block_editor_styles( $settings ) {
* the Gutenberg editor.
*
* @since 0.1.0
- *
- * @param string $hook Screen name.
*/
-function gutenberg_editor_scripts_and_styles( $hook ) {
- global $wp_meta_boxes;
-
- // Enqueue heartbeat separately as an "optional" dependency of the editor.
- // Heartbeat is used for automatic nonce refreshing, but some hosts choose
- // to disable it outright.
- wp_enqueue_script( 'heartbeat' );
-
- wp_enqueue_script( 'wp-edit-post' );
- wp_enqueue_script( 'wp-format-library' );
- wp_enqueue_style( 'wp-format-library' );
-
- global $post;
-
- // Set initial title to empty string for auto draft for duration of edit.
- // Otherwise, title defaults to and displays as "Auto Draft".
- $is_new_post = 'auto-draft' === $post->post_status;
-
- // Set the post type name.
- $post_type = get_post_type( $post );
- $post_type_object = get_post_type_object( $post_type );
- $rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
-
- $preload_paths = array(
- '/',
- '/wp/v2/types?context=edit',
- '/wp/v2/taxonomies?per_page=-1&context=edit',
- '/wp/v2/themes?status=active',
- sprintf( '/wp/v2/%s/%s?context=edit', $rest_base, $post->ID ),
- sprintf( '/wp/v2/types/%s?context=edit', $post_type ),
- sprintf( '/wp/v2/users/me?post_type=%s&context=edit', $post_type ),
- array( '/wp/v2/media', 'OPTIONS' ),
- array( '/wp/v2/blocks', 'OPTIONS' ),
- );
-
- /**
- * Preload common data by specifying an array of REST API paths that will be preloaded.
- *
- * Filters the array of paths that will be preloaded.
- *
- * @param array $preload_paths Array of paths to preload
- * @param object $post The post resource data.
- */
- $preload_paths = apply_filters( 'block_editor_preload_paths', $preload_paths, $post );
-
- // Ensure the global $post remains the same after
- // API data is preloaded. Because API preloading
- // can call the_content and other filters, callbacks
- // can unexpectedly modify $post resulting in issues
- // like https://github.com/WordPress/gutenberg/issues/7468.
- $backup_global_post = $post;
-
- $preload_data = array_reduce(
- $preload_paths,
- 'rest_preload_api_request',
- array()
- );
-
- // Restore the global $post as it was before API preloading.
- $post = $backup_global_post;
-
- wp_add_inline_script(
- 'wp-api-fetch',
- sprintf( 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );', wp_json_encode( $preload_data ) ),
- 'after'
- );
-
- wp_add_inline_script(
- 'wp-blocks',
- sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $post ) ) ),
- 'after'
- );
-
- // Assign initial edits, if applicable. These are not initially assigned
- // to the persisted post, but should be included in its save payload.
- if ( $is_new_post ) {
- // Override "(Auto Draft)" new post default title with empty string,
- // or filtered value.
- $initial_edits = array(
- 'title' => $post->post_title,
- 'content' => $post->post_content,
- 'excerpt' => $post->post_excerpt,
- );
- } else {
- $initial_edits = null;
- }
-
- gutenberg_load_locale_data();
-
- // Preload server-registered block schemas.
- wp_add_inline_script(
- 'wp-blocks',
- 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . json_encode( get_block_editor_server_block_settings() ) . ');'
- );
-
- // Get admin url for handling meta boxes.
- $meta_box_url = admin_url( 'post.php' );
- $meta_box_url = add_query_arg(
- array(
- 'post' => $post->ID,
- 'action' => 'edit',
- 'meta-box-loader' => true,
- '_wpnonce' => wp_create_nonce( 'meta-box-loader' ),
- ),
- $meta_box_url
- );
- wp_localize_script( 'wp-editor', '_wpMetaBoxUrl', $meta_box_url );
-
- // Initialize the editor.
- $gutenberg_theme_support = get_theme_support( 'gutenberg' );
- $align_wide = get_theme_support( 'align-wide' );
- $color_palette = current( (array) get_theme_support( 'editor-color-palette' ) );
- $font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) );
-
- if ( ! empty( $gutenberg_theme_support ) ) {
- wp_enqueue_script( 'wp-deprecated' );
- wp_add_inline_script( 'wp-deprecated', 'wp.deprecated( "`gutenberg` theme support", { plugin: "Gutenberg", version: "5.2", alternative: "`align-wide` theme support" } );' );
- }
-
- /**
- * Filters the allowed block types for the editor, defaulting to true (all
- * block types supported).
- *
- * @param bool|array $allowed_block_types Array of block type slugs, or
- * boolean to enable/disable all.
- * @param object $post The post resource data.
- */
- $allowed_block_types = apply_filters( 'allowed_block_types', true, $post );
-
- // Get all available templates for the post/page attributes meta-box.
- // The "Default template" array element should only be added if the array is
- // not empty so we do not trigger the template select element without any options
- // besides the default value.
- $available_templates = wp_get_theme()->get_page_templates( get_post( $post->ID ) );
- $available_templates = ! empty( $available_templates ) ? array_merge(
- array(
- '' => apply_filters( 'default_page_template_title', __( 'Default template', 'gutenberg' ), 'rest-api' ),
- ),
- $available_templates
- ) : $available_templates;
-
- // Media settings.
- $max_upload_size = wp_max_upload_size();
- if ( ! $max_upload_size ) {
- $max_upload_size = 0;
- }
-
- // Editor Styles.
- global $editor_styles;
- $styles = array(
- array(
- 'css' => file_get_contents(
- ABSPATH . WPINC . '/css/dist/editor/editor-styles.css'
- ),
- ),
- );
-
- /* Translators: Use this to specify the CSS font family for the default font */
- $locale_font_family = esc_html_x( 'Noto Serif', 'CSS Font Family for Editor Font', 'gutenberg' );
- $styles[] = array(
- 'css' => "body { font-family: '$locale_font_family' }",
- );
-
- if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) {
- foreach ( $editor_styles as $style ) {
- if ( filter_var( $style, FILTER_VALIDATE_URL ) ) {
- $styles[] = array(
- 'css' => file_get_contents( $style ),
- );
- } else {
- $file = get_theme_file_path( $style );
- if ( file_exists( $file ) ) {
- $styles[] = array(
- 'css' => file_get_contents( $file ),
- 'baseURL' => get_theme_file_uri( $style ),
- );
- }
- }
- }
- }
-
- // Lock settings.
- $user_id = wp_check_post_lock( $post->ID );
- if ( $user_id ) {
- /**
- * Filters whether to show the post locked dialog.
- *
- * Returning a falsey value to the filter will short-circuit displaying the dialog.
- *
- * @since 3.6.0
- *
- * @param bool $display Whether to display the dialog. Default true.
- * @param WP_Post $post Post object.
- * @param WP_User|bool $user The user id currently editing the post.
- */
- if ( apply_filters( 'show_post_locked_dialog', true, $post, $user_id ) ) {
- $locked = true;
- }
-
- $user_details = null;
- if ( $locked ) {
- $user = get_userdata( $user_id );
- $user_details = array(
- 'name' => $user->display_name,
- );
- $avatar = get_avatar( $user_id, 64 );
- if ( $avatar ) {
- if ( preg_match( "|src='([^']+)'|", $avatar, $matches ) ) {
- $user_details['avatar'] = $matches[1];
- }
- }
- }
-
- $lock_details = array(
- 'isLocked' => $locked,
- 'user' => $user_details,
- );
- } else {
-
- // Lock the post.
- $active_post_lock = wp_set_post_lock( $post->ID );
- $lock_details = array(
- 'isLocked' => false,
- 'activePostLock' => esc_attr( implode( ':', $active_post_lock ) ),
- );
- }
-
- $editor_settings = array(
- 'alignWide' => $align_wide || ! empty( $gutenberg_theme_support[0]['wide-images'] ), // Backcompat. Use `align-wide` outside of `gutenberg` array.
- 'availableTemplates' => $available_templates,
- 'allowedBlockTypes' => $allowed_block_types,
- 'disableCustomColors' => get_theme_support( 'disable-custom-colors' ),
- 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
- 'disablePostFormats' => ! current_theme_supports( 'post-formats' ),
- 'titlePlaceholder' => apply_filters( 'enter_title_here', __( 'Add title', 'gutenberg' ), $post ),
- 'bodyPlaceholder' => apply_filters( 'write_your_story', __( 'Start writing or type / to choose a block', 'gutenberg' ), $post ),
- 'isRTL' => is_rtl(),
- 'autosaveInterval' => 10,
- 'maxUploadFileSize' => $max_upload_size,
- 'allowedMimeTypes' => get_allowed_mime_types(),
- 'styles' => $styles,
- 'imageSizes' => gutenberg_get_available_image_sizes(),
- 'richEditingEnabled' => user_can_richedit(),
-
- // Ideally, we'd remove this and rely on a REST API endpoint.
- 'postLock' => $lock_details,
- 'postLockUtils' => array(
- 'nonce' => wp_create_nonce( 'lock-post_' . $post->ID ),
- 'unlockNonce' => wp_create_nonce( 'update-post_' . $post->ID ),
- 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
- ),
-
- // 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.
- 'enableCustomFields' => (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ),
- );
-
- $post_autosave = gutenberg_get_autosave_newer_than_post_save( $post );
- if ( $post_autosave ) {
- $editor_settings['autosave'] = array(
- 'editLink' => get_edit_post_link( $post_autosave->ID ),
- );
- }
-
- if ( false !== $color_palette ) {
- $editor_settings['colors'] = $color_palette;
- }
-
- if ( false !== $font_sizes ) {
- $editor_settings['fontSizes'] = $font_sizes;
- }
-
- if ( ! empty( $post_type_object->template ) ) {
- $editor_settings['template'] = $post_type_object->template;
- $editor_settings['templateLock'] = ! empty( $post_type_object->template_lock ) ? $post_type_object->template_lock : false;
- }
-
- $current_screen = get_current_screen();
- $core_meta_boxes = array();
-
- // Make sure the current screen is set as well as the normal core metaboxes.
- if ( isset( $current_screen->id ) && isset( $wp_meta_boxes[ $current_screen->id ]['normal']['core'] ) ) {
- $core_meta_boxes = $wp_meta_boxes[ $current_screen->id ]['normal']['core'];
- }
-
- // Check if the Custom Fields meta box has been removed at some point.
- if ( ! isset( $core_meta_boxes['postcustom'] ) || ! $core_meta_boxes['postcustom'] ) {
- unset( $editor_settings['enableCustomFields'] );
+function gutenberg_editor_scripts_and_styles() {
+ if ( ! get_current_screen()->is_block_editor() ) {
+ return;
}
- /**
- * Filters the settings to pass to the block editor.
- *
- * @since 3.7.0
- *
- * @param array $editor_settings Default editor settings.
- * @param WP_Post $post Post being edited.
- */
- $editor_settings = apply_filters( 'block_editor_settings', $editor_settings, $post );
-
- $init_script = <<post_type,
- $post->ID,
- wp_json_encode( $editor_settings ),
- wp_json_encode( $initial_edits )
- );
- wp_add_inline_script( 'wp-edit-post', $script );
-
- /**
- * Scripts
- */
- wp_enqueue_media(
- array(
- 'post' => $post->ID,
- )
- );
- wp_tinymce_inline_scripts();
- wp_enqueue_editor();
-
- /**
- * Styles
- */
- wp_enqueue_style( 'wp-edit-post' );
-
- /**
- * Fires after block assets have been enqueued for the editing interface.
- *
- * Call `add_action` on any hook before 'admin_enqueue_scripts'.
+ /*
+ * TODO: This should become unnecessary once unblocked from using core's
+ * facilities for configuring (downloading) script translations.
*
- * In the function call you supply, simply use `wp_enqueue_script` and
- * `wp_enqueue_style` to add your functionality to the Gutenberg editor.
+ * See: https://github.com/WordPress/gutenberg/pull/12559 .
*
- * @since 0.4.0
+ * In other words, this function should be possible to deprecate/remove
+ * once the above pull request is merged.
*/
- do_action( 'enqueue_block_editor_assets' );
+ gutenberg_load_locale_data();
}
+add_action( 'admin_enqueue_scripts', 'gutenberg_editor_scripts_and_styles' );