Skip to content

Instantly share code, notes, and snippets.

@jcchikikomori
Created October 10, 2019 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jcchikikomori/7f9cc9600b5330aa19d8b6427517df34 to your computer and use it in GitHub Desktop.
Save jcchikikomori/7f9cc9600b5330aa19d8b6427517df34 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(env('DATABASE_URL'));
$ninja_db_port = $dsn->port;
}
// Connect to the DB and store the link into "$GLOBALS['nfw_mysqli']":
$GLOBALS['nfw_mysqli'] = new mysqli( env('DB_HOST') ?: 'localhost', env('DB_USER'), env('DB_PASSWORD'), env('DB_NAME'), $ninja_db_port);
// We need the table prefix too:
$GLOBALS['nfw_table_prefix'] = env('DB_PREFIX') ?: 'wp_';
$nfw_['DB_NAME'] = env('DB_NAME');
$nfw_['DB_USER'] = env('DB_USER');
$nfw_['DB_PASSWORD'] = env('DB_PASSWORD');
$nfw_['DB_HOST'] = env('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