Skip to content

Instantly share code, notes, and snippets.

@aydinjavadly
Last active November 6, 2021 13:01
Show Gist options
  • Save aydinjavadly/d40c2132c950ab191fbd4260403223d6 to your computer and use it in GitHub Desktop.
Save aydinjavadly/d40c2132c950ab191fbd4260403223d6 to your computer and use it in GitHub Desktop.
WordPress - Enable WP_DEBUG only for specific IP address.
<?php
/**
* File: wp-config.php
*
* Enable WordPress debug only for your IP address
*
* Once you know your IP address you can edit your wp-config.php file and edit the WP_DEBUG constant and replace it with this function and your IP address.
*
* NOTE: If you re-boot your router and have a dynamic IP address you will need to update your IP address in wp-config.php
*/
// 1. by REMOTE_ADDR (recommended)
if ( !empty($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] == '00.00.00.00' ) {
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
} else {
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', false );
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_LOG', false );
define( 'WP_DEBUG_DISPLAY', false );
}
// 2. by HTTP_X_REAL_IP
if ( !empty($_SERVER['HTTP_X_REAL_IP']) && $_SERVER['HTTP_X_REAL_IP'] == '00.00.00.00' ) {
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
} else {
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', false );
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_LOG', false );
define( 'WP_DEBUG_DISPLAY', false );
}
// 3. by HTTP_CLIENT_IP
if ( !empty($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP'] == '00.00.00.00' ) {
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
} else {
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', false );
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_LOG', false );
define( 'WP_DEBUG_DISPLAY', false );
}
// 4. by HTTP_X_FORWARDED_FOR
if ( !empty($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] == '00.00.00.00' ) {
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
} else {
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', false );
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_LOG', false );
define( 'WP_DEBUG_DISPLAY', false );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment