Skip to content

Instantly share code, notes, and snippets.

@tonyclemmey
Forked from jcchikikomori/.htninja
Last active January 10, 2022 00:14
Show Gist options
  • Save tonyclemmey/f34efe32c0ec08396ee2ecb12cef5fc9 to your computer and use it in GitHub Desktop.
Save tonyclemmey/f34efe32c0ec08396ee2ecb12cef5fc9 to your computer and use it in GitHub Desktop.
NinjaFirewall config for Bedrock
<?php
/*
+=====================================================================+
| NinjaFirewall optional configuration file |
| |
| See: https://nintechnet.com/ninjafirewall/wp-edition/help/?htninja |
| |
+=====================================================================+
| |
| BEDROCK SUPPORT |
| |
+=====================================================================+
*/
require_once dirname(__DIR__) . '/vendor/autoload.php';
require_once dirname(__DIR__) . '/config/application.php';
$ninja_db_port = 3306;
if (env('DATABASE_URL')) {
$dsn = (object) parse_url(getenv('DATABASE_URL'));
$ninja_db_port = $dsn->port;
}
// Connect to the DB and store the link into "$GLOBALS['nfw_mysqli']":
$GLOBALS['nfw_mysqli'] = new mysqli( getenv('DB_HOST') ?: 'localhost', getenv('DB_USER'), getenv('DB_PASSWORD'), getenv('DB_NAME'), $ninja_db_port);
// We need the table prefix too:
$GLOBALS['nfw_table_prefix'] = getenv('DB_PREFIX') ?: 'wp_';
$nfw_['DB_NAME'] = getenv('DB_NAME');
$nfw_['DB_USER'] = getenv('DB_USER');
$nfw_['DB_PASSWORD'] = getenv('DB_PASSWORD');
$nfw_['DB_HOST'] = getenv('DB_HOST');
$nfw_['table_prefix'] = $GLOBALS['nfw_table_prefix'];
$nfw_['port'] = $ninja_db_port;
// Users of Cloudflare CDN:
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