Changeset 50920
- Timestamp:
- 05/17/2021 03:06:27 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-editor.php
r50798 r50920 121 121 */ 122 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 name129 * of the editor type, e.g. 'post-editor', 'site-editor', etc.130 *131 * @since 5.8.0132 *133 * @param bool|array $allowed_block_types Array of block type slugs, or134 * 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 );138 123 if ( 'post-editor' === $editor_name ) { 139 124 $post = get_post(); … … 268 253 */ 269 254 $editor_settings = apply_filters( 'block_editor_settings_all', $editor_settings, $editor_name ); 270 271 /**272 * Filters the settings to pass to the block editor for a given editor type.273 *274 * The dynamic portion of the hook name, `$editor_name`, refers to the name275 * of the editor type, e.g. 'post-editor', 'site-editor', etc.276 *277 * @since 5.8.0278 *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 );283 255 if ( 'post-editor' === $editor_name ) { 284 256 $post = get_post(); -
trunk/tests/phpunit/tests/blocks/block-editor.php
r50777 r50920 239 239 * @ticket 52920 240 240 */ 241 function test_get_block_editor_settings_returns_default_settings() { 242 $this->assertSameSets( 243 get_block_editor_settings( 'my-editor' ), 244 get_default_block_editor_settings() 245 ); 246 } 247 248 /** 249 * @ticket 52920 250 */ 251 function test_get_block_editor_settings_overrides_default_settings_my_editor() { 241 function test_get_block_editor_settings_overrides_default_settings_all_editors() { 252 242 function filter_allowed_block_types_my_editor() { 253 243 return array( 'test/filtered-my-block' ); 254 244 } 245 function filter_block_categories_my_editor() { 246 return array( 247 array( 248 'slug' => 'filtered-my-category', 249 'title' => 'Filtered My Category', 250 'icon' => null, 251 ), 252 ); 253 } 255 254 function filter_block_editor_settings_my_editor( $editor_settings ) { 256 255 $editor_settings['maxUploadFileSize'] = 12345; … … 259 258 } 260 259 261 add_filter( 'allowed_block_types_my-editor', 'filter_allowed_block_types_my_editor', 10, 1 ); 262 add_filter( 'block_editor_settings_my-editor', 'filter_block_editor_settings_my_editor', 10, 1 ); 260 add_filter( 'allowed_block_types_all', 'filter_allowed_block_types_my_editor', 10, 1 ); 261 add_filter( 'block_categories_all', 'filter_block_categories_my_editor', 10, 1 ); 262 add_filter( 'block_editor_settings_all', 'filter_block_editor_settings_my_editor', 10, 1 ); 263 263 264 264 $settings = get_block_editor_settings( 'my-editor' ); 265 265 266 remove_filter( 'allowed_block_types_my-editor', 'filter_allowed_block_types_my_editor' ); 267 remove_filter( 'block_editor_settings_my-editor', 'filter_block_editor_settings_my_editor' ); 266 remove_filter( 'allowed_block_types_all', 'filter_allowed_block_types_my_editor' ); 267 remove_filter( 'block_categories_all', 'filter_block_categories_my_editor' ); 268 remove_filter( 'block_editor_settings_all', 'filter_block_editor_settings_my_editor' ); 268 269 269 270 $this->assertSameSets( array( 'test/filtered-my-block' ), $settings['allowedBlockTypes'] ); 271 $this->assertSameSets( 272 array( 273 array( 274 'slug' => 'filtered-my-category', 275 'title' => 'Filtered My Category', 276 'icon' => null, 277 ), 278 ), 279 $settings['blockCategories'] 280 ); 270 281 $this->assertSame( 12345, $settings['maxUploadFileSize'] ); 271 }272 273 /**274 * @ticket 52920275 */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',311 'icon' => null,312 ),313 ),314 $settings['blockCategories']315 );316 $this->assertSame( 54321, $settings['maxUploadFileSize'] );317 282 } 318 283
Note: See TracChangeset
for help on using the changeset viewer.