: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
const SCAN_TYPE_QUICK = 'quick';
const SCAN_TYPE_LIMITED = 'limited';
const SCAN_TYPE_STANDARD = 'standard';
const SCAN_TYPE_HIGH_SENSITIVITY = 'highsensitivity';
const SCAN_TYPE_CUSTOM = 'custom';
const SCAN_SCHEDULING_MODE_AUTOMATIC = 'auto';
const SCAN_SCHEDULING_MODE_MANUAL = 'manual';
const MANUAL_SCHEDULING_ONCE_DAILY = 'onceDaily';
const MANUAL_SCHEDULING_TWICE_DAILY = 'twiceDaily';
const MANUAL_SCHEDULING_EVERY_OTHER_DAY = 'everyOtherDay';
const MANUAL_SCHEDULING_WEEKDAYS = 'weekdays';
const MANUAL_SCHEDULING_WEEKENDS = 'weekends';
const MANUAL_SCHEDULING_ODD_DAYS_WEEKENDS = 'oddDaysWE';
const MANUAL_SCHEDULING_CUSTOM = 'custom';
const SIGNATURE_MODE_PREMIUM = 'premium';
const SIGNATURE_MODE_COMMUNITY = 'community';
const STATUS_PENDING = 'pending';
const STATUS_RUNNING = 'running';
const STATUS_RUNNING_WARNING = 'running-warning';
const STATUS_COMPLETE_SUCCESS = 'complete-success';
const STATUS_COMPLETE_WARNING = 'complete-warning';
const STATUS_PREMIUM = 'premium';
const STATUS_DISABLED = 'disabled';
const STAGE_SPAMVERTISING_CHECKS = 'spamvertising';
const STAGE_SPAM_CHECK = 'spam';
const STAGE_BLACKLIST_CHECK = 'blacklist';
const STAGE_SERVER_STATE = 'server';
const STAGE_FILE_CHANGES = 'changes';
const STAGE_PUBLIC_FILES = 'public';
const STAGE_MALWARE_SCAN = 'malware';
const STAGE_CONTENT_SAFETY = 'content';
const STAGE_PASSWORD_STRENGTH = 'password';
const STAGE_VULNERABILITY_SCAN = 'vulnerability';
const STAGE_OPTIONS_AUDIT = 'options';
const SUMMARY_TOTAL_USERS = 'totalUsers';
const SUMMARY_TOTAL_PAGES = 'totalPages';
const SUMMARY_TOTAL_POSTS = 'totalPosts';
const SUMMARY_TOTAL_COMMENTS = 'totalComments';
const SUMMARY_TOTAL_CATEGORIES = 'totalCategories';
const SUMMARY_TOTAL_TABLES = 'totalTables';
const SUMMARY_TOTAL_ROWS = 'totalRows';
const SUMMARY_SCANNED_POSTS = 'scannedPosts';
const SUMMARY_SCANNED_COMMENTS = 'scannedComments';
const SUMMARY_SCANNED_FILES = 'scannedFiles';
const SUMMARY_SCANNED_PLUGINS = 'scannedPlugins';
const SUMMARY_SCANNED_THEMES = 'scannedThemes';
const SUMMARY_SCANNED_USERS = 'scannedUsers';
const SUMMARY_SCANNED_URLS = 'scannedURLs';
const CENTRAL_STAGE_UPDATE_THRESHOLD = 5;
private $_scanType = false;
private $_summary = false;
private $_destructRegistered = false;
* Returns the singleton wfScanner with the user-configured scan type set.
public static function shared() {
if ($_scanner === null) {
$_scanner = new wfScanner();
* Schedules a cron rescheduling to happen at the end of the current process's execution.
public static function setNeedsRescheduling() {
static $willReschedule = false;
register_shutdown_function(array(self::shared(), 'scheduleScans'));
* Returns whether or not the scan type passed is valid.
public static function isValidScanType($type) {
case self::SCAN_TYPE_QUICK:
case self::SCAN_TYPE_LIMITED:
case self::SCAN_TYPE_HIGH_SENSITIVITY:
case self::SCAN_TYPE_CUSTOM:
case self::SCAN_TYPE_STANDARD:
* Returns the display string for the given type.
public static function displayScanType($type) {
case self::SCAN_TYPE_QUICK:
return __('Quick', 'wordfence');
case self::SCAN_TYPE_LIMITED:
return __('Limited', 'wordfence');
case self::SCAN_TYPE_HIGH_SENSITIVITY:
return __('High Sensitivity', 'wordfence');
case self::SCAN_TYPE_CUSTOM:
return __('Custom', 'wordfence');
case self::SCAN_TYPE_STANDARD:
return __('Standard', 'wordfence');
* Returns the display detail string for the given type.
public static function displayScanTypeDetail($type) {
case self::SCAN_TYPE_QUICK:
case self::SCAN_TYPE_LIMITED:
return __('Low resource utilization, limited detection capability', 'wordfence');
case self::SCAN_TYPE_HIGH_SENSITIVITY:
return __('Standard detection capability, chance of false positives', 'wordfence');
case self::SCAN_TYPE_CUSTOM:
return __('Custom scan options selected', 'wordfence');
case self::SCAN_TYPE_STANDARD:
return __('Standard detection capability', 'wordfence');
* Returns an array of the scan options (as keys) and the corresponding value for the quick scan type. All omitted
* scan stages are considered disabled.
public static function quickScanTypeOptions() {
if (wfConfig::get('scanType') == self::SCAN_TYPE_CUSTOM) { //Obey the setting in custom if that's the true scan type
$oldVersions = wfConfig::get('scansEnabled_oldVersions');
$wafStatus = wfConfig::get('scansEnabled_wafStatus');
return array_merge(self::_inactiveScanOptions(), array(
'scansEnabled_oldVersions' => $oldVersions,
'scansEnabled_wafStatus' => $wafStatus,
* Returns an array of the scan options (as keys) and the corresponding value for the limited scan type.
public static function limitedScanTypeOptions() {
return array_merge(self::_inactiveScanOptions(), array(
'scansEnabled_checkHowGetIPs' => true,
'scansEnabled_malware' => true,
'scansEnabled_fileContents' => true,
'scansEnabled_fileContentsGSB' => true,
'scansEnabled_suspiciousOptions' => true,
'scansEnabled_oldVersions' => true,
'scansEnabled_wafStatus' => true,
'lowResourceScansEnabled' => true,
'scan_exclude' => wfConfig::get('scan_exclude', ''),
'scan_include_extra' => wfConfig::get('scan_include_extra', ''),
'scansEnabled_geoipSupport' => true,
* Returns an array of the scan options (as keys) and the corresponding value for the standard scan type.
public static function standardScanTypeOptions() {
return array_merge(self::_inactiveScanOptions(), array(
'spamvertizeCheck' => true,
'scansEnabled_checkGSB' => true,
'scansEnabled_checkHowGetIPs' => true,
'scansEnabled_checkReadableConfig' => true,
'scansEnabled_suspectedFiles' => true,
'scansEnabled_core' => true,
'scansEnabled_coreUnknown' => true,
'scansEnabled_malware' => true,
'scansEnabled_fileContents' => true,
'scansEnabled_fileContentsGSB' => true,
'scansEnabled_posts' => true,
'scansEnabled_comments' => true,
'scansEnabled_suspiciousOptions' => true,
'scansEnabled_oldVersions' => true,
'scansEnabled_suspiciousAdminUsers' => true,
'scansEnabled_passwds' => true,
'scansEnabled_diskSpace' => true,
'scansEnabled_wafStatus' => true,
'scan_exclude' => wfConfig::get('scan_exclude', ''),
'scan_include_extra' => wfConfig::get('scan_include_extra', ''),
'scansEnabled_geoipSupport' => true,
* Returns an array of the scan options (as keys) and the corresponding value for the high sensitivity scan type.
public static function highSensitivityScanTypeOptions() {
return array_merge(self::_inactiveScanOptions(), array(
'spamvertizeCheck' => true,
'scansEnabled_checkGSB' => true,
'scansEnabled_checkHowGetIPs' => true,
'scansEnabled_checkReadableConfig' => true,
'scansEnabled_suspectedFiles' => true,
'scansEnabled_core' => true,
'scansEnabled_themes' => true,
'scansEnabled_plugins' => true,
'scansEnabled_coreUnknown' => true,
'scansEnabled_malware' => true,
'scansEnabled_fileContents' => true,
'scansEnabled_fileContentsGSB' => true,
'scansEnabled_posts' => true,
'scansEnabled_comments' => true,
'scansEnabled_suspiciousOptions' => true,
'scansEnabled_oldVersions' => true,
'scansEnabled_suspiciousAdminUsers' => true,
'scansEnabled_passwds' => true,
'scansEnabled_diskSpace' => true,
'scansEnabled_wafStatus' => true,
'other_scanOutside' => true,
'scansEnabled_scanImages' => true,
'scan_exclude' => wfConfig::get('scan_exclude', ''),
'scan_include_extra' => wfConfig::get('scan_include_extra', ''),
'scansEnabled_geoipSupport' => true,
* Returns an array of the scan options (as keys) and the corresponding value for the custom scan type.
public static function customScanTypeOptions() {
$allOptions = self::_inactiveScanOptions();
foreach ($allOptions as $key => &$value) {
$value = wfConfig::get($key);
$allOptions['scansEnabled_geoipSupport'] = true;
$allOptions['scansEnabled_highSense'] = false; //deprecated
* Returns an array of scan options and their inactive values for convenience in merging with the various scan type
protected static function _inactiveScanOptions() {
'spamvertizeCheck' => false,
'scansEnabled_checkGSB' => false,
'scansEnabled_checkHowGetIPs' => false,
'scansEnabled_checkReadableConfig' => false,
'scansEnabled_suspectedFiles' => false,
'scansEnabled_core' => false,
'scansEnabled_themes' => false,
'scansEnabled_plugins' => false,
'scansEnabled_coreUnknown' => false,
'scansEnabled_malware' => false,
'scansEnabled_fileContents' => false,
'scan_include_extra' => '',
'scansEnabled_fileContentsGSB' => false,
'scansEnabled_posts' => false,
'scansEnabled_comments' => false,
'scansEnabled_suspiciousOptions' => false,
'scansEnabled_oldVersions' => false,
'scansEnabled_suspiciousAdminUsers' => false,
'scansEnabled_passwds' => false,
'scansEnabled_diskSpace' => false,
'scansEnabled_wafStatus' => false,
'other_scanOutside' => false,
'scansEnabled_scanImages' => false,
'scansEnabled_highSense' => false,
'lowResourceScansEnabled' => false,
'scansEnabled_geoipSupport' => false,
* Returns the scan options only available to premium users.
protected static function _premiumScanOptions() {
return array('spamvertizeCheck', 'checkSpamIP', 'scansEnabled_checkGSB');
* Returns an array of weights for calculating the scan option status score.
protected static function _scanOptionWeights() {
'spamvertizeCheck' => 0.05,
'scansEnabled_checkGSB' => 0.05,
'scansEnabled_checkHowGetIPs' => 0.05,
'scansEnabled_checkReadableConfig' => 0.05,
'scansEnabled_suspectedFiles' => 0.05,
'scansEnabled_core' => 0.05,
'scansEnabled_themes' => 0,
'scansEnabled_plugins' => 0,
'scansEnabled_coreUnknown' => 0.05,
'scansEnabled_malware' => 0.05,
'scansEnabled_fileContents' => 0.1,
'scan_include_extra' => 0,
'scansEnabled_fileContentsGSB' => 0.05,
'scansEnabled_posts' => 0.05,
'scansEnabled_comments' => 0.05,
'scansEnabled_suspiciousOptions' => 0.05,
'scansEnabled_oldVersions' => 0.1,
'scansEnabled_suspiciousAdminUsers' => 0.05,
'scansEnabled_passwds' => 0.05,
'scansEnabled_diskSpace' => 0.05,
'other_scanOutside' => 0,
'scansEnabled_scanImages' => 0,
'scansEnabled_highSense' => 0,
'lowResourceScansEnabled' => 0,
'scansEnabled_geoipSupport' => 0,
'scansEnabled_wafStatus' => 0,
* @param int|bool $scanType If false, defaults to the config option `scanType`.
public function __construct($scanType = false) {
if ($scanType === false || !self::isValidScanType($scanType)) {
$this->_scanType = wfConfig::get('scanType');
$this->_scanType = $scanType;
* Returns whether or not the scanner will run as premium.
public function isPremiumScan() {
return !!wfConfig::get('isPaid');
* Returns whether or not automatic scans will run.
public function isEnabled() {
return !!wfConfig::get('scheduledScansEnabled');
* Returns whether or not a scan is running. A scan is considered running if the timestamp
* under wf_scanRunning is within WORDFENCE_MAX_SCAN_LOCK_TIME seconds of now.
public function isRunning() {
$scanRunning = wfConfig::get('wf_scanRunning');
return ($scanRunning && time() - $scanRunning < WORDFENCE_MAX_SCAN_LOCK_TIME);
* Returns the current scan scheduling mode.
* @return string One of the SCAN_SCHEDULING_MODE_ constants
public function schedulingMode() {
if (wfConfig::get('isPaid') && wfConfig::get('schedMode') == 'manual') {
return self::SCAN_SCHEDULING_MODE_MANUAL;
return self::SCAN_SCHEDULING_MODE_AUTOMATIC;
* Returns the manual scheduling type. This is only applicable when the scheduling mode is
* SCAN_SCHEDULING_MODE_MANUAL.
* @return string One of the MANUAL_SCHEDULING_ constants.
public function manualSchedulingType() {
return wfConfig::get('manualScanType', self::MANUAL_SCHEDULING_ONCE_DAILY);
* Returns the start hour used for non-custom manual schedules. This is initially random but may be modified
* @return int An hour number.
public function manualSchedulingStartHour() {
return wfConfig::get('schedStartHour');
* Returns the currently defined custom schedule. This is only applicable when the scheduling mode is
* SCAN_SCHEDULING_MODE_MANUAL and the manual type is set to MANUAL_SCHEDULING_CUSTOM.
* @return array The array will be of the format array(0 => array(0 => 0, 1 => 0 ... 23 => 0), ... 6 => array(...))
public function customSchedule() {
$normalizedSchedule = array_fill(0, 7, array_fill(0, 24, 0));
$storedSchedule = wfConfig::get_ser('scanSched', array());
if (is_array($storedSchedule) && !empty($storedSchedule) && is_array($storedSchedule[0])) {
foreach ($storedSchedule as $dayNumber => $day) {
foreach ($day as $hourNumber => $enabled) {
$normalizedSchedule[$dayNumber][$hourNumber] = wfUtils::truthyToInt($enabled);
return $normalizedSchedule;
public function shouldRunQuickScan() {
if (!$this->isEnabled()) {
if (time() - $this->lastQuickScanTime() < 79200) { //Do not run within 22 hours of a completed quick scan
$lastFullScanCompletion = (int) $this->lastScanTime();
if (time() - $lastFullScanCompletion < 43200) { //Do not run within 12 hours of a completed full scan
$nextFullScan = $this->nextScheduledScanTime();
if ($nextFullScan === false || $nextFullScan - time() < 3600) { //Scans are not running (e.g., custom schedule selected with no times configured) or if scheduled, then avoid running within 1 hour of a pending full scan
$tzOffset = wfUtils::formatLocalTime('Z', $now);
$currentDayOfWeekUTC = date('w', $now);
$currentHourUTC = date('G', $now);
$preferredHourUTC = false;
if ($this->schedulingMode() == wfScanner::SCAN_SCHEDULING_MODE_MANUAL) {
$manualType = $this->manualSchedulingType();
$preferredHourUTC = round(($this->manualSchedulingStartHour() * 3600 - $tzOffset) / 3600, 2) % 24; //round() rather than floor() to account for fractional time zones
case self::MANUAL_SCHEDULING_ONCE_DAILY:
case self::MANUAL_SCHEDULING_EVERY_OTHER_DAY:
case self::MANUAL_SCHEDULING_WEEKDAYS:
case self::MANUAL_SCHEDULING_WEEKENDS:
case self::MANUAL_SCHEDULING_ODD_DAYS_WEEKENDS:
$preferredHourUTC = ($preferredHourUTC + 12) % 24;
case self::MANUAL_SCHEDULING_TWICE_DAILY:
$preferredHourUTC = ($preferredHourUTC + 6) % 24; //When automatic scans run twice daily, possibly run a quick scan 6 hours offset (will only run if either scheduled one fails for some reason)
case self::MANUAL_SCHEDULING_CUSTOM: //Iterate from the current day backwards and base it on the first time found, may or may not actually run depending on the spacing of the custom schedule
$preferredHourUTC = false;
$oneWeekSchedule = $this->customSchedule();
for ($i = 7; $i > 0; $i--) { //Sample sequence for `$currentDayOfWeekUTC == 2` => 2, 1, 0, 6, 5, 4, 3
$checkingDayNumber = ($currentDayOfWeekUTC + $i) % 7;