Reputation: 1668
I started developing few WordPress plugins on my own. While developing a plugin i am using different hooks(wp_head, add_shortcode, etc) function in the plugin. Can anyone advice me an easy and convenient way to debug a WordPress plugin or is there any other way to develop a WordPress plugin easily. Thanks in advance.
Upvotes: 9
Views: 19385
Reputation: 1004
The Best way is to Download the Plugin Query Monitor
Then you can go ahead and add the line
\do_action('qm/debug', <your_data>);
And this will Log everything in the log section. To open Query Monitor just go to the admin panel and click on top admin bar you'll find some metrics like speed, just click on that.
Upvotes: 0
Reputation: 2841
Using a PHP debugger can be good, but it can also be a bit like "follow the bouncing ball". For simplicity, enable WP_DEBUG and WP_DEBUG_LOG (see Debugging in WordPress) and use the error_log() function to dump useful information to the wp-content/debug.log file.
I tend to prefix log statements with the class method, function, or include file name, so that I know where they've come from. e.g.
error_log(__METHOD__ . ": value = $value");
error_log(__FUNCTION__ . "\n" . print_r($_POST, 1));
ob_start();
var_dump($collection);
error_log(basename(__FILE__) . "\n" . ob_get_clean());
The Debug Bar plugin can also be pretty handy, especially with some of the available add-ons.
Upvotes: 4
Reputation: 3204
The Debug Bar plugin is a great start when combined with turning debug mode and debug logging on in the wp-config.php file.
Debugging In WordPress, debug and debuglog settings
Upvotes: 2
Reputation: 3917
Other things that may be useful to you:
1) Plugins that look for deprecated functions in your code, such as Log Deprecated Calls or Log Deprecated Notices.
2) Setting the WP_DEBUG constant will provide useful information in the PHP log.
Upvotes: 1
Reputation: 5731
For debugging I usually use the standard php function to inspect variables, you know, var_export
and print_r
. If I have a bug that is more difficult to detect, then I use Xdebug: http://xdebug.org/.
In addition, in Wordpress you can use this plugins to log the content of your variables:
Upvotes: 2