Blocks: Include the offending block name in registration error notices.

Three of the four `_doing_it_wrong()` calls in `WP_Block_Type_Registry::register()` emitted a generic message that did not identify which block name triggered it, making it hard to locate the offending registration. The notices for non-string names, uppercase characters, and a missing namespace prefix now include the received value (the type via `gettype()` for non-strings, and the escaped name otherwise), matching the existing "already registered" notice that did already report the name.

Developed in https://github.com/WordPress/wordpress-develop/pull/11478.
Follow-up to r44108.

Props manishxdp, desrosj, benjgrolleau, westonruter.
Fixes #65039.

Built from https://develop.svn.wordpress.org/trunk@62452


git-svn-id: http://core.svn.wordpress.org/trunk@61733 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter
2026-06-03 05:19:44 +00:00
parent a85258a55e
commit 6b7e66ee1e
2 changed files with 7 additions and 4 deletions
+6 -3
View File
@@ -55,7 +55,8 @@ final class WP_Block_Type_Registry {
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 @@ final class WP_Block_Type_Registry {
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.' ), esc_html( $name ) ),
'5.0.0'
);
return false;
@@ -74,7 +76,8 @@ final class WP_Block_Type_Registry {
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.' ), esc_html( $name ) ),
'5.0.0'
);
return false;
+1 -1
View File
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '7.1-alpha-62451';
$wp_version = '7.1-alpha-62452';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.