From 0a06f412e2d38ce1e2b3b820408c2b71d144aaf5 Mon Sep 17 00:00:00 2001 From: ilclaudio Date: Wed, 25 Mar 2026 01:18:55 +0100 Subject: [PATCH 1/3] 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 2/3] 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 3/3] 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 ) ); } }