enable_debug_bar() ) { return; } load_plugin_textdomain( 'debug-bar' ); add_action( 'wp_before_admin_bar_render', array( $this, 'wp_before_admin_bar_render' ), 1000000 ); add_action( 'admin_footer', array( $this, 'render' ), 1000 ); add_action( 'wp_footer', array( $this, 'render' ), 1000 ); add_action( 'wp_head', array( $this, 'ensure_ajaxurl' ), 1 ); add_filter( 'body_class', array( $this, 'body_class' ) ); add_filter( 'admin_body_class', array( $this, 'body_class' ) ); $this->requirements(); $this->enqueue(); $this->init_panels(); } /** * Are we on the wp-login.php page? * * We can get here while logged in and break the page as the admin bar * is not shown and other things the js relies on are not available. * * @return bool */ function is_wp_login() { return 'wp-login.php' == basename( $_SERVER['SCRIPT_NAME'] ); } /** * Should the debug bar functionality be enabled? * * @since 0.9 * * @param bool $ajax Whether this is an ajax call or not. Defaults to false. * @return bool */ function enable_debug_bar( $ajax = false ) { $enable = false; if ( $ajax && is_super_admin() ) { $enable = true; } elseif ( ! $ajax && ( is_super_admin() && is_admin_bar_showing() && ! $this->is_wp_login() ) ) { $enable = true; } /** * Allows for overruling of whether the debug bar functionality will be enabled. * * @since 0.9 * * @param bool $enable Whether the debug bar will be enabled or not. */ return apply_filters( 'debug_bar_enable', $enable ); } function init_ajax() { if ( ! $this->enable_debug_bar( true ) ) { return; } $this->requirements(); $this->init_panels(); } function requirements() { $path = plugin_dir_path( __FILE__ ); $recs = array( 'panel', 'php', 'queries', 'request', 'wp-query', 'object-cache', 'deprecated', 'js' ); foreach ( $recs as $rec ) { require_once "$path/panels/class-debug-bar-$rec.php"; } } function enqueue() { $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.dev' : ''; wp_enqueue_style( 'debug-bar', plugins_url( "css/debug-bar$suffix.css", __FILE__ ), array(), '20170515' ); wp_enqueue_script( 'debug-bar', plugins_url( "js/debug-bar$suffix.js", __FILE__ ), array( 'jquery' ), '20170515', true ); do_action( 'debug_bar_enqueue_scripts' ); } function init_panels() { $classes = array( 'Debug_Bar_PHP', 'Debug_Bar_Queries', 'Debug_Bar_WP_Query', 'Debug_Bar_Deprecated', 'Debug_Bar_Request', 'Debug_Bar_Object_Cache', 'Debug_Bar_JS', ); foreach ( $classes as $class ) { $this->panels[] = new $class; } $this->panels = apply_filters( 'debug_bar_panels', $this->panels ); } function ensure_ajaxurl() { ?> = 5.2.0 only function safe_memory_get_peak_usage() { return function_exists( 'memory_get_peak_usage' ) ? memory_get_peak_usage() : memory_get_usage(); } function wp_before_admin_bar_render() { global $wp_admin_bar; $classes = apply_filters( 'debug_bar_classes', array() ); $classes = implode( " ", $classes ); /* Add the main siteadmin menu item */ $wp_admin_bar->add_menu( array( 'id' => 'debug-bar', 'parent' => 'top-secondary', 'title' => apply_filters( 'debug_bar_title', __( 'Debug', 'debug-bar' ) ), 'meta' => array( 'class' => $classes ), ) ); foreach ( $this->panels as $panel_key => $panel ) { $panel->prerender(); if ( ! $panel->is_visible() ) { continue; } $panel_class = get_class( $panel ); $wp_admin_bar->add_menu( array( 'parent' => 'debug-bar', 'id' => "debug-bar-$panel_class", 'title' => $panel->title(), 'href' => '#debug-menu-target-' . esc_attr( $panel_class ), 'meta' => array( 'rel' => '#debug-menu-link-' . esc_attr( $panel_class ), ), ) ); } } function body_class( $classes ) { if ( is_array( $classes ) ) { $classes[] = 'debug-bar-maximized'; } else { $classes .= ' debug-bar-maximized '; } if ( isset( $_GET['debug-bar'] ) ) { if ( is_array( $classes ) ) { $classes[] = 'debug-bar-visible'; } else { $classes .= ' debug-bar-visible '; } } return $classes; } function render() { global $wpdb; if ( empty( $this->panels ) ) { return; } foreach ( $this->panels as $panel_key => $panel ) { $panel->prerender(); if ( ! $panel->is_visible() ) { unset( $this->panels[ $panel_key ] ); } } ?>