Quick Debugging Trick in WordPress

August 5th, 2011 — 1:13am

I always found it a pain when writing new plugins/themes in wordpress to have to turn on or off the WP_DEBUG flag to get errors to show. Plus often times I will be working on a site that others are also viewing or working on, so turning on the flag would disrupt their work. A really simple solution to this problems was to wrap a define statement for the WP_DEBUG flag in an if statement. For example:


if ($_GET['debug'] == 1) {
define("WP_DEBUG", 1);
}
else {
define("WP_DEBUG", 0);
}

The beauty of the code is that you can trigger debugging easily by adding ?debug=1 onto your uri. This saves you from having to change the wp-config.php file, as well as solves the issue of multiple users/developers.

Note this should only be done on a development site. Having this on a live WordPress install could open up your site to be more easily exploiting as you are giving your attackers access to the notifications, warnings and errors.

Category: Short Notes, Wordpress
Tags: , 4 comments »

4 Responses to “Quick Debugging Trick in WordPress”

  1. Michael

    Great tip, thanks!

  2. Michael

    Again thanks for all the help!

  3. Michael

    You the man!

  4. هادی خسروجردی ( hadi khosrojerdi )

    oh, i’m sorry. please remove prev comment.

    if ( current_user_can(‘remove_users’) && isset( $_GET[‘debuge’] ) ) {
    define(“WP_DEBUG”, 1);
    }else{
    define(“WP_DEBUG”, 0);
    }


Leave a Reply



Back to top