Skip to content

Commit 1c6e7e2

Browse files
kraftbjjomdonnchawp
authored
Fix: hide debug HTML comments in REST and Ajax responses (#1021)
* fix: hide debug HTML comments in REST and Ajax responses * fix: clarify debug comment suppression messages * Extract wpsc_skip_debug_output() to de-duplicate the non-HTML response check The REST/Ajax/JSON/WC bail condition was copy-pasted into both wp_cache_append_tag() and wp_cache_add_to_buffer(). Move it into a single named predicate so the two call sites can't drift, and drop the explanatory comment the inline condition needed. * Also skip debug comments on XML-RPC requests advanced-cache.php already treats XMLRPC_REQUEST as a non-HTML response type; keep wpsc_skip_debug_output() consistent so XML-RPC bodies stay clean regardless of the <html sniff. --------- Co-authored-by: Jake Morrison <68693+jom@users.noreply.github.com> Co-authored-by: Donncha O Caoimh <5656673+donnchawp@users.noreply.github.com>
1 parent 63e2a8a commit 1c6e7e2

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

wp-cache-phase2.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,6 +2196,15 @@ function wp_cache_ob_callback( $buffer ) {
21962196
}
21972197
}
21982198

2199+
function wpsc_skip_debug_output( $buffer ) {
2200+
return strpos( $buffer, '<html' ) === false ||
2201+
( defined( 'REST_REQUEST' ) && REST_REQUEST ) ||
2202+
( defined( 'JSON_REQUEST' ) && JSON_REQUEST ) ||
2203+
( defined( 'WC_API_REQUEST' ) && WC_API_REQUEST ) ||
2204+
( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) ||
2205+
( function_exists( 'wp_doing_ajax' ) && wp_doing_ajax() );
2206+
}
2207+
21992208
function wp_cache_append_tag( &$buffer ) {
22002209
global $wp_cache_gmt_offset, $wp_super_cache_comments;
22012210
global $cache_enabled, $super_cache_enabled;
@@ -2215,7 +2224,7 @@ function wp_cache_append_tag( &$buffer ) {
22152224
$msg = "Live page served on $timestamp";
22162225
}
22172226

2218-
if ( strpos( $buffer, '<html' ) === false ) {
2227+
if ( wpsc_skip_debug_output( $buffer ) ) {
22192228
wp_cache_debug( site_url( $_SERVER['REQUEST_URI'] ) . ' - ' . $msg );
22202229
return false;
22212230
}
@@ -2234,7 +2243,7 @@ function wp_cache_add_to_buffer( &$buffer, $text ) {
22342243
return false;
22352244
}
22362245

2237-
if ( strpos( $buffer, '<html' ) === false ) {
2246+
if ( wpsc_skip_debug_output( $buffer ) ) {
22382247
wp_cache_debug( site_url( $_SERVER['REQUEST_URI'] ) . ' - ' . $text );
22392248
return false;
22402249
}

0 commit comments

Comments
 (0)