Changeset 50983 for trunk/src/wp-includes/block-editor.php
- Timestamp:
- 05/24/2021 09:20:31 PM (5 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/block-editor.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-editor.php
r50973 r50983 59 59 * 60 60 * @since 5.0.0 61 * 62 * @param string|WP_Post $editor_name_or_post The name of the editor (e.g. 'post-editor') 63 * or the post object. 61 * @since 5.8.0 It is possible to pass the block editor context as param. 62 * 63 * @param WP_Post|WP_Block_Editor_Context $post_or_block_editor_context The current post object or 64 * the block editor context. 64 65 * 65 66 * @return array[] Array of categories for block types. 66 67 */ 67 function get_block_categories( $editor_name_or_post ) { 68 // Assume the post editor when the WP_Post object passed. 69 $editor_name = is_object( $editor_name_or_post ) ? 'post-editor' : $editor_name_or_post; 70 $block_categories = get_default_block_categories(); 68 function get_block_categories( $post_or_block_editor_context ) { 69 $block_categories = get_default_block_categories(); 70 $block_editor_context = $post_or_block_editor_context instanceof WP_Post ? 71 new WP_Block_Editor_Context( 72 array( 73 'post' => $post_or_block_editor_context, 74 ) 75 ) : $post_or_block_editor_context; 71 76 72 77 /** … … 75 80 * @since 5.8.0 76 81 * 77 * @param array[] $block_categoriesArray of categories for block types.78 * @param string $editor_name The name of the editor, e.g. 'post-editor'.82 * @param array[] $block_categories Array of categories for block types. 83 * @param WP_Block_Editor_Context $block_editor_context The current block editor context. 79 84 */ 80 $block_categories = apply_filters( 'block_categories_all', $block_categories, $ editor_name);81 if ( 'post-editor' === $editor_name) {82 $post = is_object( $editor_name_or_post ) ? $editor_name_or_post : get_post();85 $block_categories = apply_filters( 'block_categories_all', $block_categories, $block_editor_context ); 86 if ( ! empty( $block_editor_context->post ) ) { 87 $post = $block_editor_context->post; 83 88 84 89 /** … … 102 107 * @since 5.8.0 103 108 * 104 * @param string $editor_name The name of the editor (e.g. 'post-editor').109 * @param WP_Block_Editor_Context $block_editor_context The current block editor context. 105 110 * 106 111 * @return bool|array Array of block type slugs, or boolean to enable/disable all. 107 112 */ 108 function get_allowed_block_types( $ editor_name) {113 function get_allowed_block_types( $block_editor_context ) { 109 114 $allowed_block_types = true; 110 115 … … 116 121 * @since 5.8.0 117 122 * 118 * @param bool|array $allowed_block_typesArray of block type slugs, or119 * boolean to enable/disable all.120 * @param string $editor_name The name of the editor, e.g. 'post-editor'.123 * @param bool|array $allowed_block_types Array of block type slugs, or 124 * boolean to enable/disable all. 125 * @param WP_Block_Editor_Context $block_editor_context The current block editor context. 121 126 */ 122 $allowed_block_types = apply_filters( 'allowed_block_types_all', $allowed_block_types, $ editor_name);123 if ( 'post-editor' === $editor_name) {124 $post = get_post();127 $allowed_block_types = apply_filters( 'allowed_block_types_all', $allowed_block_types, $block_editor_context ); 128 if ( ! empty( $block_editor_context->post ) ) { 129 $post = $block_editor_context->post; 125 130 126 131 /** … … 225 230 226 231 /** 227 * Returns the contextualized block editor settings settings for a selected editor type.232 * Returns the contextualized block editor settings settings for a selected editor context. 228 233 * 229 234 * @since 5.8.0 230 235 * 231 * @param string $editor_name The name of the editor (e.g. 'post-editor').232 * @param array $custom_settings Optional custom settings to use with the editor type.236 * @param array $custom_settings Custom settings to use with the given editor type. 237 * @param WP_Block_Editor_Context $block_editor_context The current block editor context. 233 238 * 234 239 * @return array The contextualized block editor settings. 235 240 */ 236 function get_block_editor_settings( $editor_name, $custom_settings = array()) {241 function get_block_editor_settings( array $custom_settings, $block_editor_context ) { 237 242 $editor_settings = array_merge( 238 243 get_default_block_editor_settings(), 239 244 array( 240 'allowedBlockTypes' => get_allowed_block_types( $ editor_name),241 'blockCategories' => get_block_categories( $ editor_name),245 'allowedBlockTypes' => get_allowed_block_types( $block_editor_context ), 246 'blockCategories' => get_block_categories( $block_editor_context ), 242 247 ), 243 248 $custom_settings … … 302 307 * @since 5.8.0 303 308 * 304 * @param array $editor_settingsDefault editor settings.305 * @param string $editor_name The name of the editor, e.g. 'post-editor'.309 * @param array $editor_settings Default editor settings. 310 * @param WP_Block_Editor_Context $block_editor_context The current block editor context. 306 311 */ 307 $editor_settings = apply_filters( 'block_editor_settings_all', $editor_settings, $ editor_name);308 if ( 'post-editor' === $editor_name) {309 $post = get_post();312 $editor_settings = apply_filters( 'block_editor_settings_all', $editor_settings, $block_editor_context ); 313 if ( ! empty( $block_editor_context->post ) ) { 314 $post = $block_editor_context->post; 310 315 311 316 /**
Note: See TracChangeset
for help on using the changeset viewer.