: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
require_once __DIR__ . '/wfCurlInterceptor.php';
public static function get()
if ($instance === null) {
private function __construct()
$rows = $wpdb->get_results("SHOW GRANTS FOR current_user()", ARRAY_N);
foreach ($rows as $row) {
preg_match("/GRANT (.+) ON (.+) TO/", $row[0], $matches);
foreach (explode(",", $matches[1]) as $permission) {
$permission = str_replace(" ", "_", trim(strtolower($permission)));
if ($permission === 'all_privileges') {
foreach ($this as $key => $value) {
if (property_exists($this, $permission))
$this->$permission = true;
protected $minVersion = array(
protected $description = false; //Defined in the constructor to allow for localization
protected $results = array();
public function __construct()
$this->description = array(
'Wordfence Status' => array(
'description' => __('General information about the Wordfence installation.', 'wordfence'),
'wfVersion' => __('Wordfence Version', 'wordfence'),
'geoIPVersion' => __('GeoIP Version', 'wordfence'),
'cronStatus' => __('Cron Status', 'wordfence'),
'description' => __('Ability to read/write various files.', 'wordfence'),
'isPluginReadable' => __('Checking if web server can read from <code>~/plugins/wordfence</code>', 'wordfence'),
'isPluginWritable' => __('Checking if web server can write to <code>~/plugins/wordfence</code>', 'wordfence'),
'isWAFReadable' => __('Checking if web server can read from <code>~/wp-content/wflogs</code>', 'wordfence'),
'isWAFWritable' => __('Checking if web server can write to <code>~/wp-content/wflogs</code>', 'wordfence'),
'Wordfence Config' => array(
'description' => __('Ability to save Wordfence settings to the database.', 'wordfence'),
'configWritableSet' => __('Checking basic config reading/writing', 'wordfence'),
'configWritableSetSer' => __('Checking serialized config reading/writing', 'wordfence'),
'Wordfence Firewall' => array(
'description' => __('Current WAF configuration.', 'wordfence'),
'wafAutoPrepend' => __('WAF auto prepend active', 'wordfence'),
'wafStorageEngine' => __('Configured WAF storage engine (WFWAF_STORAGE_ENGINE)', 'wordfence'),
'wafActiveStorageEngine' => __('Active WAF storage engine', 'wordfence'),
'wafLogPath' => __('WAF log path', 'wordfence'),
'wafSubdirectoryInstall' => __('WAF subdirectory installation', 'wordfence'),
'wafAutoPrependFilePath' => __('wordfence-waf.php path', 'wordfence'),
'wafFilePermissions' => __('WAF File Permissions', 'wordfence'),
'wafRecentlyRemoved' => __('Recently removed wflogs files', 'wordfence'),
'wafLoaded' => __('WAF Loaded Successfully', 'wordfence'),
'wafAutoPrependHtaccess' => __('WAF .htaccess contents', 'wordfence'),
'wafAutoPrependUserIni' => __('WAF .user.ini contents', 'wordfence'),
'wafAutoPrependHtaccessOther' => __('.htaccess other auto prepend', 'wordfence'),
'wafAutoPrependUserIniOther' => __('.user.ini other auto prepend', 'wordfence'),
'description' => __('Database version and privileges.', 'wordfence'),
'databaseVersion' => __('Database Version', 'wordfence'),
'userCanDelete' => __('Checking if MySQL user has <code>DELETE</code> privilege', 'wordfence'),
'userCanInsert' => __('Checking if MySQL user has <code>INSERT</code> privilege', 'wordfence'),
'userCanUpdate' => __('Checking if MySQL user has <code>UPDATE</code> privilege', 'wordfence'),
'userCanSelect' => __('Checking if MySQL user has <code>SELECT</code> privilege', 'wordfence'),
'userCanCreate' => __('Checking if MySQL user has <code>CREATE TABLE</code> privilege', 'wordfence'),
'userCanAlter' => __('Checking if MySQL user has <code>ALTER TABLE</code> privilege', 'wordfence'),
'userCanDrop' => __('Checking if MySQL user has <code>DROP</code> privilege', 'wordfence'),
'userCanTruncate' => __('Checking if MySQL user has <code>TRUNCATE</code> privilege', 'wordfence'),
'PHP Environment' => array(
'description' => __('PHP version, important PHP extensions.', 'wordfence'),
'phpVersion' => array('raw' => true, 'value' => wp_kses(sprintf(/* translators: Support URL. */ __('PHP version >= PHP 5.6.20<br><em> (<a href="https://wordpress.org/about/requirements/" target="_blank" rel="noopener noreferrer">Minimum version required by WordPress</a>)</em> <a href="%s" target="_blank" rel="noopener noreferrer" class="wfhelp"><span class="screen-reader-text"> (opens in new tab)</span></a>', 'wordfence'), wfSupportController::esc_supportURL(wfSupportController::ITEM_VERSION_PHP)), array('a'=>array('href'=>array(), 'target'=>array(), 'rel'=>array(), 'class'=>array()), 'span'=>array('class'=>array())))),
'processOwner' => __('Process Owner', 'wordfence'),
'hasOpenSSL' => __('Checking for OpenSSL support', 'wordfence'),
'openSSLVersion' => __('Checking OpenSSL version', 'wordfence'),
'hasCurl' => __('Checking for cURL support', 'wordfence'),
'curlFeatures' => __('cURL Features Code', 'wordfence'),
'curlHost' => __('cURL Host', 'wordfence'),
'curlProtocols' => __('cURL Support Protocols', 'wordfence'),
'curlSSLVersion' => __('cURL SSL Version', 'wordfence'),
'curlLibZVersion' => __('cURL libz Version', 'wordfence'),
'displayErrors' => array('raw' => true, 'value' => wp_kses(__('Checking <code>display_errors</code><br><em> (<a href="http://php.net/manual/en/errorfunc.configuration.php#ini.display-errors" target="_blank" rel="noopener noreferrer">Should be disabled on production servers<span class="screen-reader-text"> (opens in new tab)</span></a>)</em>', 'wordfence'), array('a'=>array('href'=>array(), 'target'=>array(), 'rel'=>array()), 'span'=>array('class'=>array()), 'em'=>array(), 'code'=>array(), 'br'=>array()))),
'description' => __('Ability to connect to the Wordfence servers and your own site.', 'wordfence'),
'connectToServer2' => __('Connecting to Wordfence servers (https)', 'wordfence'),
'connectToSelf' => __('Connecting back to this site', 'wordfence'),
'connectToSelfIpv6' => array('raw' => true, 'value' => wp_kses(sprintf(__('Connecting back to this site via IPv6 (not required; failure to connect may not be an issue on some sites) <a href="%s" target="_blank" rel="noopener noreferrer" class="wfhelp"><span class="screen-reader-text"> (opens in new tab)</span></a>', 'wordfence'), wfSupportController::esc_supportURL(wfSupportController::ITEM_DIAGNOSTICS_IPV6)), array('a'=>array('href'=>array(), 'target'=>array(), 'rel'=>array(), 'class'=>array()), 'span'=>array('class'=>array())))),
'serverIP' => __('IP(s) used by this server', 'wordfence'),
'description' => __('Server time accuracy and applied offsets.', 'wordfence'),
'wfTime' => __('Wordfence Network Time', 'wordfence'),
'serverTime' => __('Server Time', 'wordfence'),
'wfTimeOffset' => __('Wordfence Network Time Offset', 'wordfence'),
'ntpTimeOffset' => __('NTP Time Offset', 'wordfence'),
'ntpStatus' => __('NTP Status', 'wordfence'),
'timeSourceInUse' => __('TOTP Time Source', 'wordfence'),
'wpTimeZone' => __('WordPress Time Zone', 'wordfence'),
foreach ($this->description as $title => $tests) {
$this->results[$title] = array(
'description' => $tests['description'],
foreach ($tests['tests'] as $name => $description) {
if (!method_exists($this, $name)) {
$result = $this->$name();
'message' => $result ? 'OK' : 'FAIL',
$result['label'] = $description;
$this->results[$title]['results'][] = $result;
public function getResults()
public function wfVersion() {
return array('test' => true, 'message' => WORDFENCE_VERSION . ' (' . WORDFENCE_BUILD_NUMBER . ')');
public function geoIPVersion() {
return array('test' => true, 'infoOnly' => true, 'message' => wfUtils::geoIPVersion());
public function cronStatus() {
$cron = _get_cron_array();
foreach ($cron as $timestamp => $values) {
foreach ($values as $cron_job => $v) {
if (is_numeric($timestamp)) {
if ((time() - 1800) > $timestamp) { $overdue++; }
return array('test' => true, 'infoOnly' => true, 'message' => $overdue ? sprintf(/* translators: Number of jobs. */ _n('%d Job Overdue', '%d Jobs Overdue', $overdue, 'wordfence'), $overdue) : __('Normal', 'wordfence'));
public function geoIPError() {
$error = wfUtils::last_error('geoip');
return array('test' => true, 'infoOnly' => true, 'message' => $error ? $error : __('None', 'wordfence'));
public function isPluginReadable() {
return is_readable(WORDFENCE_PATH);
public function isPluginWritable() {
return is_writable(WORDFENCE_PATH);
public function isWAFReadable() {
if (!is_readable(WFWAF_LOG_PATH)) {
if (defined('WFWAF_STORAGE_ENGINE') && WFWAF_STORAGE_ENGINE == 'mysqli') {
return array('test' => false, 'infoOnly' => true, 'message' => __('No files readable', 'wordfence'));
return array('test' => false, 'message' => __('No files readable', 'wordfence'));
WFWAF_LOG_PATH . 'attack-data.php',
WFWAF_LOG_PATH . 'ips.php',
WFWAF_LOG_PATH . 'config.php',
WFWAF_LOG_PATH . 'rules.php',
$unreadable[] = sprintf(__('File "%s" does not exist', 'wordfence'), basename($f));
else if (!is_readable($f)) {
$unreadable[] = sprintf(/* translators: File path. */ __('File "%s" is unreadable', 'wordfence'), basename($f));
if (count($unreadable) > 0) {
if (defined('WFWAF_STORAGE_ENGINE') && WFWAF_STORAGE_ENGINE == 'mysqli') {
return array('test' => false, 'infoOnly' => true, 'message' => implode(', ', $unreadable));
return array('test' => false, 'message' => implode(', ', $unreadable));
public function isWAFWritable() {
if (!is_writable(WFWAF_LOG_PATH)) {
if (defined('WFWAF_STORAGE_ENGINE') && WFWAF_STORAGE_ENGINE == 'mysqli') {
return array('test' => false, 'infoOnly' => true, 'message' => __('No files writable', 'wordfence'));
return array('test' => false, 'message' => __('No files writable', 'wordfence'));
WFWAF_LOG_PATH . 'attack-data.php',
WFWAF_LOG_PATH . 'ips.php',
WFWAF_LOG_PATH . 'config.php',
WFWAF_LOG_PATH . 'rules.php',
$unwritable[] = sprintf(/* translators: File name. */__('File "%s" does not exist', 'wordfence'), basename($f));
else if (!is_writable($f)) {
$unwritable[] = sprintf(/* translators: File name. */__('File "%s" is unwritable', 'wordfence'), basename($f));
if (count($unwritable) > 0) {
if (defined('WFWAF_STORAGE_ENGINE') && WFWAF_STORAGE_ENGINE == 'mysqli') {
return array('test' => false, 'infoOnly' => true, 'message' => implode(', ', $unwritable));
return array('test' => false, 'message' => implode(', ', $unwritable));
public function databaseVersion() {
$version = $wpdb->get_var("SELECT VERSION()");
return array('test' => true, 'message' => $version);
public function userCanInsert() {
return wfGrant::get()->insert;
public function userCanUpdate() {
return wfGrant::get()->update;
public function userCanDelete() {
return wfGrant::get()->delete;
public function userCanSelect() {
return wfGrant::get()->select;
public function userCanCreate() {
return wfGrant::get()->create;
public function userCanDrop() {
return wfGrant::get()->drop;
public function userCanTruncate() {
return wfGrant::get()->drop && wfGrant::get()->delete;
public function userCanAlter() {
return wfGrant::get()->alter;
public function phpVersion()
'test' => version_compare(phpversion(), $this->minVersion['PHP'], '>='),
'message' => phpversion(),
public function configWritableSet() {
$show = $wpdb->hide_errors();
wfConfig::set('configWritingTest', $val, wfConfig::DONT_AUTOLOAD);
$testVal = wfConfig::get('configWritingTest');
$wpdb->show_errors($show);
'test' => ($val === $testVal),
'message' => __('Basic config writing', 'wordfence')
public function configWritableSetSer() {
$show = $wpdb->hide_errors();
wfConfig::set_ser('configWritingTest_ser', array($val), false, wfConfig::DONT_AUTOLOAD);
$testVal = @array_shift(wfConfig::get_ser('configWritingTest_ser', array(), false));
$wpdb->show_errors($show);
'test' => ($val === $testVal),
'message' => __('Serialized config writing', 'wordfence')
public function wafAutoPrepend() {
return array('test' => true, 'infoOnly' => true, 'message' => (defined('WFWAF_AUTO_PREPEND') && WFWAF_AUTO_PREPEND ? __('Yes', 'wordfence') : __('No', 'wordfence')));
public function wafAutoPrependHtaccess() {
$htaccessPath = wfWAFAutoPrependHelper::getHtaccessPath();
if (!file_exists($htaccessPath)) {
return array('test' => true, 'infoOnly' => true, 'message' => __('(.htaccess not present)', 'wordfence'));
else if (!is_readable($htaccessPath)) {
return array('test' => true, 'infoOnly' => true, 'message' => __('(.htaccess not readable)', 'wordfence'));
$htaccessContents = file_get_contents($htaccessPath);
$section = wfWAFAutoPrependHelper::getHtaccessSectionContent($htaccessContents);
if ($section === false) {
return array('test' => true, 'infoOnly' => true, 'message' => __('(not set)', 'wordfence'));
$snippet = wfUtils::pregExtract("/auto_prepend_file\s+['\"]?[^'\"]*['\"]?/", $section);
return array('test' => true, 'infoOnly' => true, 'message' => $snippet, 'detail' => array('escaped' => nl2br(esc_html($section)), 'textonly' => $section));
public function wafAutoPrependHtaccessOther() {
$htaccessPath = wfWAFAutoPrependHelper::getHtaccessPath();
if (!file_exists($htaccessPath)) {
return array('test' => true, 'infoOnly' => true, 'message' => __('(.htaccess not present)', 'wordfence'));
else if (!is_readable($htaccessPath)) {
return array('test' => true, 'infoOnly' => true, 'message' => __('(.htaccess not readable)', 'wordfence'));
$htaccessContents = file_get_contents($htaccessPath);
$section = wfWAFAutoPrependHelper::getHtaccessSectionContent($htaccessContents);
if ($section !== false) {
$htaccessContents = str_replace($section, '', $htaccessContents);
$snippet = wfUtils::pregExtract("/auto_prepend_file\s+['\"]?[^'\"]*['\"]?/", $htaccessContents, true);
return array('test' => true, 'infoOnly' => true, 'message' => ($snippet === false ? __('(not present)', 'wordfence') : trim($snippet)));
public function wafAutoPrependUserIni() {
$userIniPath = wfWAFAutoPrependHelper::getUserIniPath();
if (!file_exists($userIniPath)) {
return array('test' => true, 'infoOnly' => true, 'message' => __('(.user.ini not present)', 'wordfence'));
else if (!is_readable($userIniPath)) {
return array('test' => true, 'infoOnly' => true, 'message' => __('(.user.ini not readable)', 'wordfence'));
$userIniContents = file_get_contents($userIniPath);
$section = wfWAFAutoPrependHelper::getUserIniSectionContent($userIniContents);
if ($section === false) {
return array('test' => true, 'infoOnly' => true, 'message' => __('(not set)', 'wordfence'));
$snippet = wfUtils::pregExtract("/auto_prepend_file\s*=\s*['\"]?[^'\"]*['\"]?/", $section);
return array('test' => true, 'infoOnly' => true, 'message' => $snippet, 'detail' => $section);
public function wafAutoPrependUserIniOther() {
$userIniPath = wfWAFAutoPrependHelper::getUserIniPath();
if (!file_exists($userIniPath)) {
return array('test' => true, 'infoOnly' => true, 'message' => __('(.user.ini not present)', 'wordfence'));
else if (!is_readable($userIniPath)) {
return array('test' => true, 'infoOnly' => true, 'message' => __('(.user.ini not readable)', 'wordfence'));
$userIniContents = file_get_contents($userIniPath);
$section = wfWAFAutoPrependHelper::getUserIniSectionContent($userIniContents);
if ($section !== false) {
$userIniContents = str_replace($section, '', $userIniContents);
$snippet = wfUtils::pregExtract("/auto_prepend_file\s*=\s*['\"]?[^'\"]*['\"]?/", $userIniContents, true);
return array('test' => true, 'infoOnly' => true, 'message' => ($snippet === false ? __('(not present)', 'wordfence') : trim($snippet)));
public function wafStorageEngine() {
return array('test' => true, 'infoOnly' => true, 'message' => (defined('WFWAF_STORAGE_ENGINE') ? WFWAF_STORAGE_ENGINE : __('(default)', 'wordfence')));
private static function getStorageEngineDescription($storageEngine) {
if ($storageEngine === null) {
return __('None', 'wordfence');
else if (method_exists($storageEngine, 'getDescription')) {
return $storageEngine->getDescription();
return __('Unknown (mixed plugin version)', 'wordfence');
public function wafActiveStorageEngine() {
return array('test' => true, 'infoOnly' => true, 'message' => self::getStorageEngineDescription(wfWAF::getSharedStorageEngine()));
public function wafLogPath() {
$logPath = __('(not set)', 'wordfence');
if (defined('WFWAF_LOG_PATH')) {
$logPath = WFWAF_LOG_PATH;
if (strpos($logPath, ABSPATH) === 0) {
$logPath = '~/' . substr($logPath, strlen(ABSPATH));
return array('test' => true, 'infoOnly' => true, 'message' => $logPath);
public function wafSubdirectoryInstall() {
return array('test' => true, 'infoOnly' => true, 'message' => (defined('WFWAF_SUBDIRECTORY_INSTALL') && WFWAF_SUBDIRECTORY_INSTALL ? __('Yes', 'wordfence') : __('No', 'wordfence')));
public function wafAutoPrependFilePath() {
$path = wordfence::getWAFBootstrapPath();
if (!file_exists($path)) {
return array('test' => true, 'infoOnly' => true, 'message' => $path);
public function wafFilePermissions() {
if (defined('WFWAF_LOG_FILE_MODE')) {
return array('test' => true, 'infoOnly' => true, 'message' => sprintf(/* translators: Unix file permissions in octal (example 0777). */ __('%s - using constant', 'wordfence'), str_pad(decoct(WFWAF_LOG_FILE_MODE), 4, '0', STR_PAD_LEFT)));
if (defined('WFWAF_LOG_PATH')) {
$template = rtrim(WFWAF_LOG_PATH, '/') . '/template.php';
if (file_exists($template)) {
$stat = @stat($template);
if (($mode & 0020) == 0020) {
$updatedMode = $updatedMode | 0060;
return array('test' => true, 'infoOnly' => true, 'message' => sprintf(/* translators: Unix file permissions in octal (example 0777). */ __('%s - using template', 'wordfence'), str_pad(decoct($updatedMode), 4, '0', STR_PAD_LEFT)));