Skip to content

Commit 2ccf96e

Browse files
committed
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 #11478. Follow-up to r44108. Props manishxdp, desrosj, benjgrolleau, westonruter. Fixes #65039. git-svn-id: https://develop.svn.wordpress.org/trunk@62452 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ba36e52 commit 2ccf96e

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎src/wp-includes/class-wp-block-type-registry.php‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public function register( $name, $args = array() ) {
5555
if ( ! is_string( $name ) ) {
5656
_doing_it_wrong(
5757
__METHOD__,
58-
__( 'Block type names must be strings.' ),
58+
/* translators: %s: The received block type name type. */
59+
sprintf( __( 'Block type names must be strings, received %s.' ), gettype( $name ) ),
5960
'5.0.0'
6061
);
6162
return false;
@@ -64,7 +65,8 @@ public function register( $name, $args = array() ) {
6465
if ( preg_match( '/[A-Z]+/', $name ) ) {
6566
_doing_it_wrong(
6667
__METHOD__,
67-
__( 'Block type names must not contain uppercase characters.' ),
68+
/* translators: %s: Block name. */
69+
sprintf( __( 'Block type names must not contain uppercase characters. "%s" was given.' ), esc_html( $name ) ),
6870
'5.0.0'
6971
);
7072
return false;
@@ -74,7 +76,8 @@ public function register( $name, $args = array() ) {
7476
if ( ! preg_match( $name_matcher, $name ) ) {
7577
_doing_it_wrong(
7678
__METHOD__,
77-
__( 'Block type names must contain a namespace prefix. Example: my-plugin/my-custom-block-type' ),
79+
/* translators: %s: Block name. */
80+
sprintf( __( 'Block type names must contain a namespace prefix. Example: my-plugin/my-custom-block-type. "%s" was given.' ), esc_html( $name ) ),
7881
'5.0.0'
7982
);
8083
return false;

0 commit comments

Comments
 (0)