|
8 | 8 | * @copyright 2014 |
9 | 9 | * |
10 | 10 | */ |
11 | | - |
12 | 11 | if ( !class_exists( 'WPBP_Debug' ) ) { |
13 | | - class WPBP_Debug { |
14 | 12 |
|
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 | + } |
23 | 35 |
|
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 | + } |
31 | 48 |
|
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 | + } |
34 | 55 |
|
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 | + } |
47 | 59 |
|
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(); |
54 | 61 |
|
55 | | - if ( $die ) { |
56 | | - die(); |
57 | | - } |
| 62 | + $GLOBALS[ 'WPBP_Debug' ][] = $debug; |
58 | 63 |
|
59 | | - $debug = ob_get_clean(); |
| 64 | + // Allow this to be used as a filter |
| 65 | + return $var; |
| 66 | + } |
60 | 67 |
|
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 | + } |
62 | 80 |
|
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 | + } |
79 | 82 |
|
80 | | - } |
81 | 83 | } |
0 commit comments