start(); add_action('wp_print_footer_scripts', array($this, 'stop'), 99); add_action('admin_footer', array($this, 'stop'), 99); add_action('wp_enqueue_scripts', array($this, 'assets'), 1); add_action('admin_enqueue_scripts', array($this, 'assets'), 1); add_action('login_enqueue_scripts', array($this, 'assets'), 1); add_action('wp_footer', array($this, 'debug_bar'), 999999); add_action('login_footer', array($this, 'debug_bar'), 999999); add_action('admin_footer', array($this, 'debug_bar'), 999999); add_action('check_segment', array($this, 'check_segment'), 10, 2); $this->data = array(); add_action('init', array($this, 'add_filters'), 1); $this->load_tools(); } public function add_filters() { foreach (array('the_content') as $filter) { add_filter($filter, array($this, 'check_filter'), 0); add_filter($filter, array($this, 'check_filter'), 99999); } } public function check_filter($input) { global $wp_current_filter; $current_filter = $wp_current_filter; $current_filter = array_pop($current_filter); $this->check_segment($current_filter); return $input; } public function check_segment($name, $is_done = null) { global $wpdb; $current_filter = $name; if (!isset($this->data[$current_filter])) { $this->data[$current_filter] = array( 'time' => 0, 'time_buffer' => 0, 'queries' => 0, 'queries_buffer' => 0, 'times' => 0, ); } $timestamp = $this->microtime_float(); if ($is_done) { $this->data[$current_filter]['time'] += $timestamp - $this->start; $this->data[$current_filter]['queries'] += $wpdb->num_queries; $this->data[$current_filter]['times']++; return; } if (empty($this->data[$current_filter]['time_buffer'])) { $this->data[$current_filter]['time_buffer'] = $timestamp; $this->data[$current_filter]['queries_buffer'] = $wpdb->num_queries; } else { $this->data[$current_filter]['time'] += $timestamp - $this->data[$current_filter]['time_buffer']; $this->data[$current_filter]['queries'] += $wpdb->num_queries - $this->data[$current_filter]['queries_buffer']; $this->data[$current_filter]['times']++; $this->data[$current_filter]['time_buffer'] = 0; $this->data[$current_filter]['queries_buffer'] = 0; } } public function start() { $this->start = $this->microtime_float(); } public function stop() { $this->stop = $this->microtime_float(); $this->time = $this->stop - $this->start; } public function assets() { wp_enqueue_style('wp-debug-bar', plugin_dir_url(__FILE__) . '/css/style.css', array(), DBT_VERSION, 'screen'); wp_enqueue_script('wp-debug-bar', plugin_dir_url(__FILE__) . '/js/debug.js', array(), DBT_VERSION, true); do_action('debug_tool_assets'); } public function load_tools() { do_action('load_debug_tools'); } public function debug_bar() { global $wpdb; $memory = memory_get_usage ( false ); $memory_unit = ''; if ($memory > 1000) { $memory = $memory / 1000; $memory_unit = 'K'; } if ($memory > 1000) { $memory = $memory / 1000; $memory_unit = 'M'; } ?>
>

Debug bar

time, 3); ?>sImp. time

num_queries; ?> Queries

Memory

× refs = apply_filters('wp_debug_refs', array()); ?>
refs as $ref_key => $ref) { echo '
'.$ref['content'].'
'; } ?>