Skip to content

Commit

Permalink
fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mte90 committed Nov 10, 2017
1 parent 216344c commit bf658a9
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ Add to your plugin the Debug Bar support (work also on Query Monitor) with a sim
## Example

```php
$debug = new WPBP_Debug( );
$debug = new WPBP_Debug( 'Name of the panel' );
$debug->log( __( 'Plugin Loaded', 'your-textdomain' ) );
```
4 changes: 2 additions & 2 deletions WPBP_Debug_Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class WPBP_Debug_Panel extends Debug_Bar_Panel {
/**
* Register with WordPress API on construct
*/
function __construct( ) {
$this->title( 'Plugin Name Debug' );
function __construct( $title ) {
$this->title( $title );
}

/**
Expand Down
120 changes: 61 additions & 59 deletions debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,74 +8,76 @@
* @copyright 2014
*
*/

if ( !class_exists( 'WPBP_Debug' ) ) {
class WPBP_Debug {

/**
* Instance of this class.
*
* @var object
*
* @since 1.0.0
*/
protected static $instance = null;
class WPBP_Debug {

/**
* Instance of this class.
*
* @var object
*
* @since 1.0.0
*/
protected static $instance = null;

/**
* Check user cap and WP_DEBUG on init to see if class should continue loading
*/
function __construct( $title ) {
if ( !current_user_can( 'manage_options' ) || !WP_DEBUG ) {
return;
}
$this->title = $title;

add_filter( 'debug_bar_panels', array( $this, 'init_panel' ) );
}

/**
* Check user cap and WP_DEBUG on init to see if class should continue loading
*/
function __construct( ) {
if ( !current_user_can( 'manage_options' ) || !WP_DEBUG ) {
return;
}
/**
* Debugs a variable
* Only visible to admins if WP_DEBUG is on
* @param mixed $var The var to debug.
* @param bool $die Whether to die after outputting.
* @param string $function The function to call, usually either print_r or var_dump, but can be anything.
* @return mixed
*/
function log( $var, $die = false, $function = 'var_dump' ) {
if ( !current_user_can( 'manage_options' ) || !WP_DEBUG ) {
return;
}

add_filter( 'debug_bar_panels', array( $this, 'init_panel' ));
}
ob_start();
if ( is_string( $var ) ) {
echo "- " . $var . "\n";
} else {
call_user_func( $function, $var );
}

/**
* Debugs a variable
* Only visible to admins if WP_DEBUG is on
* @param mixed $var The var to debug.
* @param bool $die Whether to die after outputting.
* @param string $function The function to call, usually either print_r or var_dump, but can be anything.
* @return mixed
*/
function log( $var, $die = false, $function = 'var_dump' ) {
if ( !current_user_can( 'manage_options' ) || !WP_DEBUG ) {
return;
}
if ( $die ) {
die();
}

ob_start();
if ( is_string( $var ) ) {
echo "- " . $var . "\n";
} else {
call_user_func( $function, $var );
}
$debug = ob_get_clean();

if ( $die ) {
die();
}
$GLOBALS[ 'WPBP_Debug' ][] = $debug;

$debug = ob_get_clean();
// Allow this to be used as a filter
return $var;
}

$GLOBALS['WPBP_Debug'][] = $debug;
/**
* Extend Debug_Bar_Panel
* @param array $panels The default panels.
* @return array passback The original panels.
*/
function init_panel( $panels ) {
if ( !class_exists( 'WPBP_Debug_Panel' ) ) {
require_once('WPBP_Debug_Panel.php');
$panels[] = new WPBP_Debug_Panel( $this->title );
}
return $panels;
}

// Allow this to be used as a filter
return $var;
}

/**
* Extend Debug_Bar_Panel
* @param array $panels The default panels.
* @return array passback The original panels.
*/
function init_panel( $panels ) {
if ( !class_exists( 'WPBP_Debug_Panel' ) ) {
require_once('WPBP_Debug_Panel.php');
$panels[] = new WPBP_Debug_Panel();
}
return $panels;
}
}

}
}

0 comments on commit bf658a9

Please sign in to comment.