Skip to content

Commit 573d073

Browse files
Added "KINT ACTIVE" on admin bar.
1 parent 2d9be60 commit 573d073

File tree

6 files changed

+188
-16
lines changed

6 files changed

+188
-16
lines changed

assets/css/admin-bar.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<style type="text/css">
2+
#wpadminbar {
3+
background-color: %s !important;
4+
}
5+
6+
#wp-admin-bar-environment-notice {
7+
display: none;
8+
}
9+
10+
#wpadminbar .ab-item,
11+
#wpadminbar a.ab-item,
12+
#wpadminbar > #wp-toolbar span.ab-label,
13+
#wpadminbar > #wp-toolbar span.noticon,
14+
.adminbar--environment-notice {
15+
color: #fff;
16+
}
17+
18+
@media only screen and ( min-width: 800px ) {
19+
#wp-admin-bar-environment-notice {
20+
display: block;
21+
}
22+
23+
#wp-admin-bar-environment-notice .ab-item {
24+
background-color: %s !important;
25+
}
26+
27+
#wp-admin-bar-environment-notice:hover .ab-item {
28+
background-color: %s !important;
29+
color: #fff;
30+
}
31+
}
32+
</style>

config/admin-bar.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Admin Bar Runtime Configuration Parameters.
4+
*
5+
* @package KnowTheCode\Kint_PHP_Debugger
6+
* @since 1.2.1
7+
* @author hellofromTonya
8+
* @link https://wordpress.org/plugins/kint-php-debugger/
9+
* @license GNU-2.0+
10+
*/
11+
12+
namespace KnowTheCode\Kint_PHP_Debugger;
13+
14+
return array(
15+
'message' => 'KINT ACTIVE',
16+
'colors' => array(
17+
'admin_bar_background_color' => '#627f00',
18+
'message_background_color' => '#cb4b14',
19+
'message_hover_color' => '#1b202d',
20+
),
21+
);

plugin.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,39 @@
22
/**
33
* Kint PHP Debugger - a modern and powerful PHP debugging helper
44
*
5-
* @package Know_The_Code\Kint_PHP_Debugger
5+
* @package KnowTheCode\Kint_PHP_Debugger
66
* @author hellofromTonya
77
* @license dual license GPL-2.0+ & MIT (Kint is licensed MIT)
8-
* @link https://knowthecode.io/
8+
* @link https://wordpress.org/plugins/kint-php-debugger/
99
*
1010
* @wordpress-plugin
1111
* Plugin Name: Kint PHP Debugger
1212
* Plugin URI: https://github.com/KnowTheCode/kint-php-debugger
1313
* 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.
14-
* Version: 1.2.0
14+
* Version: 1.2.1
1515
* Author: hellofromTonya
16-
* Author URI: https://knowthecode.io/
16+
* Author URI: https://KnowTheCode.io/
1717
* Text Domain: wpkint
1818
* Requires WP: 3.5
1919
* Requires PHP: 5.3
2020
*/
21-
namespace Know_The_Code\Kint_PHP_Debugger;
21+
namespace KnowTheCode\Kint_PHP_Debugger;
2222

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

25-
if ( ! class_exists( 'Kint' ) && is_readable( $pathto_kint ) ) {
26-
require_once $pathto_kint;
28+
/**
29+
* Gets the plugin's root directory.
30+
*
31+
* @since 1.2.1
32+
*
33+
* @return string
34+
*/
35+
function _get_plugin_root_dir() {
36+
return __DIR__;
2737
}
38+
39+
require_once __DIR__ . '/src/kint-php/kint/Kint.class.php';
40+
require_once __DIR__ . '/src/admin-color.php';

readme.txt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://hellofromtonya.com
44
Tags: debug, debugger, kint, var_dump, print_r, backtrace, trace, debug_backtrace
55
Requires at least: 3.5
66
Tested up to: 5.1
7-
Stable tag: 1.2.0
7+
Stable tag: 1.2.1
88
License: GPLv2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010

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

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

27-
Here are some variations of d() to give you the display you want:
26+
Here are some variations of `d()` to give you the display you want:
2827

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

3433
= Profiler =
3534

3635
Kint even includes a naïve profiler, which can help you analyze which blocks of code take longer than others:
36+
3737
`Kint::dump( microtime() ); // just pass microtime()
3838
sleep( 1 );
3939
Kint::dump( microtime(), 'after sleep(1)' );
@@ -42,6 +42,10 @@ ddd( microtime(), 'final call, after sleep(2)' );`
4242

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

45+
== Admin Bar ==
46+
47+
"KINT ACTIVE" indicator displays in the WordPress admin bar to alert you when the plugin is active.
48+
4549
== Installation ==
4650

4751
= From your WordPress dashboard =
@@ -83,10 +87,15 @@ Deactivate and delete this plugin.
8387
== Screenshots ==
8488

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

8893
== ChangeLog ==
8994

95+
= Version 1.2.1 =
96+
97+
* Added "KINT ACTIVE" indicator to the WordPress admin bar to alert the plugin is activated.
98+
9099
= Version 1.2.0 =
91100

92101
* Excluded Composer files.

screenshot-3.png

9.86 KB
Loading

src/admin-color.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Admin functions to change the look of the admin bar when this plugin
4+
* is activated, i.e. to differentiate that we are in development mode.
5+
*
6+
* @package KnowTheCode\Kint_PHP_Debugger
7+
* @since 1.2.1
8+
* @author hellofromTonya
9+
* @link https://wordpress.org/plugins/kint-php-debugger/
10+
* @license GNU-2.0+
11+
*/
12+
13+
namespace KnowTheCode\Kint_PHP_Debugger;
14+
15+
add_filter( 'get_user_option_admin_color', __NAMESPACE__ . '\set_local_development_admin_color_scheme', 5 );
16+
/**
17+
* Force different admin color scheme when this plugin is active.
18+
*
19+
* @since 1.2.1
20+
*
21+
* @return string
22+
*/
23+
function set_local_development_admin_color_scheme() {
24+
return 'coffee';
25+
}
26+
27+
add_action( 'admin_bar_menu', __NAMESPACE__ . '\add_admin_bar_notice', 9999 );
28+
/**
29+
* Add an admin bar notice to alert user that they are in local development
30+
* and this plugin is activated.
31+
*
32+
* @since 1.2.1
33+
*
34+
* @return void
35+
*/
36+
function add_admin_bar_notice() {
37+
if ( ! is_admin_bar_showing() ) {
38+
return;
39+
}
40+
global $wp_admin_bar;
41+
42+
$message = get_admin_bar_config( 'message' );
43+
44+
$admin_notice = array(
45+
'parent' => 'top-secondary',
46+
'id' => 'environment-notice',
47+
'title' => sprintf( '<span class="adminbar--environment-notice">%s</span>', $message ),
48+
);
49+
50+
$wp_admin_bar->add_menu( $admin_notice );
51+
}
52+
53+
add_action( 'admin_head', __NAMESPACE__ . '\render_admin_bar_css', 9999 );
54+
add_action( 'wp_head', __NAMESPACE__ . '\render_admin_bar_css', 9999 );
55+
/**
56+
* Render the admin bar CSS.
57+
*
58+
* @since 1.2.1
59+
*
60+
* @return void
61+
*/
62+
function render_admin_bar_css() {
63+
if ( ! is_admin_bar_showing() ) {
64+
return;
65+
}
66+
67+
ob_start();
68+
69+
include _get_plugin_root_dir() . '/assets/css/admin-bar.php';
70+
71+
$css_pattern = ob_get_clean();
72+
73+
vprintf( $css_pattern, get_admin_bar_config( 'colors' ) );
74+
}
75+
76+
/**
77+
* Get the admin bar's runtime configuration parameter(s).
78+
*
79+
* @since 1.2.1
80+
*
81+
* @param string $parameter
82+
*
83+
* @return array|mixed
84+
*/
85+
function get_admin_bar_config( $parameter = '' ) {
86+
static $config = array();
87+
88+
if ( ! $config ) {
89+
$config = include _get_plugin_root_dir() . '/config/admin-bar.php';
90+
}
91+
92+
if ( $parameter && isset( $config[ $parameter ] ) ) {
93+
return $config[ $parameter ];
94+
}
95+
96+
return $config;
97+
}

0 commit comments

Comments
 (0)