From 810a9b2e62969e23b0852e9e200e05ff851f7d81 Mon Sep 17 00:00:00 2001 From: benjaming Date: Wed, 8 Apr 2026 16:15:49 +0200 Subject: [PATCH] Blocks: Include block name context in _doing_it_wrong messages in WP_Block_Type_Registry::register() The _doing_it_wrong() calls for invalid block type names did not include the offending value, making it difficult to identify which block was causing the issue. This adds the block name (or received type) to each validation message for better developer experience. --- src/wp-includes/class-wp-block-type-registry.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/class-wp-block-type-registry.php b/src/wp-includes/class-wp-block-type-registry.php index 969f0f0f64a42..8c3e6fc0ffb14 100644 --- a/src/wp-includes/class-wp-block-type-registry.php +++ b/src/wp-includes/class-wp-block-type-registry.php @@ -55,7 +55,8 @@ public function register( $name, $args = array() ) { if ( ! is_string( $name ) ) { _doing_it_wrong( __METHOD__, - __( 'Block type names must be strings.' ), + /* translators: %s: The received block type name type. */ + sprintf( __( 'Block type names must be strings, received %s.' ), gettype( $name ) ), '5.0.0' ); return false; @@ -64,7 +65,8 @@ public function register( $name, $args = array() ) { if ( preg_match( '/[A-Z]+/', $name ) ) { _doing_it_wrong( __METHOD__, - __( 'Block type names must not contain uppercase characters.' ), + /* translators: %s: Block name. */ + sprintf( __( 'Block type names must not contain uppercase characters. "%s" was given.' ), $name ), '5.0.0' ); return false; @@ -74,7 +76,8 @@ public function register( $name, $args = array() ) { if ( ! preg_match( $name_matcher, $name ) ) { _doing_it_wrong( __METHOD__, - __( 'Block type names must contain a namespace prefix. Example: my-plugin/my-custom-block-type' ), + /* translators: %s: Block name. */ + sprintf( __( 'Block type names must contain a namespace prefix. Example: my-plugin/my-custom-block-type. "%s" was given.' ), $name ), '5.0.0' ); return false;