Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.