Skip to content
This repository has been archived by the owner on Feb 23, 2019. It is now read-only.

Commit

Permalink
Debug Mode Not Working (#405)
Browse files Browse the repository at this point in the history
The "Debug Mode" feature is a great way to help get more information when trying to figure out why a page isn't working.  However, there were a few issues:

1. When using "CDN" or "Minify", and enabling their respective debugging option, those specific debug information summary outputs did not display in the page footer.

2. If a user had opted to support W3TC (via the admin popup, a string can get assigned to "common.support" or a boolean of "true" can be assigned to "common.tweeted") and then decided to use the debug mode, no debug information would show in the footer for any caching feature. When supporting W3TC the intention is to only hide the:  "Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/products/" text display line that appears in page footers for users who have not opted into supporting W3TC, but by doing so it incorrectly also took away the debug information entirely (if debug mode was used) for those who did opt-in.

Both problems outlined above are now fixed in this patch.
  • Loading branch information
amiga-500 authored Feb 21, 2017
1 parent 143b723 commit 9eb5250
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 41 deletions.
21 changes: 13 additions & 8 deletions Cdn_Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ function run() {
'cron_schedules'
) );

if ( !$this->_config->get_boolean( 'cdn.debug' ) )
add_filter( 'w3tc_footer_comment', array(
$this,
'w3tc_footer_comment'
) );
add_filter( 'w3tc_footer_comment', array(
$this,
'w3tc_footer_comment'
) );

if ( !Cdn_Util::is_engine_mirror( $cdn_engine ) ) {
add_action( 'delete_attachment', array(
Expand Down Expand Up @@ -725,16 +724,19 @@ public function w3tc_footer_comment( $strings ) {
$cdn = $common->get_cdn();
$via = $cdn->get_via();

$strings[] = sprintf(
$comment = sprintf(
__( 'Content Delivery Network via %s%s', 'w3-total-cache' ),
( $via ? $via : 'N/A' ),
( empty( $this->cdn_reject_reason ) ? '' :
sprintf( ' (%s)', $this->cdn_reject_reason ) ) );

if ( $this->_config->get_boolean( 'cdn.debug' ) ) {
$strings[] = "~~~~~~~~~~~~~~~~~~~~~~~~~~";
$strings[] = "CDN debug info:";
$strings[] = sprintf( "%s%s", str_pad( 'Engine: ', 20 ),
$this->_config->get_string( 'cdn.engine' ) );
$strings[] = "~~~~~~~~~~~~~~~~~~~~~~~~~~";
$strings[] = sprintf( "%s%s via %s", str_pad( 'Engine: ', 20 ),
$this->_config->get_string( 'cdn.engine' ),
( $via ? $via : 'N/A' ) );

if ( $this->cdn_reject_reason ) {
$strings[] = sprintf( "%s%s", str_pad( 'Reject reason: ', 20 ),
Expand All @@ -750,6 +752,9 @@ public function w3tc_footer_comment( $strings ) {
Util_Content::escape_comment( $new_url ) );
}
}
} elseif ( $this->_config->get_string( 'common.support' ) == '' &&
!$this->_config->get_boolean( 'common.tweeted' ) ){
$strings[] = $comment;
}

return $strings;
Expand Down
5 changes: 4 additions & 1 deletion DbCache_WpdbInjection_QueryCaching.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,9 @@ private function _get_reject_reason_message( $key ) {

public function w3tc_footer_comment( $strings ) {
if ( $this->debug ) {
$strings[] = "~~~~~~~~~~~~~~~~~~~~~~~~~~";
$strings[] = "Db cache debug info:";
$strings[] = "~~~~~~~~~~~~~~~~~~~~~~~~~~";
$strings[] = sprintf( "%s%s", str_pad( 'Engine: ', 20 ), Cache::engine_name( $this->_config->get_string( 'dbcache.engine' ) ) );
$strings[] = sprintf( "%s%d", str_pad( 'Total queries: ', 20 ), $this->query_total );
$strings[] = sprintf( "%s%d", str_pad( 'Cached queries: ', 20 ), $this->query_hits );
Expand All @@ -639,7 +641,8 @@ public function w3tc_footer_comment( $strings ) {
trim( $query['query'] ) );
}
}
} else {
} elseif ( $this->_config->get_string( 'common.support' ) == '' &&
!$this->_config->get_boolean( 'common.tweeted' ) ){
$reason = $this->get_reject_reason();
$append = ( $reason ? sprintf( ' (%s)', $reason ) : '' );

Expand Down
2 changes: 2 additions & 0 deletions Extension_FragmentCache_WpObjectCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ function _can_cache() {
*/
public function w3tc_footer_comment( $strings ) {
if ( $this->_config->get_boolean( array( 'fragmentcache', 'debug' ) ) ) {
$strings[] = "~~~~~~~~~~~~~~~~~~~~~~~~~~";
$strings[] = "Fragment Cache debug info:";
$strings[] = "~~~~~~~~~~~~~~~~~~~~~~~~~~";
$strings[] = sprintf( "%s%s", str_pad( 'Engine: ', 20 ), Cache::engine_name( $this->_config->get_string( array( 'fragmentcache', 'engine' ) ) ) );
$strings[] = sprintf( "%s%s", str_pad( 'Caching: ', 20 ), ( $this->_caching ? 'enabled' : 'disabled' ) );

Expand Down
41 changes: 21 additions & 20 deletions Generic_Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,28 +490,29 @@ function ob_callback( $buffer ) {
if ( Util_Environment::is_preview_mode() )
$buffer .= "\r\n<!-- W3 Total Cache used in preview mode -->";

if ( $this->_config->get_string( 'common.support' ) != '' ||
$this->_config->get_boolean( 'common.tweeted' ) ) {
$buffer .= sprintf( "\r\n<!-- Served from: %s @ %s by W3 Total Cache -->",
Util_Content::escape_comment( $host ), $date );
} else {
$strings = array();
$strings = apply_filters( 'w3tc_footer_comment', $strings );

$buffer .= "\r\n<!-- Performance optimized by W3 Total Cache. Learn more: https://www.w3-edge.com/products/\r\n";

if ( count( $strings ) ) {
$buffer .= "\r\n" .
Util_Content::escape_comment( implode( "\r\n", $strings ) ) .
"\r\n";
}

$buffer .= sprintf( "\r\n Served from: %s @ %s by W3 Total Cache -->", Util_Content::escape_comment( $host ), $date );
}
$buffer .= "\r\n<!--\r\n";

$strings = array();
$strings = apply_filters( 'w3tc_footer_comment', $strings );

if ( $this->_config->get_string( 'common.support' ) == '' &&
!$this->_config->get_boolean( 'common.tweeted' ) ) {
$buffer .= "Performance optimized by W3 Total Cache. Learn more: https://www.w3-edge.com/products/\r\n";
if ( count( $strings ) ) {
$buffer .= "\r\n";
}
}

if ( count( $strings ) ) {
$buffer .= Util_Content::escape_comment( implode( "\r\n", $strings ) ) . "\r\n\r\n";
}

$buffer .= sprintf( "Served from: %s @ %s by W3 Total Cache\r\n-->",
Util_Content::escape_comment( $host ), $date );

$buffer = apply_filters( 'w3tc_process_content', $buffer );
}
}

$buffer = Util_Bus::do_ob_callbacks(
array( 'minify', 'newrelic', 'cdn', 'browsercache', 'pagecache' ),
$buffer );
Expand Down
16 changes: 10 additions & 6 deletions Minify_Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ function run() {
add_filter( 'w3tc_admin_bar_menu',
array( $this, 'w3tc_admin_bar_menu' ) );

if ( !$this->_config->get_boolean( 'minify.debug' ) )
add_filter( 'w3tc_footer_comment', array(
$this,
'w3tc_footer_comment'
) );
add_filter( 'w3tc_footer_comment', array(
$this,
'w3tc_footer_comment'
) );

if ( $this->_config->get_string( 'minify.engine' ) == 'file' ) {
add_action( 'w3_minify_cleanup', array(
Expand Down Expand Up @@ -420,15 +419,17 @@ public function w3tc_admin_bar_menu( $menu_items ) {
}

function w3tc_footer_comment( $strings ) {
$strings[] = sprintf(
$comment = sprintf(
__( 'Minified using %s%s', 'w3-total-cache' ),
Cache::engine_name( $this->_config->get_string( 'minify.engine' ) ),
( $this->minify_reject_reason != ''
? sprintf( ' (%s)', $this->minify_reject_reason )
: '' ) );

if ( $this->_config->get_boolean( 'minify.debug' ) ) {
$strings[] = "~~~~~~~~~~~~~~~~~~~~~~~~~~";
$strings[] = "Minify debug info:";
$strings[] = "~~~~~~~~~~~~~~~~~~~~~~~~~~";
$strings[] = sprintf( "%s%s", str_pad( 'Engine: ', 20 ), Cache::engine_name( $this->_config->get_string( 'minify.engine' ) ) );
$strings[] = sprintf( "%s%s", str_pad( 'Theme: ', 20 ), $this->get_theme() );
$strings[] = sprintf( "%s%s", str_pad( 'Template: ', 20 ), $this->get_template() );
Expand Down Expand Up @@ -456,6 +457,9 @@ function w3tc_footer_comment( $strings ) {
$strings[] = sprintf( "%d. %s\r\n", $index + 1, Util_Content::escape_comment( $file ) );
}
}
} elseif ( $this->_config->get_string( 'common.support' ) == '' &&
!$this->_config->get_boolean( 'common.tweeted' ) ){
$strings[] = $comment;
}

return $strings;
Expand Down
9 changes: 6 additions & 3 deletions ObjectCache_WpObjectCache_Regular.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ function flush( $reason = '' ) {

if ( $this->_debug ) {
$this->debug_info[] = array(
'id' => $id,
'group' => $group,
'id' => '',
'group' => '',
'operation' => 'flush',
'returned' => $reason,
'data_size' => 0,
Expand Down Expand Up @@ -841,7 +841,9 @@ private function _is_transient_group( $group ) {

public function w3tc_footer_comment( $strings ) {
if ( $this->_config->get_boolean( 'objectcache.debug' ) ) {
$strings[] = "~~~~~~~~~~~~~~~~~~~~~~~~~~";
$strings[] = "Object Cache debug info:";
$strings[] = "~~~~~~~~~~~~~~~~~~~~~~~~~~";
$strings[] = sprintf( "%s%s", str_pad( 'Engine: ', 20 ), Cache::engine_name( $this->_config->get_string( 'objectcache.engine' ) ) );
$strings[] = sprintf( "%s%s", str_pad( 'Caching: ', 20 ), ( $this->_caching ? 'enabled' : 'disabled' ) );

Expand Down Expand Up @@ -874,7 +876,8 @@ public function w3tc_footer_comment( $strings ) {
str_pad( $debug['group'], 15, ' ', STR_PAD_LEFT ),
$debug['id'] );
}
} else {
} elseif ( $this->_config->get_string( 'common.support' ) == '' &&
!$this->_config->get_boolean( 'common.tweeted' ) ){
$reason = $this->get_reject_reason();
$append = ( $reason != '' ? sprintf( ' (%s)', $reason ) : '' );

Expand Down
10 changes: 7 additions & 3 deletions PgCache_ContentGrabber.php
Original file line number Diff line number Diff line change
Expand Up @@ -1349,18 +1349,19 @@ function _get_page_key( $mobile_group = '', $referrer_group = '',
* @return string
*/
public function w3tc_footer_comment( $strings ) {
$strings[] = sprintf(
$comment = sprintf(
__( 'Page Caching using %s%s', 'w3-total-cache' ),
Cache::engine_name( $this->_config->get_string( 'pgcache.engine' ) ),
( $this->cache_reject_reason != ''
? sprintf( ' (%s)', $this->cache_reject_reason )
: '' ) );


if ( $this->_debug ) {
$time_total = Util_Debug::microtime() - $this->_time_start;
$engine = $this->_config->get_string( 'pgcache.engine' );
$strings[] = "~~~~~~~~~~~~~~~~~~~~~~~~~~";
$strings[] = "Page cache debug info:";
$strings[] = "~~~~~~~~~~~~~~~~~~~~~~~~~~";
$strings[] = sprintf( "%s%s", str_pad( 'Engine: ', 20 ), Cache::engine_name( $engine ) );
$strings[] = sprintf( "%s%s", str_pad( 'Cache key: ', 20 ), $this->_page_key );

Expand All @@ -1379,9 +1380,12 @@ public function w3tc_footer_comment( $strings ) {
foreach ( $headers['plain'] as $i ) {
$strings[] = sprintf( "%s%s",
str_pad( $i['name'] . ': ', 20 ),
Util_Content::escape_comment( $i['value'] ) );
Util_Content::escape_comment( trim( $i['value'] ) ) );
}
}
} elseif ( $this->_config->get_string( 'common.support' ) == '' &&
!$this->_config->get_boolean( 'common.tweeted' ) ){
$strings[] = $comment;
}

return $strings;
Expand Down

0 comments on commit 9eb5250

Please sign in to comment.