0 && $ob_level <= $max_clean_level && $clean_attempts < $max_attempts ) { // Check if buffer is still active before attempting to close. if ( ob_get_level() <= 0 ) { break; } // Get buffer contents to verify it's valid before closing. $buffer_content = ob_get_contents(); if ( false === $buffer_content ) { // Invalid buffer, stop trying. break; } // Explicitly close the buffer with error suppression. // We suppress errors because we're checking validity first. @ob_end_clean(); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged // Check new level. $new_level = ob_get_level(); // Safety check: if level didn't decrease or is invalid, we've hit a core buffer - stop. if ( $new_level >= $ob_level || $new_level < 0 ) { break; } $ob_level = $new_level; $clean_attempts++; } } nocache_headers(); status_header( 200 ); header( 'Content-Type: text/plain; charset=utf-8' ); header( 'Cache-Control: no-store, no-cache, must-revalidate, max-age=0' ); header( 'Pragma: no-cache' ); header( 'Expires: 0' ); // ads.txt is a plain text file. Escaping is not required and would break the format. echo rtrim( $code, "\r\n" ) . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped exit; }, 0 );