Skip to content

Instantly share code, notes, and snippets.

@khoipro
Last active September 11, 2024 01:32
Show Gist options
  • Save khoipro/41f4bc8a9db24f7b53cbfdcefcf1aca4 to your computer and use it in GitHub Desktop.
Save khoipro/41f4bc8a9db24f7b53cbfdcefcf1aca4 to your computer and use it in GitHub Desktop.
Ninjafirewall : Whitelist admin actions and keep original IP with CloudFlare
<?php
/**
* Ninjafirewall Custom Rules
*
* @package codetot-maintenance
* @author codetot
* @since 0.0.1
**/
if ( !empty($_POST['_wpnonce']) && strpos($_SERVER['SCRIPT_NAME'], '/wp-admin/post.php') !== FALSE ) {
return 'ALLOW';
}
if ( !empty($_POST['_wpnonce']) && strpos($_SERVER['SCRIPT_NAME'], '/wp-admin/admin-ajax.php') !== FALSE ) {
return 'ALLOW';
}
if (! empty($_SERVER["HTTP_CF_CONNECTING_IP"]) &&
filter_var($_SERVER["HTTP_CF_CONNECTING_IP"],FILTER_VALIDATE_IP)) {
$_SERVER["REMOTE_ADDR"] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment