Changeset 50777
- Timestamp:
- 04/21/2021 09:30:40 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-editor.php
r50776 r50777 67 67 function get_block_categories( $editor_name_or_post ) { 68 68 // Assume the post editor when the WP_Post object passed. 69 $editor_name 70 $ default_categories = get_default_block_categories();69 $editor_name = is_object( $editor_name_or_post ) ? 'post-editor' : $editor_name_or_post; 70 $block_categories = get_default_block_categories(); 71 71 72 72 /** … … 75 75 * @since 5.8.0 76 76 * 77 * @param array[] $default_categories Array of categories for block types. 78 */ 79 $block_categories = apply_filters( "block_categories_{$editor_name}", $default_categories ); 77 * @param array[] $block_categories Array of categories for block types. 78 * @param string $editor_name The name of the editor, e.g. 'post-editor'. 79 */ 80 $block_categories = apply_filters( 'block_categories_all', $block_categories, $editor_name ); 80 81 if ( 'post-editor' === $editor_name ) { 81 82 $post = is_object( $editor_name_or_post ) ? $editor_name_or_post : get_post(); … … 90 91 * @param WP_Post $post Post being loaded. 91 92 */ 92 $block_categories = apply_filters_deprecated( 'block_categories', array( $block_categories, $post ), '5.8.0', "block_categories_{$editor_name}");93 $block_categories = apply_filters_deprecated( 'block_categories', array( $block_categories, $post ), '5.8.0', 'block_categories_all' ); 93 94 } 94 95 … … 109 110 110 111 /** 111 * Filters the allowed block types for the given editor, defaulting to true (all 112 * registered block types supported). 112 * Filters the allowed block types for all editor types, defaulting to `true` 113 * (all registered block types supported). 114 * 113 115 * 114 116 * @since 5.8.0 … … 116 118 * @param bool|array $allowed_block_types Array of block type slugs, or 117 119 * boolean to enable/disable all. 118 */ 119 $allowed_block_types = apply_filters( "allowed_block_types_{$editor_name}", $allowed_block_types ); 120 * @param string $editor_name The name of the editor, e.g. 'post-editor'. 121 */ 122 $allowed_block_types = apply_filters( 'allowed_block_types_all', $allowed_block_types, $editor_name ); 123 124 /** 125 * Filters the allowed block types for the given editor, defaulting to `true` 126 * (all registered block types supported). 127 * 128 * The dynamic portion of the hook name, `$editor_name`, refers to the name 129 * of the editor type, e.g. 'post-editor', 'site-editor', etc. 130 * 131 * @since 5.8.0 132 * 133 * @param bool|array $allowed_block_types Array of block type slugs, or 134 * boolean to enable/disable all. 135 * @param string $editor_name The name of the editor, e.g. 'post-editor'. 136 */ 137 $allowed_block_types = apply_filters( "allowed_block_types_{$editor_name}", $allowed_block_types, $editor_name ); 120 138 if ( 'post-editor' === $editor_name ) { 121 139 $post = get_post(); … … 132 150 * @param WP_Post $post The post resource data. 133 151 */ 134 $allowed_block_types = apply_filters_deprecated( 'allowed_block_types', array( $allowed_block_types, $post ), '5.8.0', "allowed_block_types_{$editor_name}");152 $allowed_block_types = apply_filters_deprecated( 'allowed_block_types', array( $allowed_block_types, $post ), '5.8.0', 'allowed_block_types_all' ); 135 153 } 136 154 … … 242 260 243 261 /** 262 * Filters the settings to pass to the block editor for all editor type. 263 * 264 * @since 5.8.0 265 * 266 * @param array $editor_settings Default editor settings. 267 * @param string $editor_name The name of the editor, e.g. 'post-editor'. 268 */ 269 $editor_settings = apply_filters( 'block_editor_settings_all', $editor_settings, $editor_name ); 270 271 /** 244 272 * Filters the settings to pass to the block editor for a given editor type. 245 273 * 246 * @since 5.8.0 247 * 248 * @param array $editor_settings Default editor settings. 249 */ 250 $editor_settings = apply_filters( "block_editor_settings_{$editor_name}", $editor_settings ); 274 * The dynamic portion of the hook name, `$editor_name`, refers to the name 275 * of the editor type, e.g. 'post-editor', 'site-editor', etc. 276 * 277 * @since 5.8.0 278 * 279 * @param array $editor_settings Default editor settings. 280 * @param string $editor_name The name of the editor, e.g. 'post-editor'. 281 */ 282 $editor_settings = apply_filters( "block_editor_settings_{$editor_name}", $editor_settings, $editor_name ); 251 283 if ( 'post-editor' === $editor_name ) { 252 284 $post = get_post(); … … 261 293 * @param WP_Post $post Post being edited. 262 294 */ 263 $editor_settings = apply_filters_deprecated( 'block_editor_settings', array( $editor_settings, $post ), '5.8.0', "block_editor_settings_{$editor_name}");295 $editor_settings = apply_filters_deprecated( 'block_editor_settings', array( $editor_settings, $post ), '5.8.0', 'block_editor_settings_all' ); 264 296 } 265 297 -
trunk/tests/phpunit/tests/blocks/block-editor.php
r50776 r50777 253 253 return array( 'test/filtered-my-block' ); 254 254 } 255 function filter_block_categories_my_editor() {256 return array(257 array(258 'slug' => 'filtered-my-category',259 'title' => 'Filtered My Category',260 'icon' => null,261 ),262 );263 }264 255 function filter_block_editor_settings_my_editor( $editor_settings ) { 265 256 $editor_settings['maxUploadFileSize'] = 12345; … … 269 260 270 261 add_filter( 'allowed_block_types_my-editor', 'filter_allowed_block_types_my_editor', 10, 1 ); 271 add_filter( 'block_categories_my-editor', 'filter_block_categories_my_editor', 10, 1 );272 262 add_filter( 'block_editor_settings_my-editor', 'filter_block_editor_settings_my_editor', 10, 1 ); 273 263 … … 275 265 276 266 remove_filter( 'allowed_block_types_my-editor', 'filter_allowed_block_types_my_editor' ); 277 remove_filter( 'block_categories_my-editor', 'filter_block_categories_my_editor' );278 267 remove_filter( 'block_editor_settings_my-editor', 'filter_block_editor_settings_my_editor' ); 279 268 280 269 $this->assertSameSets( array( 'test/filtered-my-block' ), $settings['allowedBlockTypes'] ); 281 $this->assertSameSets( 282 array( 283 array( 284 'slug' => 'filtered-my-category', 285 'title' => 'Filtered My Category', 270 $this->assertSame( 12345, $settings['maxUploadFileSize'] ); 271 } 272 273 /** 274 * @ticket 52920 275 */ 276 function test_get_block_editor_settings_overrides_default_settings_any_editor() { 277 function filter_allowed_block_types_any_editor() { 278 return array( 'test/filtered-any-block' ); 279 } 280 function filter_block_categories_any_editor() { 281 return array( 282 array( 283 'slug' => 'filtered-any-category', 284 'title' => 'Filtered Any Category', 285 'icon' => null, 286 ), 287 ); 288 } 289 function filter_block_editor_settings_any_editor( $editor_settings ) { 290 $editor_settings['maxUploadFileSize'] = 54321; 291 292 return $editor_settings; 293 } 294 295 add_filter( 'allowed_block_types_all', 'filter_allowed_block_types_any_editor', 10, 1 ); 296 add_filter( 'block_categories_all', 'filter_block_categories_any_editor', 10, 1 ); 297 add_filter( 'block_editor_settings_all', 'filter_block_editor_settings_any_editor', 10, 1 ); 298 299 $settings = get_block_editor_settings( 'any-editor' ); 300 301 remove_filter( 'allowed_block_types_all', 'filter_allowed_block_types_any_editor' ); 302 remove_filter( 'block_categories_all', 'filter_block_categories_any_editor' ); 303 remove_filter( 'block_editor_settings_all', 'filter_block_editor_settings_any_editor' ); 304 305 $this->assertSameSets( array( 'test/filtered-any-block' ), $settings['allowedBlockTypes'] ); 306 $this->assertSameSets( 307 array( 308 array( 309 'slug' => 'filtered-any-category', 310 'title' => 'Filtered Any Category', 286 311 'icon' => null, 287 312 ), … … 289 314 $settings['blockCategories'] 290 315 ); 291 $this->assertSame( 12345, $settings['maxUploadFileSize'] );316 $this->assertSame( 54321, $settings['maxUploadFileSize'] ); 292 317 } 293 318
Note: See TracChangeset
for help on using the changeset viewer.