Make WordPress Core

Opened 5 weeks ago

Last modified 25 hours ago

#65039 reviewing enhancement

_doing_it_wrong messages in WP_Block_Type_Registry::register() lack context

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

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 (8)

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


5 weeks 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 weeks 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 weeks 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 weeks ago

  • Milestone changed from Awaiting Review to 7.1
  • Owner set to westonruter
  • Status changed from new to reviewing

@manishxdp commented on PR #11478:


5 weeks ago
#5

@desrosj done changes

@manishxdp commented on PR #11478:


5 weeks ago
#6

@desrosj changes done can you please review once

@manishxdp commented on PR #11478:


11 days ago
#7

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

@manishxdp commented on PR #11478:


25 hours ago
#8

@desrosj hi jonathan any update on this?

Note: See TracTickets for help on using tickets.