Skip to content

Instantly share code, notes, and snippets.

@unfulvio
Created July 9, 2014 08:35
Show Gist options
  • Save unfulvio/ea9472bd43b9efbe60cd to your computer and use it in GitHub Desktop.
Save unfulvio/ea9472bd43b9efbe60cd to your computer and use it in GitHub Desktop.
WordPress development: define WP_DEBUG conditionally using cookies
<?php
/**
* Sets a 'wp_debug' cookie for logged in WordPress administrators
* In conjunction with a properly configured wp-config.php, it can enable WP_DEBUG mode conditionally.
*
* @link http://wordpress.stackexchange.com/questions/69549/define-wp-debug-conditionally-for-admins-only-log-errors-append-query-arg-f
*/
function set_admin_debug_cookie( $user_login, $user ) {
if ( in_array( 'administrator', $user->roles ) ) :
setcookie( 'wp_debug', 'on', time() + 86400 );
endif;
}
add_action( 'wp_login', 'set_admin_debug_cookie', 10, 2 );
<?php
// ...
// Place this statement at the end of your wp-config.php file
if( isset( $_COOKIE['wp_debug'] ) && 'on' === $_COOKIE['wp_debug'] ) {
define('WP_DEBUG', true);
} else {
define('WP_DEBUG', false);
}
// ...
@requisite2k
Copy link

Is it possible to write a define statement in wp-config.php that only applies to one website in a multisite environment?

Basically like conditional instructions per website...

e.g. All of website allows for define ( revisions 3 ); but I wan't one of the website's in the multisite environment to have define ( revisions 10 ); that is setup for training.

Any help would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment