I am pretty new to plugin authoring and was having a hard time debuging.
I used lots of echo and it is sloppy and ugly.
I am sure there is a better way to do this, maybe an IDE with a debugger that I can run the entire site in including the plugin?
I am pretty new to plugin authoring and was having a hard time debuging.
I used lots of echo and it is sloppy and ugly.
I am sure there is a better way to do this, maybe an IDE with a debugger that I can run the entire site in including the plugin?
You must be logged in to post a comment.
Go into wp-config.php and change
define('WP_DEBUG', false);
todefine('WP_DEBUG', true);
. Also, install Andrew Nacin’s Log Deprecated Notices plugin.If you’re getting errors printed, then x-debug is a brilliant PHP extension that adds modern backtraces to PHP.
If you’re trying to work out what’s going on where there are no errors, my favourite approach is to define a function which logs its output to a file. So I do plog($variable) and that appears in the log file which I can then examine. This is especially useful when you’re trying to work out what happened before header() is called, or other situations where you can’t print to STDOUT.
Use xdebug + NetBeans IDE. When fully configured – which is easy to do – you can set break points in your plugin and watch variables at the break points. I think it is the best way to debug plugins or any php applications for that matter.
After tinkering with a number of IDE’s, I settled into plain old Notepad++ with an ultra-customized Syntax Highlighting color scheme.
I have a macro set up such that when I hit Shift-Ctrl-X , the following code gets output where my cursor is:
It’s simple, but I can generally hunt down 90% of my bugs with this macro plus WP_DEBUG enabled.
I debug the old fashioned way,
error_log()
ing andvar_dump
ing. I find that is the most efficient way for me, I have a couple of wrapper functions to handle different types of data, aserror_log
ing arrays and objects can be a pain. Also, usingprint_r()
in can be tricky to read when it is not in a<pre>
. I havetj_log()
for error logging, andtj()
for showing output (which basically shows any data type in a presentable mannor:So then I just do:
tj( $current_user );
or whatever.I wrote a little class for make a logfile, is very useful when you are debugging ajax calls.
http://github.com/hunk/Magic-Fields/blob/master/tools/debug.php
You only needs do something like:
Debug::log(“This is a debug message”);
When that line is executed a the message will be added in the log file and after that you can use the tail command (if you are using some unix’s style operative system)
tail -f mylogfile.log
If you can pass to this function a array or a object as well.
note you needs change the line 20 for a path where you want save your log file
I use Aptane IDE on Linux and UltraEdit on Windows, and this one also has a PHP-parser. Also, I view all hints from xDebug with the constant
WP_DEBUG
defined inwp-config.php
.See also my post on this topic and feel free to comment and give feedback about your development tools.
I recommend checking out FirePHP. You can send debug info to Firefox’s Firebug over HTTP headers, which usually makes for cleaner debug output.
Not that bad too: Eclipse It’s close to PhpStorm + free.
There are two IDEs I can recommend and I’ve used both extensively: PhpED (Windows only) and PhpStorm+XDEBUG (Mac, Windows and Linux.) I’m on Mac now so can only use the latter.
Both of them ROCK! The good news that PhpStorm is $49 before September 2010 and only $99 after that. If I was on Windows and had to choose again, not sure which I would choose.
Frankly I can’t help but feel that any plugin developer not using one of these two tools is severely handicapped, especially if they are relatively new to developing WordPress plugins.
Krumo – the styled php debug class
Another really nice thing is the “krumo” php class. It’s implemented in ½ min and offers an easy way to debug all sort of variables:
Plus it helps with backtracing, shows loaded classes or included files and everything on demand.
Plus it’s FREE!
Download
Krumo @sourceforge
I use a $13 plugin called LogPress you can buy on ThemeForest and it is an absolute God-send. You can debug everything relating to their plugins and site. Supports Firebug console logging and a whole lot more. I can’t live without it, that is how much I use this plugin.
This plugin is probably the best money I have ever spent and it has saved countless hours in my WordPress plugin development.
I’m using phpED and xdebug but for me (and seems for somebody else) it’s impossible to debug the plugins or theme’s file! The debugger only stops on the breakpoints that are in the main or original “core” files!
anybody can help me?
Firstly I add
define('WP_DEBUG', false);
to the wp-config.php file (as most people have said) to my local install which is a recent copy of a relevant production site (both files and data). This makes stuff quick, safe, separate but reflects well at least one place the plugin will actually be used.I also add the Debug Bar plugin together with some of the some of the Debug Bar add-ons (Transients for example) – as appropriate to your plugins.
I also use the Firebug add-on for Firefox which is excellent for helping track down html, css and JavaScript issues also well for looking into layout weirdness.
I code using UltraEdit which I have used for 15+ years for a whole bunch of coding (php through to SQL) both at work and home and so this works well for me but maybe doesn’t have enough I to rate as an IDE for many folks. It has syntax highlighting, automatic completion and code layout features and a bunch of html and css shortcut tools which can help avoid typos and alike. Mostly this bring familiarity to me which is an important aspect often overlooked in the rush to the new. Muscle memory aids repeatability even in coding.
And of course I usually have some appropriate page from the codex open in another tab on a suitable exemplar.
These all help in different ways to highlight coding, parsing, functional and layout errors and do not interfere much in how I code or if nothing is amiss. Most can be ignored or deactivated for a bit if you’re experimenting or working around something you’ll revisit later.
Oh, and there’s nothing wrong with a well positioned echo or print_r to check something at a key (so long as you remove them when you are done).
Check out Query Monitor combined with Query Monitor Extend for comprehensive debugging of WordPress (PHP errors/notices/stricts/warnings, database queries, paths, constants, HTTP requests, transients, session variables, var dumps).
Also check out All Post Meta and Saving What plugins for specific info on posts.
PHPStorm and Xdebug is a game changing for me for WordPress development. Highly recommend now. Specially with theirs inline debug tools.