Skip to content

Commit 2ac3825

Browse files
committed
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.
1 parent b86fa97 commit 2ac3825

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

wp-cache-phase2.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,14 @@ function wp_cache_ob_callback( $buffer ) {
21912191
}
21922192
}
21932193

2194+
function wpsc_skip_debug_output( $buffer ) {
2195+
return strpos( $buffer, '<html' ) === false ||
2196+
( defined( 'REST_REQUEST' ) && REST_REQUEST ) ||
2197+
( defined( 'JSON_REQUEST' ) && JSON_REQUEST ) ||
2198+
( defined( 'WC_API_REQUEST' ) && WC_API_REQUEST ) ||
2199+
( function_exists( 'wp_doing_ajax' ) && wp_doing_ajax() );
2200+
}
2201+
21942202
function wp_cache_append_tag( &$buffer ) {
21952203
global $wp_cache_gmt_offset, $wp_super_cache_comments;
21962204
global $cache_enabled, $super_cache_enabled;
@@ -2210,14 +2218,7 @@ function wp_cache_append_tag( &$buffer ) {
22102218
$msg = "Live page served on $timestamp";
22112219
}
22122220

2213-
// Don't append debug HTML comments to non-HTML responses (REST, Ajax, etc.).
2214-
if (
2215-
strpos( $buffer, '<html' ) === false ||
2216-
( defined( 'REST_REQUEST' ) && REST_REQUEST ) ||
2217-
( defined( 'JSON_REQUEST' ) && JSON_REQUEST ) ||
2218-
( defined( 'WC_API_REQUEST' ) && WC_API_REQUEST ) ||
2219-
( function_exists( 'wp_doing_ajax' ) && wp_doing_ajax() )
2220-
) {
2221+
if ( wpsc_skip_debug_output( $buffer ) ) {
22212222
wp_cache_debug( site_url( $_SERVER['REQUEST_URI'] ) . ' - ' . $msg );
22222223
return false;
22232224
}
@@ -2236,14 +2237,7 @@ function wp_cache_add_to_buffer( &$buffer, $text ) {
22362237
return false;
22372238
}
22382239

2239-
// Don't append debug HTML comments to non-HTML responses (REST, Ajax, etc.).
2240-
if (
2241-
strpos( $buffer, '<html' ) === false ||
2242-
( defined( 'REST_REQUEST' ) && REST_REQUEST ) ||
2243-
( defined( 'JSON_REQUEST' ) && JSON_REQUEST ) ||
2244-
( defined( 'WC_API_REQUEST' ) && WC_API_REQUEST ) ||
2245-
( function_exists( 'wp_doing_ajax' ) && wp_doing_ajax() )
2246-
) {
2240+
if ( wpsc_skip_debug_output( $buffer ) ) {
22472241
wp_cache_debug( site_url( $_SERVER['REQUEST_URI'] ) . ' - ' . $text );
22482242
return false;
22492243
}

0 commit comments

Comments
 (0)