From a756900974662678c7c59ff2148131524e6585af Mon Sep 17 00:00:00 2001 From: gziolo Date: Fri, 8 Jan 2021 16:45:07 +0000 Subject: [PATCH] Editor: Support filtering arguments in block type registration from metadata Adds 2 new hooks in `register_block_type_from_metadata`: - Named `block_type_metadata` to filter the content of metadata read from `block.json` - Named `block_type_metadata_settings` to filter the settings object determined from the metadata that is passed to `register_block_type` call Props swissspidy. Fixes #52138. Built from https://develop.svn.wordpress.org/trunk@49948 git-svn-id: http://core.svn.wordpress.org/trunk@49647 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 29 ++++++++++++++++++++++++++--- wp-includes/version.php | 2 +- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index 000ded53e6..1b5427340f 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -201,6 +201,15 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { } $metadata['file'] = $metadata_file; + /** + * Filters the metadata provided for registering a block type. + * + * @since 5.7.0 + * + * @param array $metadata Metadata for registering a block type. + */ + $metadata = apply_filters( 'block_type_metadata', $metadata ); + $settings = array(); $property_mappings = array( 'title' => 'title', @@ -252,12 +261,26 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { ); } - return register_block_type( - $metadata['name'], + /** + * Filters the settings determined from the block type metadata. + * + * @since 5.7.0 + * + * @param array $settings Array of determined settings for registering a block type. + * @param array $metadata Metadata provided for registering a block type. + */ + $settings = apply_filters( + 'block_type_metadata_settings', array_merge( $settings, $args - ) + ), + $metadata + ); + + return register_block_type( + $metadata['name'], + $settings ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 1888a2aaa4..10069f4420 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.7-alpha-49947'; +$wp_version = '5.7-alpha-49948'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.