Make WordPress Core

Opened 5 months ago

Closed 3 months ago

#65039 closed enhancement (fixed)

_doing_it_wrong messages in WP_Block_Type_Registry::register() lack context

Reported by: benjgrolleau Owned by: westonruter
Priority: normal Milestone: 7.1
Component: Editor Version: 5.0
Severity: normal Keywords: has-patch
Cc: Focuses:

Description

WP_Block_Type_Registry::register() has four _doing_it_wrong() calls for invalid block names. Three of them don't say which name caused the error.

Example: you get "Block type names must not contain uppercase characters." with no way to tell which block it's about.

The fourth message ("Block type "%s" is already registered.") already includes the name. The other three should do the same to improve developper experience.

Change History (16)

This ticket was mentioned in PR #11475 on WordPress/wordpress-develop by @benjgrolleau.


5 months ago
#1

  • Keywords has-patch added

WP_Block_Type_Registry::register() has four _doing_it_wrong() calls for invalid block names. Three of them don't say which name caused the error.

Example: you get "Block type names must not contain uppercase characters." with no way to tell which block it's about.
The fourth message ("Block type "%s" is already registered.") already includes the name. The other three should do the same to improve developper experience.

Trac ticket: https://core.trac.wordpress.org/ticket/65039

_Use of AI : I used AI to help write this PR description — my English isn't great._

This ticket was mentioned in PR #11478 on WordPress/wordpress-develop by @manishxdp.


5 months ago
#2

Tested the existing patch and it works as expected.

Testing Instructions:

  1. Apply the patch from PR #11475.
  2. In a test plugin or theme, try registering a block with an invalid name (e.g., containing uppercase characters):

register_block_type( 'MyBlock' );

  1. Observe the _doing_it_wrong() notice.

Results:

  • Before applying the patch: The error message is generic and does not indicate which block caused the issue.

Example:
"Block type names must not contain uppercase characters."

  • After applying the patch: The error message correctly includes the block name, making debugging easier.

Example:
"Block type "MyBlock" must not contain uppercase characters."

  1. Also verified similar improvements for other _doing_it_wrong() calls in WP_Block_Type_Registry::register().

Ticket track - https://core.trac.wordpress.org/ticket/65039

@manishxdp commented on PR #11478:


5 months ago
#3

  1. I tested this issue by creating a sample plugin that registers invalid block types:

https://www.dropbox.com/scl/fi/yydrbuv2saaf8w7gmw4yy/test-invalid-block.zip?rlkey=f1u85jp0424lqczpvtltve6j1&st=h30rmcia&dl=0

The plugin includes the following invalid cases:

  • Block names with uppercase characters
  • Missing namespace
  • Invalid characters
  1. I enabled WP_DEBUG and verified the output in the debug.log file:

https://github.com/user-attachments/files/26590078/debug.log

Result:
The _doing_it_wrong() messages now correctly include the block name causing the issue, improving debugging clarity.

#4 @westonruter
5 months ago

  • Milestone Awaiting Review7.1
  • Owner set to westonruter
  • Status newreviewing

@manishxdp commented on PR #11478:


5 months ago
#5

@desrosj done changes

@manishxdp commented on PR #11478:


5 months ago
#6

@desrosj changes done can you please review once

@manishxdp commented on PR #11478:


4 months ago
#7

@westonruter any progress on this pr as it is approved or should i look into it

@manishxdp commented on PR #11478:


4 months ago
#8

@desrosj hi jonathan any update on this?

#9 @audrasjb
4 months ago

Removing trunk version as this is not going to be shipped with WP 7.0 but in the next releases.

#10 @desrosj
4 months ago

  • Version trunk5.0

Appears to have been introduced in [43742]/[44108] through #45097.

@manishxdp commented on PR #11478:


4 months ago
#11

@westonruter can wordpress 7 is released is the is code unfreeze now?

@manishxdp commented on PR #11478:


3 months ago
#12

@westonruter any progress on this pr as it is approved or should i look into it

@manishxdp commented on PR #11478:


3 months ago
#13

@desrosj hi jonathan any update on this?

@manishxdp commented on PR #11478:


3 months ago
#14

@westonruter can wordpress 7 is released is the is code unfreeze now?

@manishxdp commented on PR #11478:


3 months ago
#15

@westonruter can you check this pr please let me know if any changes required

#16 @westonruter
3 months ago

  • Resolutionfixed
  • Status reviewingclosed

In 62452:

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.

Note: See TracTickets for help on using tickets.