Skip to content

Commit bf658a9

Browse files
committed
fix #1
1 parent 216344c commit bf658a9

3 files changed

Lines changed: 64 additions & 62 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ Add to your plugin the Debug Bar support (work also on Query Monitor) with a sim
1313
## Example
1414

1515
```php
16-
$debug = new WPBP_Debug( );
16+
$debug = new WPBP_Debug( 'Name of the panel' );
1717
$debug->log( __( 'Plugin Loaded', 'your-textdomain' ) );
1818
```

WPBP_Debug_Panel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class WPBP_Debug_Panel extends Debug_Bar_Panel {
77
/**
88
* Register with WordPress API on construct
99
*/
10-
function __construct( ) {
11-
$this->title( 'Plugin Name Debug' );
10+
function __construct( $title ) {
11+
$this->title( $title );
1212
}
1313

1414
/**

debug.php

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,74 +8,76 @@
88
* @copyright 2014
99
*
1010
*/
11-
1211
if ( !class_exists( 'WPBP_Debug' ) ) {
13-
class WPBP_Debug {
1412

15-
/**
16-
* Instance of this class.
17-
*
18-
* @var object
19-
*
20-
* @since 1.0.0
21-
*/
22-
protected static $instance = null;
13+
class WPBP_Debug {
14+
15+
/**
16+
* Instance of this class.
17+
*
18+
* @var object
19+
*
20+
* @since 1.0.0
21+
*/
22+
protected static $instance = null;
23+
24+
/**
25+
* Check user cap and WP_DEBUG on init to see if class should continue loading
26+
*/
27+
function __construct( $title ) {
28+
if ( !current_user_can( 'manage_options' ) || !WP_DEBUG ) {
29+
return;
30+
}
31+
$this->title = $title;
32+
33+
add_filter( 'debug_bar_panels', array( $this, 'init_panel' ) );
34+
}
2335

24-
/**
25-
* Check user cap and WP_DEBUG on init to see if class should continue loading
26-
*/
27-
function __construct( ) {
28-
if ( !current_user_can( 'manage_options' ) || !WP_DEBUG ) {
29-
return;
30-
}
36+
/**
37+
* Debugs a variable
38+
* Only visible to admins if WP_DEBUG is on
39+
* @param mixed $var The var to debug.
40+
* @param bool $die Whether to die after outputting.
41+
* @param string $function The function to call, usually either print_r or var_dump, but can be anything.
42+
* @return mixed
43+
*/
44+
function log( $var, $die = false, $function = 'var_dump' ) {
45+
if ( !current_user_can( 'manage_options' ) || !WP_DEBUG ) {
46+
return;
47+
}
3148

32-
add_filter( 'debug_bar_panels', array( $this, 'init_panel' ));
33-
}
49+
ob_start();
50+
if ( is_string( $var ) ) {
51+
echo "- " . $var . "\n";
52+
} else {
53+
call_user_func( $function, $var );
54+
}
3455

35-
/**
36-
* Debugs a variable
37-
* Only visible to admins if WP_DEBUG is on
38-
* @param mixed $var The var to debug.
39-
* @param bool $die Whether to die after outputting.
40-
* @param string $function The function to call, usually either print_r or var_dump, but can be anything.
41-
* @return mixed
42-
*/
43-
function log( $var, $die = false, $function = 'var_dump' ) {
44-
if ( !current_user_can( 'manage_options' ) || !WP_DEBUG ) {
45-
return;
46-
}
56+
if ( $die ) {
57+
die();
58+
}
4759

48-
ob_start();
49-
if ( is_string( $var ) ) {
50-
echo "- " . $var . "\n";
51-
} else {
52-
call_user_func( $function, $var );
53-
}
60+
$debug = ob_get_clean();
5461

55-
if ( $die ) {
56-
die();
57-
}
62+
$GLOBALS[ 'WPBP_Debug' ][] = $debug;
5863

59-
$debug = ob_get_clean();
64+
// Allow this to be used as a filter
65+
return $var;
66+
}
6067

61-
$GLOBALS['WPBP_Debug'][] = $debug;
68+
/**
69+
* Extend Debug_Bar_Panel
70+
* @param array $panels The default panels.
71+
* @return array passback The original panels.
72+
*/
73+
function init_panel( $panels ) {
74+
if ( !class_exists( 'WPBP_Debug_Panel' ) ) {
75+
require_once('WPBP_Debug_Panel.php');
76+
$panels[] = new WPBP_Debug_Panel( $this->title );
77+
}
78+
return $panels;
79+
}
6280

63-
// Allow this to be used as a filter
64-
return $var;
65-
}
66-
67-
/**
68-
* Extend Debug_Bar_Panel
69-
* @param array $panels The default panels.
70-
* @return array passback The original panels.
71-
*/
72-
function init_panel( $panels ) {
73-
if ( !class_exists( 'WPBP_Debug_Panel' ) ) {
74-
require_once('WPBP_Debug_Panel.php');
75-
$panels[] = new WPBP_Debug_Panel();
76-
}
77-
return $panels;
78-
}
81+
}
7982

80-
}
8183
}

0 commit comments

Comments
 (0)