From 0a06f412e2d38ce1e2b3b820408c2b71d144aaf5 Mon Sep 17 00:00:00 2001 From: ilclaudio Date: Wed, 25 Mar 2026 01:18:55 +0100 Subject: [PATCH 01/17] Fixed rest_handle_doing_it_wrong to manage debug messages properly - part 2 --- src/wp-includes/rest-api.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index c524f9e22a12f..73b2d7ef0e600 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -767,7 +767,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; } @@ -781,7 +781,15 @@ function rest_handle_doing_it_wrong( $function_name, $message, $version ) { $string = sprintf( $string, $function_name, $message ); } - header( sprintf( 'X-WP-DoingItWrong: %s', $string ) ); + if ( WP_DEBUG_LOG ) { + error_log( + sprintf( + 'REST API - Function %1$s was called incorrectly. %2$s', + $function_name, + wp_strip_all_tags( $message ) + ) + ); + } } /** From 6c3e353cf8125c7ec8a41db412924075982b9b48 Mon Sep 17 00:00:00 2001 From: ilclaudio Date: Wed, 25 Mar 2026 18:54:48 +0100 Subject: [PATCH 02/17] Fixed rest_handle_doing_it_wrong: added headers check --- src/wp-includes/rest-api.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 73b2d7ef0e600..30fe8c3aeefe3 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -781,6 +781,9 @@ function rest_handle_doing_it_wrong( $function_name, $message, $version ) { $string = sprintf( $string, $function_name, $message ); } + if ( ! headers_sent() ) { + header( sprintf( 'X-WP-DoingItWrong: %s', $string ) ); + } if ( WP_DEBUG_LOG ) { error_log( sprintf( From 610ac74f62f460309870357b0bbaa40c92ee5af1 Mon Sep 17 00:00:00 2001 From: ilclaudio Date: Thu, 26 Mar 2026 10:21:39 +0100 Subject: [PATCH 03/17] REST API: Use with 'PHP Notice:' prefix in rest_handle_doing_it_wrong() error log --- src/wp-includes/rest-api.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 30fe8c3aeefe3..492d9244e7a03 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -785,13 +785,7 @@ function rest_handle_doing_it_wrong( $function_name, $message, $version ) { header( sprintf( 'X-WP-DoingItWrong: %s', $string ) ); } if ( WP_DEBUG_LOG ) { - error_log( - sprintf( - 'REST API - Function %1$s was called incorrectly. %2$s', - $function_name, - wp_strip_all_tags( $message ) - ) - ); + error_log( 'PHP Notice: ' . wp_strip_all_tags( $string ) ); } } From 8bb3815aea7ef398c630bc4430a2c8eb85674570 Mon Sep 17 00:00:00 2001 From: ilclaudio Date: Mon, 6 Apr 2026 18:00:48 +0200 Subject: [PATCH 04/17] REST API: Add caller location to rest_handle_doing_it_wrong() error log Use debug_backtrace() to find and append the first plugin or theme file responsible for the incorrect usage to the error_log() message. --- src/wp-includes/rest-api.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 492d9244e7a03..99147bf8338d2 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -784,8 +784,18 @@ function rest_handle_doing_it_wrong( $function_name, $message, $version ) { if ( ! headers_sent() ) { header( sprintf( 'X-WP-DoingItWrong: %s', $string ) ); } + if ( WP_DEBUG_LOG ) { - error_log( 'PHP Notice: ' . wp_strip_all_tags( $string ) ); + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); + $caller = ''; + // Find the first caller outside of WordPress core (plugin or theme). + foreach ( $backtrace as $frame ) { + if ( isset( $frame['file'] ) && str_contains( $frame['file'], WP_CONTENT_DIR ) ) { + $caller = ' in ' . $frame['file'] . ' on line ' . $frame['line']; + break; + } + } + error_log( 'PHP Notice: ' . wp_strip_all_tags( $string ) . $caller ); } } From 0a98d181fed269558628919c9c002dadfe02e22e Mon Sep 17 00:00:00 2001 From: Claudio Date: Fri, 15 May 2026 09:22:52 +0200 Subject: [PATCH 05/17] Update src/wp-includes/rest-api.php REST API: Guard against missing line in backtrace frame Co-authored-by: Weston Ruter --- src/wp-includes/rest-api.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 06e45ffd396d7..d7e8e780db5b4 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -784,7 +784,10 @@ function rest_handle_doing_it_wrong( $function_name, $message, $version ) { // Find the first caller outside of WordPress core (plugin or theme). foreach ( $backtrace as $frame ) { if ( isset( $frame['file'] ) && str_contains( $frame['file'], WP_CONTENT_DIR ) ) { - $caller = ' in ' . $frame['file'] . ' on line ' . $frame['line']; + $caller = ' in ' . $frame['file']; + if ( isset( $frame['line'] ) ) { + $caller .= ' on line ' . $frame['line']; + } break; } } From 922b7358ed546a9d9e72ad252dfea4b5c02c5f44 Mon Sep 17 00:00:00 2001 From: Claudio Date: Fri, 15 May 2026 09:23:11 +0200 Subject: [PATCH 06/17] Update src/wp-includes/rest-api.php REST API: Address review feedback on doing_it_wrong logger Co-authored-by: Weston Ruter --- src/wp-includes/rest-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index d7e8e780db5b4..1410fcbe1669c 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -783,7 +783,7 @@ function rest_handle_doing_it_wrong( $function_name, $message, $version ) { $caller = ''; // Find the first caller outside of WordPress core (plugin or theme). foreach ( $backtrace as $frame ) { - if ( isset( $frame['file'] ) && str_contains( $frame['file'], WP_CONTENT_DIR ) ) { + if ( isset( $frame['file'] ) && str_starts_with( $frame['file'], WP_CONTENT_DIR ) ) { $caller = ' in ' . $frame['file']; if ( isset( $frame['line'] ) ) { $caller .= ' on line ' . $frame['line']; From 3829aed76e1ee1665396f3621aee41c20e98ac42 Mon Sep 17 00:00:00 2001 From: Claudio Date: Sat, 6 Jun 2026 16:17:27 +0200 Subject: [PATCH 07/17] Update src/wp-includes/rest-api.php We don't need wp_strip_all_tags, removing it Co-authored-by: Weston Ruter --- src/wp-includes/rest-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 1410fcbe1669c..03b6efb575311 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -791,7 +791,7 @@ function rest_handle_doing_it_wrong( $function_name, $message, $version ) { break; } } - error_log( 'PHP Notice: ' . wp_strip_all_tags( $string ) . $caller ); + error_log( 'PHP Notice: ' . $string . $caller ); } } From 9b5587582c390c986d2db286cd8df9815363aed3 Mon Sep 17 00:00:00 2001 From: Claudio Date: Sat, 6 Jun 2026 16:18:29 +0200 Subject: [PATCH 08/17] Update src/wp-includes/rest-api.php This should ensure the notices only get logged out if such logs are desired. Co-authored-by: Weston Ruter --- src/wp-includes/rest-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 03b6efb575311..06f7d9a22b49a 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -778,7 +778,7 @@ function rest_handle_doing_it_wrong( $function_name, $message, $version ) { header( sprintf( 'X-WP-DoingItWrong: %s', $string ) ); } - if ( WP_DEBUG_LOG ) { + if ( WP_DEBUG_LOG && ( error_reporting() & E_USER_NOTICE ) ) { $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); $caller = ''; // Find the first caller outside of WordPress core (plugin or theme). From 5777f1a22f83e6d6a1444720f35baa22c279f1ae Mon Sep 17 00:00:00 2001 From: ilclaudio Date: Sat, 6 Jun 2026 18:58:20 +0200 Subject: [PATCH 09/17] REST API: Fix path comparison and backtrace depth in rest_handle_doing_it_wrong() - Normalize paths via wp_normalize_path() to fix Windows backslash mismatch - Add trailingslashit() to prevent false matches on sibling directories - Limit debug_backtrace() to 20 frames - After testing, the log output contains raw HTML tags (e.g. ) I'd lean toward keeping wp_strip_all_tags() for cleaner plain-text log output --- src/wp-includes/rest-api.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 06f7d9a22b49a..6e8aae0e964c7 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -779,11 +779,12 @@ function rest_handle_doing_it_wrong( $function_name, $message, $version ) { } if ( WP_DEBUG_LOG && ( error_reporting() & E_USER_NOTICE ) ) { - $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); - $caller = ''; + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 20 ); + $caller = ''; + $normalized_content_dir = trailingslashit( wp_normalize_path( WP_CONTENT_DIR ) ); // 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 ) ) { + if ( isset( $frame['file'] ) && str_starts_with( wp_normalize_path( $frame['file'] ), $normalized_content_dir ) ) { $caller = ' in ' . $frame['file']; if ( isset( $frame['line'] ) ) { $caller .= ' on line ' . $frame['line']; @@ -791,7 +792,7 @@ function rest_handle_doing_it_wrong( $function_name, $message, $version ) { break; } } - error_log( 'PHP Notice: ' . $string . $caller ); + error_log( 'PHP Notice: ' . wp_strip_all_tags( $string ) . $caller ); } } From a4076dbf8ab19ef4697fbcb2689d6caedda65341 Mon Sep 17 00:00:00 2001 From: ilclaudio Date: Wed, 10 Jun 2026 16:40:54 +0200 Subject: [PATCH 10/17] REST API: Extend debug logging to deprecated function and argument handlers, add caller location --- src/wp-includes/rest-api.php | 83 ++++++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 18 deletions(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index f49ab0ac944b7..1943cfbaff9c4 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -702,6 +702,54 @@ function rest_ensure_response( $response ) { return new WP_REST_Response( $response ); } +/** + * Returns a formatted caller location string for REST API debug log entries. + * + * Searches the call stack for the first frame whose file lives inside WP_CONTENT_DIR, + * identifying the plugin or theme that triggered the notice. Used by the REST API + * debug handlers to append actionable location info to error_log() output. + * + * @since 7.1.0 + * @access private + * + * @return string Formatted string such as ' called from my_func() in /path/plugin.php on line 8', + * or ' called from (anonymous function) in /path/plugin.php on line 8' for closures, + * or empty string when no plugin/theme frame is found in the call stack. + */ +function _rest_get_debug_backtrace_caller() { + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 20 ); + $normalized_content_dir = trailingslashit( wp_normalize_path( WP_CONTENT_DIR ) ); + + foreach ( $backtrace as $i => $frame ) { + if ( ! isset( $frame['file'] ) || ! str_starts_with( wp_normalize_path( $frame['file'] ), $normalized_content_dir ) ) { + continue; + } + + $location = ' in ' . wp_normalize_path( $frame['file'] ); + if ( isset( $frame['line'] ) ) { + $location .= ' on line ' . $frame['line']; + } + + /* + * The next frame holds the function that contains the offending call. + * PHP represents closures as '{closure}' (< 8.4) or '{closure:file:line}' (>= 8.4), + * both starting with '{'. These are replaced with a readable label. + */ + $next = $backtrace[ $i + 1 ] ?? array(); + if ( ! empty( $next['function'] ) ) { + if ( str_starts_with( $next['function'], '{' ) ) { + return ' called from (anonymous function)' . $location; + } + $caller_func = isset( $next['class'] ) ? $next['class'] . ( $next['type'] ?? '::' ) . $next['function'] : $next['function']; + return ' called from ' . $caller_func . '()' . $location; + } + + return $location; + } + + return ''; +} + /** * Handles _deprecated_function() errors. * @@ -712,7 +760,7 @@ function rest_ensure_response( $response ) { * @param string $version Version. */ function rest_handle_deprecated_function( $function_name, $replacement, $version ) { - if ( ! WP_DEBUG || headers_sent() ) { + if ( ! WP_DEBUG ) { return; } if ( ! empty( $replacement ) ) { @@ -723,7 +771,13 @@ function rest_handle_deprecated_function( $function_name, $replacement, $version $string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function_name, $version ); } - header( sprintf( 'X-WP-DeprecatedFunction: %s', $string ) ); + if ( ! headers_sent() ) { + header( sprintf( 'X-WP-DeprecatedFunction: %s', $string ) ); + } + + if ( WP_DEBUG_LOG && ( error_reporting() & E_USER_DEPRECATED ) ) { + error_log( 'PHP Deprecated: ' . wp_strip_all_tags( $string ) . _rest_get_debug_backtrace_caller() ); + } } /** @@ -736,7 +790,7 @@ function rest_handle_deprecated_function( $function_name, $replacement, $version * @param string $version Version. */ function rest_handle_deprecated_argument( $function_name, $message, $version ) { - if ( ! WP_DEBUG || headers_sent() ) { + if ( ! WP_DEBUG ) { return; } if ( $message ) { @@ -747,7 +801,13 @@ function rest_handle_deprecated_argument( $function_name, $message, $version ) { $string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function_name, $version ); } - header( sprintf( 'X-WP-DeprecatedParam: %s', $string ) ); + if ( ! headers_sent() ) { + header( sprintf( 'X-WP-DeprecatedParam: %s', $string ) ); + } + + if ( WP_DEBUG_LOG && ( error_reporting() & E_USER_DEPRECATED ) ) { + error_log( 'PHP Deprecated: ' . wp_strip_all_tags( $string ) . _rest_get_debug_backtrace_caller() ); + } } /** @@ -779,20 +839,7 @@ function rest_handle_doing_it_wrong( $function_name, $message, $version ) { } if ( WP_DEBUG_LOG && ( error_reporting() & E_USER_NOTICE ) ) { - $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 20 ); - $caller = ''; - $normalized_content_dir = trailingslashit( wp_normalize_path( WP_CONTENT_DIR ) ); - // Find the first caller outside of WordPress core (plugin or theme). - foreach ( $backtrace as $frame ) { - if ( isset( $frame['file'] ) && str_starts_with( wp_normalize_path( $frame['file'] ), $normalized_content_dir ) ) { - $caller = ' in ' . $frame['file']; - if ( isset( $frame['line'] ) ) { - $caller .= ' on line ' . $frame['line']; - } - break; - } - } - error_log( 'PHP Notice: ' . wp_strip_all_tags( $string ) . $caller ); + error_log( 'PHP Notice: ' . wp_strip_all_tags( $string ) . _rest_get_debug_backtrace_caller() ); } } From 8329da1b95631f9faf54b9c9da2c15106dab7c07 Mon Sep 17 00:00:00 2001 From: ilclaudio Date: Wed, 10 Jun 2026 18:45:27 +0200 Subject: [PATCH 11/17] REST API: Fix case-insensitive path comparison in _rest_get_debug_backtrace_caller() --- src/wp-includes/rest-api.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 1943cfbaff9c4..04eb17fb0f31e 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -718,14 +718,19 @@ function rest_ensure_response( $response ) { */ function _rest_get_debug_backtrace_caller() { $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 20 ); - $normalized_content_dir = trailingslashit( wp_normalize_path( WP_CONTENT_DIR ) ); + $normalized_content_dir = strtolower( trailingslashit( wp_normalize_path( WP_CONTENT_DIR ) ) ); foreach ( $backtrace as $i => $frame ) { - if ( ! isset( $frame['file'] ) || ! str_starts_with( wp_normalize_path( $frame['file'] ), $normalized_content_dir ) ) { + if ( ! isset( $frame['file'] ) ) { continue; } - $location = ' in ' . wp_normalize_path( $frame['file'] ); + $normalized_file = wp_normalize_path( $frame['file'] ); + if ( ! str_starts_with( strtolower( $normalized_file ), $normalized_content_dir ) ) { + continue; + } + + $location = ' in ' . $normalized_file; if ( isset( $frame['line'] ) ) { $location .= ' on line ' . $frame['line']; } From 3b7826dc8b86f7c7c0f215fdc0fa3f1a243a4c3b Mon Sep 17 00:00:00 2001 From: Claudio Date: Sun, 14 Jun 2026 12:03:42 +0200 Subject: [PATCH 12/17] Update src/wp-includes/rest-api.php Co-authored-by: Weston Ruter --- src/wp-includes/rest-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 04eb17fb0f31e..cdb722ca124f7 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -716,7 +716,7 @@ function rest_ensure_response( $response ) { * or ' called from (anonymous function) in /path/plugin.php on line 8' for closures, * or empty string when no plugin/theme frame is found in the call stack. */ -function _rest_get_debug_backtrace_caller() { +function _rest_get_debug_backtrace_caller(): string { $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 20 ); $normalized_content_dir = strtolower( trailingslashit( wp_normalize_path( WP_CONTENT_DIR ) ) ); From b714964815af541a0c67d9cb0cc03dfd3612b816 Mon Sep 17 00:00:00 2001 From: Claudio Date: Sun, 14 Jun 2026 12:05:55 +0200 Subject: [PATCH 13/17] Update src/wp-includes/rest-api.php Co-authored-by: Weston Ruter --- src/wp-includes/rest-api.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index cdb722ca124f7..e8f2df68b566d 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -745,7 +745,10 @@ function _rest_get_debug_backtrace_caller(): string { if ( str_starts_with( $next['function'], '{' ) ) { return ' called from (anonymous function)' . $location; } - $caller_func = isset( $next['class'] ) ? $next['class'] . ( $next['type'] ?? '::' ) . $next['function'] : $next['function']; + $caller_func = $next['function']; + if ( isset( $next['class'] ) ) { + $caller_func = $next['class'] . $next['type'] . $caller_func; + } return ' called from ' . $caller_func . '()' . $location; } From 546dc0738faa5c37dff99c5c7b4964fc54dd623c Mon Sep 17 00:00:00 2001 From: Claudio Date: Sun, 14 Jun 2026 12:06:08 +0200 Subject: [PATCH 14/17] Update src/wp-includes/rest-api.php Co-authored-by: Weston Ruter --- src/wp-includes/rest-api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index e8f2df68b566d..8a0a736790230 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -740,8 +740,8 @@ function _rest_get_debug_backtrace_caller(): string { * PHP represents closures as '{closure}' (< 8.4) or '{closure:file:line}' (>= 8.4), * both starting with '{'. These are replaced with a readable label. */ - $next = $backtrace[ $i + 1 ] ?? array(); - if ( ! empty( $next['function'] ) ) { + $next = $backtrace[ $i + 1 ] ?? null; + if ( $next ) { if ( str_starts_with( $next['function'], '{' ) ) { return ' called from (anonymous function)' . $location; } From 8fce388ced2d43634d28ae298e8afbb2018bc790 Mon Sep 17 00:00:00 2001 From: Claudio Date: Sun, 14 Jun 2026 12:06:22 +0200 Subject: [PATCH 15/17] Update src/wp-includes/rest-api.php Co-authored-by: Weston Ruter --- src/wp-includes/rest-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 8a0a736790230..547b5d106e71e 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -717,7 +717,7 @@ function rest_ensure_response( $response ) { * or empty string when no plugin/theme frame is found in the call stack. */ function _rest_get_debug_backtrace_caller(): string { - $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 20 ); + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); $normalized_content_dir = strtolower( trailingslashit( wp_normalize_path( WP_CONTENT_DIR ) ) ); foreach ( $backtrace as $i => $frame ) { From d88a269720d2d9e425b8944dfc4e720e4470c635 Mon Sep 17 00:00:00 2001 From: Claudio Date: Sun, 14 Jun 2026 12:06:44 +0200 Subject: [PATCH 16/17] Update src/wp-includes/rest-api.php Co-authored-by: Weston Ruter --- src/wp-includes/rest-api.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 547b5d106e71e..60aa7cff04e95 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -745,6 +745,15 @@ function _rest_get_debug_backtrace_caller(): string { if ( str_starts_with( $next['function'], '{' ) ) { return ' called from (anonymous function)' . $location; } + + /* + * A call made from a file's global scope has no enclosing function; PHP + * reports the include/require pseudo-function that loaded the file instead. + * In that case only the location is meaningful. + */ + if ( in_array( $next['function'], array( 'require', 'require_once', 'include', 'include_once' ), true ) ) { + return $location; + } $caller_func = $next['function']; if ( isset( $next['class'] ) ) { $caller_func = $next['class'] . $next['type'] . $caller_func; From 2f6ed990c291973411c611a061ea370a6623b717 Mon Sep 17 00:00:00 2001 From: ilclaudio Date: Sun, 14 Jun 2026 17:09:12 +0200 Subject: [PATCH 17/17] REST API: Remove strtolower() from path comparison in _rest_get_debug_backtrace_caller() --- src/wp-includes/rest-api.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 60aa7cff04e95..21d07d5b34ce9 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -718,7 +718,7 @@ function rest_ensure_response( $response ) { */ function _rest_get_debug_backtrace_caller(): string { $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); - $normalized_content_dir = strtolower( trailingslashit( wp_normalize_path( WP_CONTENT_DIR ) ) ); + $normalized_content_dir = trailingslashit( wp_normalize_path( WP_CONTENT_DIR ) ); foreach ( $backtrace as $i => $frame ) { if ( ! isset( $frame['file'] ) ) { @@ -726,7 +726,7 @@ function _rest_get_debug_backtrace_caller(): string { } $normalized_file = wp_normalize_path( $frame['file'] ); - if ( ! str_starts_with( strtolower( $normalized_file ), $normalized_content_dir ) ) { + if ( ! str_starts_with( $normalized_file, $normalized_content_dir ) ) { continue; } @@ -745,7 +745,7 @@ function _rest_get_debug_backtrace_caller(): string { if ( str_starts_with( $next['function'], '{' ) ) { return ' called from (anonymous function)' . $location; } - + /* * A call made from a file's global scope has no enclosing function; PHP * reports the include/require pseudo-function that loaded the file instead.