How to debug your WordPress plugin

If you are developing a plugin on WordPress, you will need to debug your code as you go.

To enable debugging, go to your wp-config.php file.

Find the line…

define('WP_DEBUG', false);

Replace the line above with the following…

// Turns WordPress debugging on
define('WP_DEBUG', true);

// Tells WordPress to log everything to the /wp-content/debug.log file
define('WP_DEBUG_LOG', true);

// Doesn't force the PHP 'display_errors' variable to be on
define('WP_DEBUG_DISPLAY', false);

// Hides errors from being displayed on-screen
@ini_set('display_errors', 0);

Now you all warnings and errors will show up in the /wp-content/debug.log file, including WordPress warnings of deprecated functions.

You can write directly to this log from your plugin using the error_log() function.

Typically…

//output some debug string
error_log( 'this works yo' );

//output some array/object
error_log( print_r( $some_obj_or_array, 1 ) );

Kudos to this post. It has some good plugin development tips, including how to enable debugging on WordPress.

3 thoughts on “How to debug your WordPress plugin

  1. Eoin,

    First and foremost I apologise as this is completely unrelated to your blog. I’m just trying to get a response by someone at polldaddy/automattic regarding a support ticket request.

    As a desperate attempt to make contact with polldaddy I’m going to go ahead and post my question here and maybe it’ll get through.

    I want to purchase a polldaddy subscription but I’d like to know if I can:

    – set ‘today’ as the default period on the top rated widget.
    – remove the word/title ‘posts’ from the top rated widget when posts is selected.

    Regards,

    David

    1. Hi David, the widget will not let you do this as it is. You are however free to download the plugin and add new settings to the widget to allow it to behave in this manner if you like.

      If you create a patch, I can review and apply it too.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s