Wordpress - Define WP_DEBUG conditionally / for admins only / log errors (append query arg for all links?)

I don't think there is a universal URL hook. There are a lot of hooks and I may have missed it, but I don't think there is one. You can look through the hooks at adambrown.info. There are a lot of URL hooks, but not a universal one.

If I may suggest another solution: Log the errors to a files.

/**
 * This will log all errors notices and warnings to a file called debug.log in
 * wp-content (if Apache does not have write permission, you may need to create
 * the file first and set the appropriate permissions (i.e. use 666) ) 
 */
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors',0);

That code is straight from the Codex for the wp-config.php file. If you do that, you won't have to worry about juggling $_GET or sorting out who is and who isn't an admin.

Edit:

I forgot one possible solution. You can do this with Javascript. A short script could attach your parameter to all the URLs on the page, and you can pretty easily load the script only for admins.

I'd still suggest the 'log' solution since errors for everybody are logged. If your people are like mine and send error 'reports' like "hey, the site is broken when you do that form" you will appreciate the log. :)


Even though my first approach was for the garbage bin and s_ha_dums answer is a clean, and probably the best, way of going about it, let me offer one more working scenario:

The following sets a cookie that is valid for the next 24 hours (86400 seconds) when an administrator logs into the system. In wp-config.php, the constant WP_DEBUG is conditionally defined depending on the presence and value of said cookie.

Caveat: WP_DEBUG will thereafter be set to true for everyone logging in from the same browser on the same machine on the same day.

in functions.php (or as a plugin):

function wpse_69549_admin_debug( $user_login, $user )
{
    if ( in_array( 'administrator', $user->roles ) ) {
        setcookie( 'wp_debug', 'on', time() + 86400, '/', get_site_option( 'siteurl' ) );
    }
}
add_action( 'wp_login', 'wpse_69549_admin_debug', 10, 2 );

See: Codex > Action Reference > wp_login

in wp-config.php:

if ( isset( $_COOKIE['wp_debug'] ) && 'on' === $_COOKIE['wp_debug'] ) {
    define( 'WP_DEBUG', true );
} else {
    define( 'WP_DEBUG', false );
}

It doesn't answer your question precisely, but from personal experience I found it is better to enable debug mode by matching IP address instead of URL.

That requires to modification of links and solves how to identify admin before WP loads required user functionality.