From cfa7f89ba0fbcf3ec89c92db2d5352a561ced3ee Mon Sep 17 00:00:00 2001 From: gziolo Date: Mon, 24 May 2021 21:21:57 +0000 Subject: [PATCH] Editor: Use the block editor context in filters that used the editor name Follow-up for [50956]. Props azaozz, chrisvanpatten, timothyblynjacobs, youknowriad. Fixes #52920. Built from https://develop.svn.wordpress.org/trunk@50983 git-svn-id: http://core.svn.wordpress.org/trunk@50592 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-form-blocks.php | 3 +- wp-includes/block-editor.php | 65 +++++++++++++++++++---------------- wp-includes/version.php | 2 +- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/wp-admin/edit-form-blocks.php b/wp-admin/edit-form-blocks.php index 0e367eb96b..c2fa7d0019 100644 --- a/wp-admin/edit-form-blocks.php +++ b/wp-admin/edit-form-blocks.php @@ -23,7 +23,6 @@ if ( ! defined( 'ABSPATH' ) ) { */ global $post_type, $post_type_object, $post, $title, $editor_styles, $wp_meta_boxes; -$editor_name = 'post-editor'; $block_editor_context = new WP_Block_Editor_Context( array( 'post' => $post ) ); // Flag that we're loading the block editor. @@ -280,7 +279,7 @@ if ( ! isset( $core_meta_boxes['postcustom'] ) || ! $core_meta_boxes['postcustom unset( $editor_settings['enableCustomFields'] ); } -$editor_settings = get_block_editor_settings( $editor_name, $editor_settings ); +$editor_settings = get_block_editor_settings( $editor_settings, $block_editor_context ); $init_script = << $post_or_block_editor_context, + ) + ) : $post_or_block_editor_context; /** * Filters the default array of categories for block types. * * @since 5.8.0 * - * @param array[] $block_categories Array of categories for block types. - * @param string $editor_name The name of the editor, e.g. 'post-editor'. + * @param array[] $block_categories Array of categories for block types. + * @param WP_Block_Editor_Context $block_editor_context The current block editor context. */ - $block_categories = apply_filters( 'block_categories_all', $block_categories, $editor_name ); - if ( 'post-editor' === $editor_name ) { - $post = is_object( $editor_name_or_post ) ? $editor_name_or_post : get_post(); + $block_categories = apply_filters( 'block_categories_all', $block_categories, $block_editor_context ); + if ( ! empty( $block_editor_context->post ) ) { + $post = $block_editor_context->post; /** * Filters the default array of categories for block types. @@ -101,11 +106,11 @@ function get_block_categories( $editor_name_or_post ) { * * @since 5.8.0 * - * @param string $editor_name The name of the editor (e.g. 'post-editor'). + * @param WP_Block_Editor_Context $block_editor_context The current block editor context. * * @return bool|array Array of block type slugs, or boolean to enable/disable all. */ -function get_allowed_block_types( $editor_name ) { +function get_allowed_block_types( $block_editor_context ) { $allowed_block_types = true; /** @@ -115,13 +120,13 @@ function get_allowed_block_types( $editor_name ) { * * @since 5.8.0 * - * @param bool|array $allowed_block_types Array of block type slugs, or - * boolean to enable/disable all. - * @param string $editor_name The name of the editor, e.g. 'post-editor'. + * @param bool|array $allowed_block_types Array of block type slugs, or + * boolean to enable/disable all. + * @param WP_Block_Editor_Context $block_editor_context The current block editor context. */ - $allowed_block_types = apply_filters( 'allowed_block_types_all', $allowed_block_types, $editor_name ); - if ( 'post-editor' === $editor_name ) { - $post = get_post(); + $allowed_block_types = apply_filters( 'allowed_block_types_all', $allowed_block_types, $block_editor_context ); + if ( ! empty( $block_editor_context->post ) ) { + $post = $block_editor_context->post; /** * Filters the allowed block types for the editor, defaulting to true (all @@ -224,21 +229,21 @@ function get_default_block_editor_settings() { } /** - * Returns the contextualized block editor settings settings for a selected editor type. + * Returns the contextualized block editor settings settings for a selected editor context. * * @since 5.8.0 * - * @param string $editor_name The name of the editor (e.g. 'post-editor'). - * @param array $custom_settings Optional custom settings to use with the editor type. + * @param array $custom_settings Custom settings to use with the given editor type. + * @param WP_Block_Editor_Context $block_editor_context The current block editor context. * * @return array The contextualized block editor settings. */ -function get_block_editor_settings( $editor_name, $custom_settings = array() ) { +function get_block_editor_settings( array $custom_settings, $block_editor_context ) { $editor_settings = array_merge( get_default_block_editor_settings(), array( - 'allowedBlockTypes' => get_allowed_block_types( $editor_name ), - 'blockCategories' => get_block_categories( $editor_name ), + 'allowedBlockTypes' => get_allowed_block_types( $block_editor_context ), + 'blockCategories' => get_block_categories( $block_editor_context ), ), $custom_settings ); @@ -301,12 +306,12 @@ function get_block_editor_settings( $editor_name, $custom_settings = array() ) { * * @since 5.8.0 * - * @param array $editor_settings Default editor settings. - * @param string $editor_name The name of the editor, e.g. 'post-editor'. + * @param array $editor_settings Default editor settings. + * @param WP_Block_Editor_Context $block_editor_context The current block editor context. */ - $editor_settings = apply_filters( 'block_editor_settings_all', $editor_settings, $editor_name ); - if ( 'post-editor' === $editor_name ) { - $post = get_post(); + $editor_settings = apply_filters( 'block_editor_settings_all', $editor_settings, $block_editor_context ); + if ( ! empty( $block_editor_context->post ) ) { + $post = $block_editor_context->post; /** * Filters the settings to pass to the block editor. diff --git a/wp-includes/version.php b/wp-includes/version.php index 2bc597517f..1847a79b99 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-alpha-50982'; +$wp_version = '5.8-alpha-50983'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.