-
Notifications
You must be signed in to change notification settings - Fork 3.5k
REST API: Log doing_it_wrong notices to debug.log #10537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
0a06f41
6c3e353
610ac74
6c7c2d4
8bb3815
40c4f98
0a98d18
922b735
043f126
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -760,7 +760,7 @@ function rest_handle_deprecated_argument( $function_name, $message, $version ) { | |||||
| * @param string|null $version The version of WordPress where the message was added. | ||||||
| */ | ||||||
| function rest_handle_doing_it_wrong( $function_name, $message, $version ) { | ||||||
| if ( ! WP_DEBUG || headers_sent() ) { | ||||||
| if ( ! WP_DEBUG ) { | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -774,7 +774,25 @@ function rest_handle_doing_it_wrong( $function_name, $message, $version ) { | |||||
| $string = sprintf( $string, $function_name, $message ); | ||||||
| } | ||||||
|
|
||||||
| header( sprintf( 'X-WP-DoingItWrong: %s', $string ) ); | ||||||
| if ( ! headers_sent() ) { | ||||||
| header( sprintf( 'X-WP-DoingItWrong: %s', $string ) ); | ||||||
| } | ||||||
|
|
||||||
| if ( WP_DEBUG_LOG ) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Claude Code (altitude): Consider whether this is the right depth for the fix. The reason these notices never reach the log during REST is line 248's Note that
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Claude Code: This logging runs on the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should ensure the notices only get logged out if such logs are desired.
Suggested change
|
||||||
| $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Claude Code (reuse): The bespoke |
||||||
| $caller = ''; | ||||||
| // Find the first caller outside of WordPress core (plugin or theme). | ||||||
| foreach ( $backtrace as $frame ) { | ||||||
| if ( isset( $frame['file'] ) && str_starts_with( $frame['file'], WP_CONTENT_DIR ) ) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Claude Code:
In both cases the log omits the offending file/line, which is exactly the information this feature exists to surface. Also note there's no path-separator boundary on the prefix match, so a sibling dir like |
||||||
| $caller = ' in ' . $frame['file']; | ||||||
| if ( isset( $frame['line'] ) ) { | ||||||
| $caller .= ' on line ' . $frame['line']; | ||||||
| } | ||||||
| break; | ||||||
| } | ||||||
| } | ||||||
| error_log( 'PHP Notice: ' . wp_strip_all_tags( $string ) . $caller ); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Claude Code: (For what it's worth, I verified the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Claude Code: With this direct |
||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 Claude Code: Incomplete/inconsistent fix. Only
rest_handle_doing_it_wrong()gains debug-log output. The sibling handlersrest_handle_deprecated_function()andrest_handle_deprecated_argument()are registered identically inrest_api_default_filters()(lines 243–246) with the same__return_falsesuppression, but still drop their notices fromdebug.logentirely.With
WP_DEBUG_LOGon, a deprecated function/argument used during a REST request logs nothing, while a_doing_it_wrong()call in the same request now logs — an asymmetry that will confuse debugging and invites copy-pasting this same backtrace/format block into two more places.