Skip to content

Instantly share code, notes, and snippets.

@khoipro
Created July 22, 2022 14:53
Show Gist options
  • Save khoipro/3695497c7a3d7edc01fcc3ae045ae757 to your computer and use it in GitHub Desktop.
Save khoipro/3695497c7a3d7edc01fcc3ae045ae757 to your computer and use it in GitHub Desktop.
<?php
function codetot_is_localhost()
{
return !empty($_SERVER['HTTP_X_CODETOT_THEME_HEADER']) && $_SERVER['HTTP_X_CODETOT_THEME_HEADER'] === 'development';
}
function codetot_is_local_dev() {
$is_localhost = azpet_is_localhost();
$domain_name = $_SERVER['HTTP_HOST'] ?? '';
$is_test_domain = !empty($domain_name) && strpos($domain_name, '.test') !== false;
return ($is_localhost || $is_test_domain);
}
add_action('init', 'codetot_warning_missing_wp_debug', 100);
function codetot_warning_missing_wp_debug() {
if (codetot_is_local_dev()) {
if ( !WP_DEBUG ) {
_e('You must enable WP_DEBUG in wp-config.php for local development.');
exit();
}
$current_plugins = get_option( 'active_plugins', array() );
$live_plugins = [
'wp-asset-clean-up/wpacu.php',
'ithemes-security-pro/ithemes-security-pro.php',
'post-smtp/postman-smtp.php',
'honeypot/wp-armour.php',
'updraftplus/updraftplus.php',
'post-smtp/postman-smtp.php',
'perfmatters/perfmatters.php',
'redirection/redirection.php',
'redis-cache/redis-cache.php',
'google-image-sitemap/image-sitemap.php',
'google-sitemap-generator/sitemap.php',
'wpvivid-backup-pro/wpvivid-backup-pro.php',
'wpvivid-backuprestore/wpvivid-backuprestore.php',
'wpvivid-imgoptim/wpvivid-imgoptim.php',
'wordfence/wordfence.php',
'wp-content-copy-protector/preventer-index.php',
'swift-performance-lite/performance.php'
];
$must_deactivate_plugins = [];
foreach ($current_plugins as $plugin) {
if (in_array($plugin, $live_plugins)) {
$must_deactivate_plugins[] = $plugin;
}
}
if ( !empty($must_deactivate_plugins) ) {
_e('To ensure local development work without any changes to live data, some plugins must be force to deactivate. Please refresh this page again to continue your work.', 'nhaphonet');
deactivate_plugins($must_deactivate_plugins);
exit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment