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.
Leave a Reply
You must be logged in to post a comment.
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.
The Debug Bar plugin can also be pretty handy, especially with some of the available add-ons.
For debugging I usually use the standard php function to inspect variables, you know,
var_export
andprint_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:
The Debug Bar plugin is a great start when combined with turning debug mode and debug logging on in the wp-config.php file.
Debug Bar
Debugging In WordPress, debug and debuglog settings
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.
The Best way is to Download the Plugin Query Monitor
Then you can go ahead and add the line
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.