Debug My Plugin 450×450
Debug My Plugin BannerDebug My Plugin In UseDebug My Plugin helper

Debug My Plugin


Add your own debugging messages to the Debug Bar UI.  Use this form to MAKE A DONATION.   It is the same exact plugin you can get for free from the WordPress Plugin Directory.

Donation *

Help support future development!

SKU: DMP Category: Tags: , ,

Product Description

Debug Bar add-on that lets you create your own debug bar output with a few simple commands.  Add a debug lines to your code where you want them and view them in the Debug Bar UI. After a trip to WordCamp I learned about a cool new utility to help tighten up my plugin development, Debug Bar. When I got back home the first thing I did was install Debug Bar. Then installed a dozen other plugins related to Debug Bar.

While many provided some very cool and very useful “inside data” that did help with my plugin development, a key feature I was looking for was missing. I wanted a simple way to add my own personal debugging output to Debug Bar. After a couple of hours of searching I decided I’d write my own.

Now  I can debug any of my plugins with ease.

  • Install Debug Bar.
  • Install Debug My Plugin.
  • Use the Debug My Plugin methods in my code and look at my own internal messages when I need to see what is going on.

[cvg-gallery galleryId=’3′ mode=’showcase’ limit=’5′ /]

Your Dev Helper

You “talk” to this plugin via the DebugMyPlugin global and use that to set properties or invoke methods.

This global, $GLOBALS[‘DebugMyPlugin’], is a named array that starts out with a single panel object called ‘main’.
If you want to, you can just work on this “scratchpad” for output.

This method will output a print_r dump of a variable, like a named array:

$GLOBALS[‘DebugMyPlugin’]->panels[‘main’]->addPR(‘Big Array is now:’,$bigArray,__FILE__,__LINE__);

This method is for simple string based messages, HTML supported:

$GLOBALS['DebugMyPlugin']->panels['main']->addMessage('I Want To Say:','Hello World');

A Class Method For Rendering Debugging

Here is  a simple class method I put into some of my plugins to create a simple interface to Debug My Plugin.  It only outputs debugging content if Debug My Plugin is active, and allows me to do things like $this->render_ToDebugBar(‘main’,’pr’,’Post Vars While Saving’,$_POST);

     * Throw debugging output into Debug My Plugin (3rd party plugin)
     * @param string $panel the panel name, default is 'main'
     * @param string $type the type 'pr' or 'msg'
     * @param string $hdr the message header
     * @param mixed $msg the variable to dump ('pr') or print ('msg')
     * @param string $file __FILE__ from calling location
     * @param string $line __LINE__ from calling location
     * @return null
    function render_ToDebugBar($panel, $type,$hdr,$msg,$file=null,$line=null) {
        if (!isset($GLOBALS['DebugMyPlugin'])) { return; }
        switch ($type) {
            case 'pr':
            case 'msg':

Hooks and Filters


type: action

Called when Debug My Plugin first starts building the panel array. Use this to invoke your own custom panels that extend the main plugin.

Add the following action hook to your code, since you cannot determine when Debug Bar and Debug My Plugin are initialized you should put this outside your init hooks.

Where you throw your AJAX listener hooks may be a good area of the code:

class MyPluginClass {
  static function create_DMPPanels() {
    if (!isset($GLOBALS['DebugMyPlugin'])) { return; }
      $GLOBALS['DebugMyPlugin']->panels['secondary'] = new DebugMyPluginPanel('Additional Debugging');
add_action('dmp_addpanel'       ,array(MyPluginClass,'create_DMPPanels')     );

Once you do this you can now use code like this to put output in the secondary debug bar panel:

$GLOBALS['DebugMyPlugin']->panels['secondary']->addMessage('I Also Want To Say:','Life is good!');


Type: action
[0] - the panel object that fired the action on init

The base panel class that ships with the plugin is named “DebugMyPluginPanel”, which is the tab labelled “My Plugin” by default.

Thus this action hook is called with “dmp_panelinit_DebugMyPluginPanel”.

Note that the action name will change for each class that extends this base class.

For example, if your project extends this class to add a new custom DMP panel like this:

class DMPPanelSLPTag               extends DebugMyPluginPanel {
   function __construct() {
       parent::__construct('SLP Tagalong');

The action would be dmp_panelinit_DMPPanelSLPTag.

This is used in version 0.6+ to turn on REQUEST and other var dumps like this:

    function addMyPanel($panels) {
        // stuff cut out here
        // Add the $_REQUEST dump if desired.
        if (true) {
            add_action('dmp_panelinit_DebugMyPluginPanel', array($this,'action_StartWithRequestVars'));
        // stuff cut out here

     * Start the main panel with a $_REQUEST dump.
     * @param \DebugMyPluginPanel $panelObj
    function action_StartWithRequestVars($panelObj) {

Hack Notes

There is a notable hack in this plugin that impacts Debug Bar. Turns out Debug Bar rendering is called somewhat early in the stack. At the action hook ‘wp_after_admin_bar_render’, as a matter of fact. Problem is, that renders BEFORE admin page contents are rendered. Reading the Action Reference you wouldn’t think that was the case… or I didn’t anyway… but it is.

As such the variables I wanted to see were not dumped to the Debug Bar panel. Thus, I moved Debug Bar render() to the ‘shutdown’ action hook. This runs AFTER the entire admin page is built. Maybe there is a better place to hook it, but for me, that is what worked so that is where it lives. Disable this plugin and the call order goes back to normal.

BTW, you will see some extra errors and warnings because of this, apparently from things that are happening “late in the game” that Debug Bar was sort of glossing over. Doesn’t seem to break anything, but thought you should know. This is a 0.1 release after all!


WordPress 3.5+

Debug Bar 0.5+


There are no reviews yet.

Be the first to review “Debug My Plugin”