Skip to content

Commit

Permalink
Added "KINT ACTIVE" on admin bar.
Browse files Browse the repository at this point in the history
  • Loading branch information
hellofromtonya committed Mar 6, 2019
1 parent 2d9be60 commit 573d073
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 16 deletions.
32 changes: 32 additions & 0 deletions assets/css/admin-bar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<style type="text/css">
#wpadminbar {
background-color: %s !important;
}
#wp-admin-bar-environment-notice {
display: none;
}
#wpadminbar .ab-item,
#wpadminbar a.ab-item,
#wpadminbar > #wp-toolbar span.ab-label,
#wpadminbar > #wp-toolbar span.noticon,
.adminbar--environment-notice {
color: #fff;
}
@media only screen and ( min-width: 800px ) {
#wp-admin-bar-environment-notice {
display: block;
}
#wp-admin-bar-environment-notice .ab-item {
background-color: %s !important;
}
#wp-admin-bar-environment-notice:hover .ab-item {
background-color: %s !important;
color: #fff;
}
}
</style>
21 changes: 21 additions & 0 deletions config/admin-bar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Admin Bar Runtime Configuration Parameters.
*
* @package KnowTheCode\Kint_PHP_Debugger
* @since 1.2.1
* @author hellofromTonya
* @link https://wordpress.org/plugins/kint-php-debugger/
* @license GNU-2.0+
*/

namespace KnowTheCode\Kint_PHP_Debugger;

return array(
'message' => 'KINT ACTIVE',
'colors' => array(
'admin_bar_background_color' => '#627f00',
'message_background_color' => '#cb4b14',
'message_hover_color' => '#1b202d',
),
);
29 changes: 21 additions & 8 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,39 @@
/**
* Kint PHP Debugger - a modern and powerful PHP debugging helper
*
* @package Know_The_Code\Kint_PHP_Debugger
* @package KnowTheCode\Kint_PHP_Debugger
* @author hellofromTonya
* @license dual license GPL-2.0+ & MIT (Kint is licensed MIT)
* @link https://knowthecode.io/
* @link https://wordpress.org/plugins/kint-php-debugger/
*
* @wordpress-plugin
* Plugin Name: Kint PHP Debugger
* Plugin URI: https://github.com/KnowTheCode/kint-php-debugger
* Description: Kint is a a modern and powerful PHP debugging helper, which requires zero-setup and replaces var_dump(), print_r() and debug_backtrace(). This plugin is a wrapper for Kint.
* Version: 1.2.0
* Version: 1.2.1
* Author: hellofromTonya
* Author URI: https://knowthecode.io/
* Author URI: https://KnowTheCode.io/
* Text Domain: wpkint
* Requires WP: 3.5
* Requires PHP: 5.3
*/
namespace Know_The_Code\Kint_PHP_Debugger;
namespace KnowTheCode\Kint_PHP_Debugger;

$pathto_kint = trailingslashit( __DIR__ ) . 'src/kint-php/kint/Kint.class.php';
// Bail out if Kint already exists.
if ( class_exists( 'Kint' ) ) {
return;
}

if ( ! class_exists( 'Kint' ) && is_readable( $pathto_kint ) ) {
require_once $pathto_kint;
/**
* Gets the plugin's root directory.
*
* @since 1.2.1
*
* @return string
*/
function _get_plugin_root_dir() {
return __DIR__;
}

require_once __DIR__ . '/src/kint-php/kint/Kint.class.php';
require_once __DIR__ . '/src/admin-color.php';
25 changes: 17 additions & 8 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://hellofromtonya.com
Tags: debug, debugger, kint, var_dump, print_r, backtrace, trace, debug_backtrace
Requires at least: 3.5
Tested up to: 5.1
Stable tag: 1.2.0
Stable tag: 1.2.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -22,18 +22,18 @@ Some handy tools just for the PHP Developer:

* `d( $var );` to render a collapsible UI container which displays your variable data in "the most informative way"
* `ddd( $var );` same as d() except that it also executes `die()` to halt execution.
See the [screenshot 1](http://wordpress.org/extend/plugins/kint-php-debugger/screenshots/) for more details.

Here are some variations of d() to give you the display you want:
Here are some variations of `d()` to give you the display you want:

* '~d( $var );' outputs in plain text format.
* '+d( $var );' disregards depth level limits and outputs everything
* '!d( $var );' shows expanded rich output
* '-d( $var );' attempts to ob_clean() the previous output (dump something inside of HTML)
* `~d( $var );` outputs in plain text format.
* `+d( $var );` disregards depth level limits and outputs everything
* `!d( $var );` shows expanded rich output
* `-d( $var );` attempts to ob_clean() the previous output (dump something inside of HTML)

= Profiler =

Kint even includes a naïve profiler, which can help you analyze which blocks of code take longer than others:

`Kint::dump( microtime() ); // just pass microtime()
sleep( 1 );
Kint::dump( microtime(), 'after sleep(1)' );
Expand All @@ -42,6 +42,10 @@ ddd( microtime(), 'final call, after sleep(2)' );`

See [screenshot 2](http://wordpress.org/extend/plugins/kint-php-debugger/screenshots/) for what is rendered out in your browser.

== Admin Bar ==

"KINT ACTIVE" indicator displays in the WordPress admin bar to alert you when the plugin is active.

== Installation ==

= From your WordPress dashboard =
Expand Down Expand Up @@ -83,10 +87,15 @@ Deactivate and delete this plugin.
== Screenshots ==

1. An example of what gets rendered in the browser when using 'd( $var )'.
2. Profiler example from Kint.
2. Profile example from Kint.
3. "KINT ACTIVE" indicator in the WordPress admin bar.

== ChangeLog ==

= Version 1.2.1 =

* Added "KINT ACTIVE" indicator to the WordPress admin bar to alert the plugin is activated.

= Version 1.2.0 =

* Excluded Composer files.
Expand Down
Binary file added screenshot-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 97 additions & 0 deletions src/admin-color.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* Admin functions to change the look of the admin bar when this plugin
* is activated, i.e. to differentiate that we are in development mode.
*
* @package KnowTheCode\Kint_PHP_Debugger
* @since 1.2.1
* @author hellofromTonya
* @link https://wordpress.org/plugins/kint-php-debugger/
* @license GNU-2.0+
*/

namespace KnowTheCode\Kint_PHP_Debugger;

add_filter( 'get_user_option_admin_color', __NAMESPACE__ . '\set_local_development_admin_color_scheme', 5 );
/**
* Force different admin color scheme when this plugin is active.
*
* @since 1.2.1
*
* @return string
*/
function set_local_development_admin_color_scheme() {
return 'coffee';
}

add_action( 'admin_bar_menu', __NAMESPACE__ . '\add_admin_bar_notice', 9999 );
/**
* Add an admin bar notice to alert user that they are in local development
* and this plugin is activated.
*
* @since 1.2.1
*
* @return void
*/
function add_admin_bar_notice() {
if ( ! is_admin_bar_showing() ) {
return;
}
global $wp_admin_bar;

$message = get_admin_bar_config( 'message' );

$admin_notice = array(
'parent' => 'top-secondary',
'id' => 'environment-notice',
'title' => sprintf( '<span class="adminbar--environment-notice">%s</span>', $message ),
);

$wp_admin_bar->add_menu( $admin_notice );
}

add_action( 'admin_head', __NAMESPACE__ . '\render_admin_bar_css', 9999 );
add_action( 'wp_head', __NAMESPACE__ . '\render_admin_bar_css', 9999 );
/**
* Render the admin bar CSS.
*
* @since 1.2.1
*
* @return void
*/
function render_admin_bar_css() {
if ( ! is_admin_bar_showing() ) {
return;
}

ob_start();

include _get_plugin_root_dir() . '/assets/css/admin-bar.php';

$css_pattern = ob_get_clean();

vprintf( $css_pattern, get_admin_bar_config( 'colors' ) );
}

/**
* Get the admin bar's runtime configuration parameter(s).
*
* @since 1.2.1
*
* @param string $parameter
*
* @return array|mixed
*/
function get_admin_bar_config( $parameter = '' ) {
static $config = array();

if ( ! $config ) {
$config = include _get_plugin_root_dir() . '/config/admin-bar.php';
}

if ( $parameter && isset( $config[ $parameter ] ) ) {
return $config[ $parameter ];
}

return $config;
}

0 comments on commit 573d073

Please sign in to comment.