: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
const VULN_SEVERITY_CRITICAL = 90;
const VULN_SEVERITY_HIGH = 70;
const VULN_SEVERITY_MEDIUM = 40;
const VULN_SEVERITY_LOW = 1;
const VULN_SEVERITY_NONE = 0;
const LAST_UPDATE_CHECK_ERROR_KEY = 'lastUpdateCheckError';
const LAST_UPDATE_CHECK_ERROR_SLUG_KEY = 'lastUpdateCheckErrorSlug';
private $needs_core_update = false;
private $core_update_patch_available = false;
private $core_earlier_branch = false;
private $core_update_version = 0;
private $core_update_patch_version = 0;
private $plugin_updates = array();
private $all_plugins = array();
private $plugin_slugs = array();
private $theme_updates = array();
* This hook exists because some plugins override their own update check and can return invalid
* responses (e.g., null) due to logic errors or their update check server being unreachable. This
* can interfere with our scan running the outdated plugins check. When scanning, we adjust the
* response in those cases to be `false`, which causes WP to fall back to the plugin repo data.
public static function installPluginAPIFixer() {
add_filter('plugins_api', 'wfUpdateCheck::_pluginAPIFixer', 999, 3);
public static function _pluginAPIFixer($result, $action, $args) {
if ($result === false || is_object($result) || is_array($result)) {
if (!wfScanEngine::isScanRunning(true)) { //Skip fixing if it's not the call the scanner made
if (is_object($args) && isset($args->slug)) {
else if (is_array($args) && isset($args['slug'])) {
wordfence::status(2, 'info', sprintf(/* translators: 1. Plugin slug. */ __('Outdated plugin scan adjusted invalid return value in plugins_api filter for %s', 'wordfence'), $slug));
public static function syncAllVersionInfo() {
// Load the core/plugin/theme versions into the WAF configuration.
wfConfig::set('wordpressVersion', wfUtils::getWPVersion());
wfWAFConfig::set('wordpressVersion', wfUtils::getWPVersion(), wfWAF::getInstance(), 'synced');
if (!function_exists('get_plugins')) {
require_once(ABSPATH . '/wp-admin/includes/plugin.php');
$pluginVersions = array();
foreach (get_plugins() as $pluginFile => $pluginData) {
$slug = plugin_basename($pluginFile);
if (preg_match('/^([^\/]+)\//', $pluginFile, $matches)) {
} else if (preg_match('/^([^\/.]+)\.php$/', $pluginFile, $matches)) {
$pluginVersions[$slug] = isset($pluginData['Version']) ? $pluginData['Version'] : null;
wfConfig::set_ser('wordpressPluginVersions', $pluginVersions);
wfWAFConfig::set('wordpressPluginVersions', $pluginVersions, wfWAF::getInstance(), 'synced');
if (!function_exists('wp_get_themes')) {
require_once(ABSPATH . '/wp-includes/theme.php');
$themeVersions = array();
foreach (wp_get_themes() as $slug => $theme) {
$themeVersions[$slug] = isset($theme['Version']) ? $theme['Version'] : null;
wfConfig::set_ser('wordpressThemeVersions', $themeVersions);
wfWAFConfig::set('wordpressThemeVersions', $themeVersions, wfWAF::getInstance(), 'synced');
public static function cvssScoreSeverity($score) {
$intScore = floor($score * 10);
if ($intScore >= self::VULN_SEVERITY_CRITICAL) {
return self::VULN_SEVERITY_CRITICAL;
else if ($intScore >= self::VULN_SEVERITY_HIGH) {
return self::VULN_SEVERITY_HIGH;
else if ($intScore >= self::VULN_SEVERITY_MEDIUM) {
return self::VULN_SEVERITY_MEDIUM;
else if ($intScore >= self::VULN_SEVERITY_LOW) {
return self::VULN_SEVERITY_LOW;
return self::VULN_SEVERITY_NONE;
public static function cvssScoreSeverityLabel($score) {
$severity = self::cvssScoreSeverity($score);
case self::VULN_SEVERITY_CRITICAL:
return __('Critical', 'wordfence');
case self::VULN_SEVERITY_HIGH:
return __('High', 'wordfence');
case self::VULN_SEVERITY_MEDIUM:
return __('Medium', 'wordfence');
case self::VULN_SEVERITY_LOW:
return __('Low', 'wordfence');
return __('None', 'wordfence');
public static function cvssScoreSeverityHexColor($score) {
$severity = self::cvssScoreSeverity($score);
case self::VULN_SEVERITY_CRITICAL:
case self::VULN_SEVERITY_HIGH:
case self::VULN_SEVERITY_MEDIUM:
case self::VULN_SEVERITY_LOW:
public static function cvssScoreSeverityClass($score) {
$severity = self::cvssScoreSeverity($score);
case self::VULN_SEVERITY_CRITICAL:
return 'wf-vulnerability-severity-critical';
case self::VULN_SEVERITY_HIGH:
return 'wf-vulnerability-severity-high';
case self::VULN_SEVERITY_MEDIUM:
return 'wf-vulnerability-severity-medium';
case self::VULN_SEVERITY_LOW:
return 'wf-vulnerability-severity-low';
return 'wf-vulnerability-severity-none';
public function __construct() {
$this->api = new wfAPI(wfConfig::get('apiKey'), wfUtils::getWPVersion());
public function __sleep() {
return array('needs_core_update', 'core_update_version', 'plugin_updates', 'all_plugins', 'plugin_slugs', 'theme_updates');
public function __wakeup() {
$this->api = new wfAPI(wfConfig::get('apiKey'), wfUtils::getWPVersion());
public function needsAnyUpdates() {
return $this->needsCoreUpdate() || count($this->getPluginUpdates()) > 0 || count($this->getThemeUpdates()) > 0;
* Check for any core, plugin or theme updates.
public function checkAllUpdates($useCachedValued = true) {
wfConfig::remove(self::LAST_UPDATE_CHECK_ERROR_KEY);
wfConfig::remove(self::LAST_UPDATE_CHECK_ERROR_SLUG_KEY);
return $this->checkCoreUpdates($useCachedValued)
->checkPluginUpdates($useCachedValued)
->checkThemeUpdates($useCachedValued);
* Check if there is an update to the WordPress core.
public function checkCoreUpdates($useCachedValued = true) {
$this->needs_core_update = false;
if (!function_exists('wp_version_check')) {
require_once(ABSPATH . WPINC . '/update.php');
if (!function_exists('get_preferred_from_update_core')) {
require_once(ABSPATH . 'wp-admin/includes/update.php');
include(ABSPATH . WPINC . '/version.php'); /** @var $wp_version */
$availableUpdates = get_site_transient('update_core');
public $response => string(7) "upgrade"
public $version => string(5) "6.4.2"
public $response => string(10) "autoupdate"
public $version => string(5) "6.4.2"
public $response => string(10) "autoupdate"
public $version => string(5) "6.3.2"
public $last_checked => int(1703025218)
public $version_checked => string(5) "6.3.1"
public $translations => ...
isset($availableUpdates->updates) && is_array($availableUpdates->updates) &&
isset($availableUpdates->last_checked) && 12 * HOUR_IN_SECONDS > (time() - $availableUpdates->last_checked) && $availableUpdates->version_checked == $wp_version) {
//Do nothing, use cached value
$availableUpdates = get_site_transient('update_core');
if (isset($availableUpdates->updates) && is_array($availableUpdates->updates)) {
$current = wfUtils::parse_version($wp_version);
$updates = $availableUpdates->updates;
foreach ($updates as $update) {
if (version_compare($update->version, $wp_version) <= 0) { continue; } //Array will contain the reinstall info for the current version if non-prerelease or the last production version if prerelease, skip
if (version_compare($update->version, $this->core_update_version) > 0) {
$this->needs_core_update = true;
$this->core_update_version = $update->version;
$checking = wfUtils::parse_version($update->version);
if ($checking[wfUtils::VERSION_MAJOR] == $current[wfUtils::VERSION_MAJOR] && $checking[wfUtils::VERSION_MINOR] == $current[wfUtils::VERSION_MINOR] && $checking[wfUtils::VERSION_PATCH] > $current[wfUtils::VERSION_PATCH]) {
$this->core_update_patch_available = true;
$this->core_update_patch_version = $update->version;
if ($this->needs_core_update && $this->core_update_patch_available && version_compare($this->core_update_version, $this->core_update_patch_version) === 0) { //Patch and edge update are the same, clear patch values
$this->core_update_patch_available = false;
$this->core_update_patch_version = 0;
if ($this->needs_core_update) {
$checking = wfUtils::parse_version($this->core_update_version);
$this->core_earlier_branch = ($checking[wfUtils::VERSION_MAJOR] > $current[wfUtils::VERSION_MAJOR] || $checking[wfUtils::VERSION_MINOR] > $current[wfUtils::VERSION_MINOR]);
private function checkPluginFile($plugin, &$installedPlugins) {
if (!array_key_exists($plugin, $installedPlugins))
$file = wfUtils::getPluginBaseDir() . $plugin;
if (!file_exists($file)) {
unset($installedPlugins[$plugin]);
private function initializePluginUpdateData($plugin, &$installedPlugins, $checkVulnerabilities, $populator = null) {
$file = $this->checkPluginFile($plugin, $installedPlugins);
$data = $installedPlugins[$plugin];
$data['pluginFile'] = $file;
$populator($data, $file);
if (!array_key_exists('slug', $data) || empty($data['slug']))
$data['slug'] = $this->extractSlug($plugin);
$vulnerable = $checkVulnerabilities ? $this->isPluginVulnerable($slug, $data['Version']) : null;
$data['vulnerable'] = !empty($vulnerable);
if ($data['vulnerable']) {
if (isset($vulnerable['link']) && is_string($vulnerable['link'])) { $data['vulnerabilityLink'] = $vulnerable['link']; }
if (isset($vulnerable['score'])) {
$data['cvssScore'] = number_format(floatval($vulnerable['score']), 1);
$data['severityColor'] = self::cvssScoreSeverityHexColor($data['cvssScore']);
$data['severityLabel'] = self::cvssScoreSeverityLabel($data['cvssScore']);
$data['severityClass'] = self::cvssScoreSeverityClass($data['cvssScore']);
if (isset($vulnerable['vector']) && is_string($vulnerable['vector'])) { $data['cvssVector'] = $vulnerable['vector']; }
$this->plugin_slugs[] = $slug;
$this->all_plugins[$slug] = $data;
unset($installedPlugins[$plugin]);
public function extractSlug($plugin, $data = null) {
if (is_array($data) && array_key_exists('slug', $data))
if (!is_string($slug) || empty($slug)) {
if (preg_match('/^([^\/]+)\//', $plugin, $matches)) {
else if (preg_match('/^([^\/.]+)\.php$/', $plugin, $matches)) {
private static function requirePluginsApi() {
if (!function_exists('plugins_api'))
require_once(ABSPATH . '/wp-admin/includes/plugin-install.php');
private function fetchPluginUpdates($useCache = true) {
$update_plugins = get_site_transient('update_plugins');
if ($useCache && isset($update_plugins->last_checked) && 12 * HOUR_IN_SECONDS > (time() - $update_plugins->last_checked)) //Duplicate of _maybe_update_plugins, which is a private call
if (!function_exists('wp_update_plugins'))
require_once(ABSPATH . WPINC . '/update.php');
wfConfig::set(self::LAST_UPDATE_CHECK_ERROR_KEY, $e->getMessage(), false);
wfConfig::remove(self::LAST_UPDATE_CHECK_ERROR_SLUG_KEY);
error_log('Caught exception while attempting to refresh plugin update status: ' . $e->getMessage());
wfConfig::set(self::LAST_UPDATE_CHECK_ERROR_KEY, $t->getMessage(), false);
wfConfig::remove(self::LAST_UPDATE_CHECK_ERROR_SLUG_KEY);
error_log('Caught error while attempting to refresh plugin update status: ' . $t->getMessage());
return get_site_transient('update_plugins');
* Check if any plugins need an update.
* @param bool $checkVulnerabilities whether or not to check for vulnerabilities while checking updates
public function checkPluginUpdates($useCachedValued = true, $checkVulnerabilities = true) {
if($checkVulnerabilities)
$this->plugin_updates = array();
self::requirePluginsApi();
$update_plugins = $this->fetchPluginUpdates($useCachedValued);
//Get the full plugin list
if (!function_exists('get_plugins')) {
require_once(ABSPATH . '/wp-admin/includes/plugin.php');
$installedPlugins = get_plugins();
if ($update_plugins && !empty($update_plugins->response)) {
foreach ($update_plugins->response as $plugin => $vals) {
$data = $this->initializePluginUpdateData($plugin, $installedPlugins, $checkVulnerabilities, function (&$data, $file) use ($context, $plugin, $vals) {
$data['slug'] = $context->extractSlug($plugin, $vals);
$data['newVersion'] = (isset($vals['new_version']) ? $vals['new_version'] : 'Unknown');
$data['wpURL'] = (isset($vals['url']) ? rtrim($vals['url'], '/') : null);
$data['updateAvailable'] = true;
if($checkVulnerabilities && $data !== null)
$this->plugin_updates[] = $data;
//We have to grab the slugs from the update response because no built-in function exists to return the true slug from the local files
if ($update_plugins && !empty($update_plugins->no_update)) {
foreach ($update_plugins->no_update as $plugin => $vals) {
$this->initializePluginUpdateData($plugin, $installedPlugins, $checkVulnerabilities, function (&$data, $file) use ($context, $plugin, $vals) {
$data['slug'] = $context->extractSlug($plugin, $vals);
$data['wpURL'] = (isset($vals['url']) ? rtrim($vals['url'], '/') : null);
//Get the remaining plugins (not in the wordpress.org repo for whatever reason)
foreach ($installedPlugins as $plugin => $data) {
$data = $this->initializePluginUpdateData($plugin, $installedPlugins, $checkVulnerabilities);
* Check if any themes need an update.
* @param bool $checkVulnerabilities whether or not to check for vulnerabilities while checking for updates
public function checkThemeUpdates($useCachedValued = true, $checkVulnerabilities = true) {
if($checkVulnerabilities)
$this->theme_updates = array();
if (!function_exists('wp_update_themes')) {
require_once(ABSPATH . WPINC . '/update.php');
$update_themes = get_site_transient('update_themes');
if ($useCachedValued && isset($update_themes->last_checked) && 12 * HOUR_IN_SECONDS > (time() - $update_themes->last_checked)) { //Duplicate of _maybe_update_themes, which is a private call
//Do nothing, use cached value
wfConfig::set(self::LAST_UPDATE_CHECK_ERROR_KEY, $e->getMessage(), false);
error_log('Caught exception while attempting to refresh theme update status: ' . $e->getMessage());
wfConfig::set(self::LAST_UPDATE_CHECK_ERROR_KEY, $t->getMessage(), false);
error_log('Caught error while attempting to refresh theme update status: ' . $t->getMessage());
$update_themes = get_site_transient('update_themes');
if ($update_themes && (!empty($update_themes->response)) && $checkVulnerabilities) {
if (!function_exists('wp_get_themes')) {
require_once(ABSPATH . '/wp-includes/theme.php');
$themes = wp_get_themes();
foreach ($update_themes->response as $theme => $vals) {
foreach ($themes as $name => $themeData) {
if (strtolower($name) == $theme) {
if (isset($themeData['Version'])) {
$vulnerable = $this->isThemeVulnerable($theme, $themeData['Version']);
'newVersion' => (isset($vals['new_version']) ? $vals['new_version'] : 'Unknown'),
'package' => (isset($vals['package']) ? $vals['package'] : null),
'URL' => (isset($vals['url']) ? $vals['url'] : null),
'Name' => $themeData['Name'],
'name' => $themeData['Name'],
'version' => $themeData['Version'],
'vulnerable' => $vulnerable
$data['vulnerable'] = !empty($vulnerable);
if ($data['vulnerable']) {
if (isset($vulnerable['link']) && is_string($vulnerable['link'])) { $data['vulnerabilityLink'] = $vulnerable['link']; }
if (isset($vulnerable['score'])) {
$data['cvssScore'] = number_format(floatval($vulnerable['score']), 1);
$data['severityColor'] = self::cvssScoreSeverityHexColor($data['cvssScore']);
$data['severityLabel'] = self::cvssScoreSeverityLabel($data['cvssScore']);
$data['severityClass'] = self::cvssScoreSeverityClass($data['cvssScore']);
if (isset($vulnerable['vector']) && is_string($vulnerable['vector'])) { $data['cvssVector'] = $vulnerable['vector']; }
$this->theme_updates[] = $data;
* @param bool $initial if true, treat as the initial scan run