Skip to content

Instantly share code, notes, and snippets.

@ocean90
Created September 19, 2012 19:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ocean90/3751658 to your computer and use it in GitHub Desktop.
Save ocean90/3751658 to your computer and use it in GitHub Desktop.
WordPress: Print some debug infos into backend footer.
/**
* For site admins: Print some debug infos into backend footer.
* - Time
* - DB Queries
* - Memory Usage
* - Cache Hts/Misses
* - Active Plugins
*
* @param string $text Existing footer text.
*
* @return string Footer text with infos.
*/
function ds_footer_debug_infos( $text ) {
if ( ! is_super_admin() )
return $text;
$text = 'Time : ' . timer_stop( 0 ) . ' | ';
$text .= 'DB Queries: ' . $GLOBALS['wpdb']->num_queries . ' | ';
$text .= 'Memory: ' . number_format( ( memory_get_peak_usage()/1024/1024 ), 1, ',', '' ) . '/' . ini_get( 'memory_limit' ) . ' | ';
$ch = empty( $GLOBALS['wp_object_cache']->cache_hits ) ? 0 : $GLOBALS['wp_object_cache']->cache_hits;
$cm = empty( $GLOBALS['wp_object_cache']->cache_misses ) ? 0 : $GLOBALS['wp_object_cache']->cache_misses;
$text .= 'Cache Hits: ' . $ch . ' | Cache Misses: ' . $cm . ' | ';
$ap = count( get_option('active_plugins') );
$text .= 'Active Plugins: ' . $ap;
return $text;
}
add_filter( 'admin_footer_text', 'ds_footer_debug_infos' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment