: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
const TABLE_EXISTS_OPTION = 'wordfence_installed'; //Also exists in bootstrap.php
const DONT_AUTOLOAD = 'no';
const TYPE_BOOL = 'boolean';
const TYPE_INT = 'integer';
const TYPE_FLOAT = 'double';
const TYPE_DOUBLE = 'double';
const TYPE_STRING = 'string';
const TYPE_ARRAY = 'array';
const TYPE_JSON = 'json';
const OPTIONS_TYPE_GLOBAL = 'global';
const OPTIONS_TYPE_FIREWALL = 'firewall';
const OPTIONS_TYPE_BLOCKING = 'blocking';
const OPTIONS_TYPE_SCANNER = 'scanner';
const OPTIONS_TYPE_TWO_FACTOR = 'twofactor';
const OPTIONS_TYPE_LIVE_TRAFFIC = 'livetraffic';
const OPTIONS_TYPE_DIAGNOSTICS = 'diagnostics';
const OPTIONS_TYPE_ALL = 'all';
public static $diskCache = array();
private static $diskCacheDisabled = false; //enables if we detect a write fail so we don't keep calling stat()
private static $cacheDisableCheckDone = false;
private static $tableExists = true;
private static $cache = array();
private static $DB = false;
private static $tmpFileHeader = "<?php\n/* Wordfence temporary file security header */\necho \"Nothing to see here!\\n\"; exit(0);\n?>";
private static $tmpDirCache = false;
public static $defaultConfig = array(
//All exportable boolean options
"alertOn_update" => array('value' => false, 'autoload' => self::AUTOLOAD),
"alertOn_scanIssues" => array('value' => true, 'autoload' => self::AUTOLOAD),
"alertOn_throttle" => array('value' => false, 'autoload' => self::AUTOLOAD),
"alertOn_block" => array('value' => true, 'autoload' => self::AUTOLOAD),
"alertOn_loginLockout" => array('value' => true, 'autoload' => self::AUTOLOAD),
'alertOn_breachLogin' => array('value' => true, 'autoload' => self::AUTOLOAD),
"alertOn_lostPasswdForm" => array('value' => true, 'autoload' => self::AUTOLOAD),
"alertOn_adminLogin" => array('value' => true, 'autoload' => self::AUTOLOAD),
"alertOn_firstAdminLoginOnly" => array('value' => false, 'autoload' => self::AUTOLOAD),
"alertOn_nonAdminLogin" => array('value' => false, 'autoload' => self::AUTOLOAD),
"alertOn_firstNonAdminLoginOnly" => array('value' => false, 'autoload' => self::AUTOLOAD),
"alertOn_wordfenceDeactivated" => array('value' => true, 'autoload' => self::AUTOLOAD),
"alertOn_wafDeactivated" => array('value' => true, 'autoload' => self::AUTOLOAD),
"liveTrafficEnabled" => array('value' => false, 'autoload' => self::AUTOLOAD),
"advancedCommentScanning" => array('value' => true, 'autoload' => self::AUTOLOAD),
"checkSpamIP" => array('value' => true, 'autoload' => self::AUTOLOAD),
"spamvertizeCheck" => array('value' => true, 'autoload' => self::AUTOLOAD),
"liveTraf_ignorePublishers" => array('value' => true, 'autoload' => self::AUTOLOAD),
"liveTraf_displayExpandedRecords" => array('value' => false, 'autoload' => self::DONT_AUTOLOAD),
"scheduledScansEnabled" => array('value' => true, 'autoload' => self::AUTOLOAD),
"lowResourceScansEnabled" => array('value' => false, 'autoload' => self::AUTOLOAD),
"scansEnabled_checkGSB" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_checkHowGetIPs" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_core" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_themes" => array('value' => false, 'autoload' => self::AUTOLOAD),
"scansEnabled_plugins" => array('value' => false, 'autoload' => self::AUTOLOAD),
"scansEnabled_coreUnknown" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_malware" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_fileContents" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_fileContentsGSB" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_checkReadableConfig" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_suspectedFiles" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_posts" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_comments" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_suspiciousOptions" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_passwds" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_diskSpace" => array('value' => true, 'autoload' => self::AUTOLOAD),
'scansEnabled_wafStatus' => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_options" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_wpscan_fullPathDisclosure" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_wpscan_directoryListingEnabled" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_scanImages" => array('value' => false, 'autoload' => self::AUTOLOAD),
"scansEnabled_highSense" => array('value' => false, 'autoload' => self::AUTOLOAD),
"scansEnabled_oldVersions" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scansEnabled_suspiciousAdminUsers" => array('value' => true, 'autoload' => self::AUTOLOAD),
"scan_force_ipv4_start" => array('value' => false, 'autoload' => self::AUTOLOAD),
"liveActivityPauseEnabled" => array('value' => true, 'autoload' => self::AUTOLOAD),
"firewallEnabled" => array('value' => true, 'autoload' => self::AUTOLOAD),
"autoBlockScanners" => array('value' => true, 'autoload' => self::AUTOLOAD),
"loginSecurityEnabled" => array('value' => true, 'autoload' => self::AUTOLOAD),
"loginSec_strongPasswds_enabled" => array('value' => true, 'autoload' => self::AUTOLOAD),
"loginSec_breachPasswds_enabled" => array('value' => true, 'autoload' => self::AUTOLOAD),
"loginSec_lockInvalidUsers" => array('value' => false, 'autoload' => self::AUTOLOAD),
"loginSec_maskLoginErrors" => array('value' => true, 'autoload' => self::AUTOLOAD),
"loginSec_blockAdminReg" => array('value' => true, 'autoload' => self::AUTOLOAD),
"loginSec_disableAuthorScan" => array('value' => true, 'autoload' => self::AUTOLOAD),
"loginSec_disableApplicationPasswords" => array('value' => true, 'autoload' => self::AUTOLOAD),
"loginSec_disableOEmbedAuthor" => array('value' => false, 'autoload' => self::AUTOLOAD),
'loginSec_requireAdminTwoFactor' => array('value' => false, 'autoload' => self::AUTOLOAD),
"notification_updatesNeeded" => array('value' => true, 'autoload' => self::AUTOLOAD),
"notification_securityAlerts" => array('value' => true, 'autoload' => self::AUTOLOAD),
"notification_promotions" => array('value' => true, 'autoload' => self::AUTOLOAD),
"notification_blogHighlights" => array('value' => true, 'autoload' => self::AUTOLOAD),
"notification_productUpdates" => array('value' => true, 'autoload' => self::AUTOLOAD),
"notification_scanStatus" => array('value' => true, 'autoload' => self::AUTOLOAD),
"enableRemoteIpLookup" => array('value' => true, 'autoload' => self::AUTOLOAD),
"other_hideWPVersion" => array('value' => false, 'autoload' => self::AUTOLOAD),
"other_blockBadPOST" => array('value' => false, 'autoload' => self::AUTOLOAD),
"other_scanComments" => array('value' => true, 'autoload' => self::AUTOLOAD),
"other_pwStrengthOnUpdate" => array('value' => true, 'autoload' => self::AUTOLOAD),
"other_WFNet" => array('value' => true, 'autoload' => self::AUTOLOAD),
"other_scanOutside" => array('value' => false, 'autoload' => self::AUTOLOAD),
"other_bypassLitespeedNoabort" => array('value' => false, 'autoload' => self::AUTOLOAD),
"deleteTablesOnDeact" => array('value' => false, 'autoload' => self::AUTOLOAD),
"autoUpdate" => array('value' => false, 'autoload' => self::AUTOLOAD),
"startScansRemotely" => array('value' => false, 'autoload' => self::AUTOLOAD),
"disableConfigCaching" => array('value' => false, 'autoload' => self::AUTOLOAD),
"addCacheComment" => array('value' => false, 'autoload' => self::AUTOLOAD),
"disableCodeExecutionUploads" => array('value' => false, 'autoload' => self::AUTOLOAD),
"allowHTTPSCaching" => array('value' => false, 'autoload' => self::AUTOLOAD),
"debugOn" => array('value' => false, 'autoload' => self::AUTOLOAD),
'email_summary_enabled' => array('value' => true, 'autoload' => self::AUTOLOAD),
'email_summary_dashboard_widget_enabled' => array('value' => true, 'autoload' => self::AUTOLOAD),
'ssl_verify' => array('value' => true, 'autoload' => self::AUTOLOAD),
'ajaxWatcherDisabled_front' => array('value' => false, 'autoload' => self::AUTOLOAD),
'ajaxWatcherDisabled_admin' => array('value' => false, 'autoload' => self::AUTOLOAD),
'wafAlertOnAttacks' => array('value' => true, 'autoload' => self::AUTOLOAD),
'disableWAFIPBlocking' => array('value' => false, 'autoload' => self::AUTOLOAD),
'showAdminBarMenu' => array('value' => true, 'autoload' => self::AUTOLOAD),
'displayTopLevelOptions' => array('value' => true, 'autoload' => self::AUTOLOAD),
'displayTopLevelBlocking' => array('value' => false, 'autoload' => self::AUTOLOAD),
'displayTopLevelLiveTraffic' => array('value' => false, 'autoload' => self::AUTOLOAD),
'displayAutomaticBlocks' => array('value' => true, 'autoload' => self::AUTOLOAD),
'allowLegacy2FA' => array('value' => false, 'autoload' => self::AUTOLOAD),
'wordfenceI18n' => array('value' => true, 'autoload' => self::AUTOLOAD),
//All exportable variable type options
"scan_include_extra" => array('value' => "", 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
"alertEmails" => array('value' => "", 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
"liveTraf_ignoreUsers" => array('value' => "", 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
"liveTraf_ignoreIPs" => array('value' => "", 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
"liveTraf_ignoreUA" => array('value' => "", 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
"maxMem" => array('value' => 256, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'scan_exclude' => array('value' => '', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'scan_maxIssues' => array('value' => 1000, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'scan_maxDuration' => array('value' => '', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
"scan_max_resume_attempts" => array('value' => wfScanMonitor::DEFAULT_RESUME_ATTEMPTS, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'whitelisted' => array('value' => '', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'whitelistedServices' => array('value' => '{}', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_JSON)),
'bannedURLs' => array('value' => '', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'maxExecutionTime' => array('value' => 0, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'howGetIPs' => array('value' => '', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'actUpdateInterval' => array('value' => 2, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'alert_maxHourly' => array('value' => 0, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'loginSec_userBlacklist' => array('value' => '', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'liveTraf_maxRows' => array('value' => 2000, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'liveTraf_maxAge' => array('value' => 30, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
"neverBlockBG" => array('value' => "neverBlockVerified", 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
"loginSec_countFailMins" => array('value' => 240, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
"loginSec_lockoutMins" => array('value' => 240, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'loginSec_strongPasswds' => array('value' => 'pubs', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'loginSec_breachPasswds' => array('value' => 'admins', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'loginSec_maxFailures' => array('value' => 20, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'loginSec_maxForgotPasswd' => array('value' => 20, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'maxGlobalRequests' => array('value' => 'DISABLED', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'maxGlobalRequests_action' => array('value' => "throttle", 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'maxRequestsCrawlers' => array('value' => 'DISABLED', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'maxRequestsCrawlers_action' => array('value' => "throttle", 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'maxRequestsHumans' => array('value' => 'DISABLED', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'maxRequestsHumans_action' => array('value' => "throttle", 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'max404Crawlers' => array('value' => 'DISABLED', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'max404Crawlers_action' => array('value' => "throttle", 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'max404Humans' => array('value' => 'DISABLED', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'max404Humans_action' => array('value' => "throttle", 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'blockedTime' => array('value' => 300, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'email_summary_interval' => array('value' => 'weekly', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'email_summary_excluded_directories' => array('value' => 'wp-content/cache,wp-content/wflogs', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'allowed404s' => array('value' => "/favicon.ico\n/apple-touch-icon*.png\n/*@2x.png\n/browserconfig.xml", 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'wafAlertWhitelist' => array('value' => '', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'wafAlertInterval' => array('value' => 600, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'wafAlertThreshold' => array('value' => 100, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'howGetIPs_trusted_proxies' => array('value' => '', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'howGetIPs_trusted_proxy_preset' => array('value' => '', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'scanType' => array('value' => wfScanner::SCAN_TYPE_STANDARD, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'manualScanType' => array('value' => wfScanner::MANUAL_SCHEDULING_ONCE_DAILY, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'schedStartHour' => array('value' => -1, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'schedMode' => array('value' => wfScanner::SCAN_SCHEDULING_MODE_AUTOMATIC, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'cbl_loggedInBlocked' => array('value' => false, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'cbl_action' => array('value' => 'block', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'cbl_redirURL' => array('value' => '', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'cbl_bypassRedirURL' => array('value' => '', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'cbl_bypassRedirDest' => array('value' => '', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'cbl_bypassViewURL' => array('value' => '', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'loginSec_enableSeparateTwoFactor' => array('value' => false, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'blockCustomText' => array('value' => '', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'alertOn_severityLevel' => array('value' => wfIssues::SEVERITY_LOW, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
//Set as default only, not included automatically in the settings import/export or options page saving
"apiKey" => array('value' => "", 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'keyType' => array('value' => wfLicense::KEY_TYPE_FREE, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'isPaid' => array('value' => false, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'hasKeyConflict' => array('value' => false, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'timeoffset_wf_updated' => array('value' => 0, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'cacheType' => array('value' => 'disabled', 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'detectProxyRecommendation' => array('value' => '', 'autoload' => self::DONT_AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'dismissAutoPrependNotice' => array('value' => false, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'onboardingAttempt1' => array('value' => '', 'autoload' => self::DONT_AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'onboardingAttempt2' => array('value' => '', 'autoload' => self::DONT_AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'onboardingAttempt3' => array('value' => '', 'autoload' => self::DONT_AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'onboardingAttempt3Initial' => array('value' => false, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'onboardingDelayedAt' => array('value' => false, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'needsNewTour_dashboard' => array('value' => true, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'needsNewTour_firewall' => array('value' => true, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'needsNewTour_scan' => array('value' => true, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'needsNewTour_blocking' => array('value' => true, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'needsNewTour_livetraffic' => array('value' => true, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'needsNewTour_loginsecurity' => array('value' => true, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'needsUpgradeTour_dashboard' => array('value' => false, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'needsUpgradeTour_firewall' => array('value' => false, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'needsUpgradeTour_scan' => array('value' => false, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'needsUpgradeTour_blocking' => array('value' => false, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'needsUpgradeTour_livetraffic' => array('value' => false, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'needsUpgradeTour_loginsecurity' => array('value' => false, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'supportContent' => array('value' => '{}', 'autoload' => self::DONT_AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'supportHash' => array('value' => '', 'autoload' => self::DONT_AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'whitelistPresets' => array('value' => '{}', 'autoload' => self::DONT_AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'whitelistHash' => array('value' => '', 'autoload' => self::DONT_AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'touppPromptNeeded' => array('value' => false, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'touppBypassNextCheck' => array('value' => false, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
'autoUpdateAttempts' => array('value' => 0, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'lastPermissionsTemplateCheck' => array('value' => 0, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'previousWflogsFileList' => array('value' => '[]', 'autoload' => self::DONT_AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'diagnosticsWflogsRemovalHistory' => array('value' => '[]', 'autoload' => self::DONT_AUTOLOAD, 'validation' => array('type' => self::TYPE_STRING)),
'satisfactionPromptDismissed' => array('value' => 0, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'satisfactionPromptInstallDate' => array('value' => 0, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_INT)),
'satisfactionPromptOverride' => array('value' => true, 'autoload' => self::AUTOLOAD, 'validation' => array('type' => self::TYPE_BOOL)),
public static $serializedOptions = array('lastAdminLogin', 'scanSched', 'emailedIssuesList', 'wf_summaryItems', 'adminUserList', 'twoFactorUsers', 'alertFreqTrack', 'wfStatusStartMsgs', 'vulnerabilities_core', 'vulnerabilities_plugin', 'vulnerabilities_theme', 'dashboardData', 'malwarePrefixes', 'coreHashes', 'noc1ScanSchedule', 'allScansScheduled', 'disclosureStates', 'scanStageStatuses', 'adminNoticeQueue', 'suspiciousAdminUsernames', 'wordpressPluginVersions', 'wordpressThemeVersions');
// Configuration keypairs that can be set from Central.
private static $wfCentralInternalConfig = array(
'wordfenceCentralUserSiteAuthGrant',
'wordfenceCentralConnected',
'wordfenceCentralPluginAlertingDisabled',
public static function setDefaults() {
foreach (self::$defaultConfig['checkboxes'] as $key => $config) {
$autoload = $config['autoload'];
if (self::get($key) === false) {
self::set($key, $val ? '1' : '0', $autoload);
foreach (self::$defaultConfig['otherParams'] as $key => $config) {
$autoload = $config['autoload'];
if (self::get($key) === false) {
self::set($key, $val, $autoload);
foreach (self::$defaultConfig['defaultsOnly'] as $key => $config) {
$autoload = $config['autoload'];
if (self::get($key) === false) {
self::set($key, '0', $autoload);
else if ($val === true) {
self::set($key, '1', $autoload);
self::set($key, $val, $autoload);
self::set('encKey', substr(wfUtils::bigRandomHex(), 0, 16));
self::set('longEncKey', bin2hex(wfWAFUtils::random_bytes(32)));
if (self::get('maxMem', false) === false) {
self::set('maxMem', '256');
if (self::get('other_scanOutside', false) === false) {
self::set('other_scanOutside', 0);
if (self::get('email_summary_enabled')) {
wfActivityReport::scheduleCronJob();
wfActivityReport::disableCronJob();
public static function loadAllOptions() {
$options = wp_cache_get('alloptions', 'wordfence');
self::updateTableExists();
$suppress = $wpdb->suppress_errors();
if (!($rawOptions = $wpdb->get_results("SELECT name, val FROM {$table} WHERE autoload = 'yes'"))) {
$rawOptions = $wpdb->get_results("SELECT name, val FROM {$table}");
$wpdb->suppress_errors($suppress);
foreach ((array) $rawOptions as $o) {
if (in_array($o->name, self::$serializedOptions)) {
$val = maybe_unserialize($o->val);
$options[$o->name] = $val;
$options[$o->name] = $o->val;
wp_cache_add_non_persistent_groups('wordfence');
wp_cache_add('alloptions', $options, 'wordfence');
* Bases the table's existence on the option specified by wfConfig::TABLE_EXISTS_OPTION for performance. We only
* set that option just prior to deletion in the uninstall handler and after table creation in the install handler.
public static function updateTableExists($change = null) {
self::$tableExists = !!$change;
if (is_multisite() && function_exists('update_network_option')) {
update_network_option(null, wfConfig::TABLE_EXISTS_OPTION, self::$tableExists);
update_option(wfConfig::TABLE_EXISTS_OPTION, self::$tableExists);
self::$tableExists = true;
if (is_multisite() && function_exists('get_network_option')) {
$optionValue = get_network_option(null, wfConfig::TABLE_EXISTS_OPTION, null);
$optionValue = get_option(wfConfig::TABLE_EXISTS_OPTION, null);
if ($optionValue === null) { //No value, set an initial one
self::updateTableExists(!!$wpdb->get_col($wpdb->prepare('SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=%s', self::table())));
self::$tableExists = false;
public static function tableExists() {
return self::$tableExists;
private static function updateCachedOption($name, $val) {
$options = self::loadAllOptions();
wp_cache_set('alloptions', $options, 'wordfence');
private static function removeCachedOption($name) {
$options = self::loadAllOptions();
if (isset($options[$name])) {
wp_cache_set('alloptions', $options, 'wordfence');
private static function getCachedOption($name) {
$options = self::loadAllOptions();
if (isset($options[$name])) {
$val = self::getDB()->querySingle("SELECT val FROM {$table} WHERE name='%s'", $name);
wp_cache_set('alloptions', $options, 'wordfence');
public static function hasCachedOption($name) {
$options = self::loadAllOptions();
return isset($options[$name]);
* Returns an array of all option keys that are eligible for export with the exception of serialized options.
public static function getExportableOptionsKeys() {
foreach (self::$defaultConfig['checkboxes'] as $key => $val) {
foreach (self::$defaultConfig['otherParams'] as $key => $val) {
public static function parseOptions($excludeOmitted = false) {
foreach (self::$defaultConfig['checkboxes'] as $key => $val) { //value is not used. We just need the keys for validation
if ($excludeOmitted && isset($_POST[$key])) {
$ret[$key] = (int) $_POST[$key];
else if (!$excludeOmitted || isset($_POST[$key])) {
$ret[$key] = isset($_POST[$key]) ? '1' : '0';
foreach (self::$defaultConfig['otherParams'] as $key => $val) {
if (!$excludeOmitted || isset($_POST[$key])) {
if (isset($_POST[$key])) {
$ret[$key] = stripslashes($_POST[$key]);
error_log("Missing options param \"$key\" when parsing parameters.");
foreach($_POST as $key => $val){
if($key != 'action' && $key != 'nonce' && (! array_key_exists($key, self::$checkboxes)) && (! array_key_exists($key, self::$otherParams)) ){
error_log("Unrecognized option: $key");
public static function setArray($arr){
foreach($arr as $key => $val){
public static function getHTML($key){
return esc_html(self::get($key));
public static function inc($key){
$val = self::get($key, false);
self::set($key, $val + 1);
public static function atomicInc($key) {
if (!self::$tableExists) {
$old_suppress_errors = $wpdb->suppress_errors(true);
if (!$rowExists && $wpdb->query($wpdb->prepare("INSERT INTO {$table} (name, val, autoload) values (%s, %s, %s)", $key, 1, self::DONT_AUTOLOAD))) {
$val = self::get($key, 1);
if ($wpdb->query($wpdb->prepare("UPDATE {$table} SET val = %s WHERE name = %s AND val = %s", $val + 1, $key, $val))) {
} while (!$successful && $attempts < 100);
$wpdb->suppress_errors($old_suppress_errors);
public static function remove($key) {
if (!self::$tableExists) {
$wpdb->query($wpdb->prepare("DELETE FROM {$table} WHERE name = %s", $key));
self::removeCachedOption($key);
if (!WFWAF_SUBDIRECTORY_INSTALL && class_exists('wfWAFIPBlocksController') && (substr($key, 0, 4) == 'cbl_' || $key == 'blockedTime' || $key == 'disableWAFIPBlocking')) {
wfWAFIPBlocksController::setNeedsSynchronizeConfigSettings();
public static function set($key, $val, $autoload = self::AUTOLOAD) {
/* translators: 1. Key in key-value store. 2. Value in key-value store. */
__('wfConfig::set() got an array as second param with key: %1$s and value: %2$s', 'wordfence'), $key, var_export($val, true));