: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$validHashes = array_slice($validHashes, 0, self::CAPTCHA_SCORE_LIMIT);
update_user_meta($user->ID, self::META_KEY_CAPTCHA_SCORES, $validHashes);
* Hashes the captcha token for storage.
private function hash_captcha_token($token) {
* Returns the cached score for the given captcha score and user if available. This action removes it from the cache
* since the intent is for it only to be used for the initial login request to validate credentials + the follow-up
* request either finalizing the login (no 2FA set) or with the 2FA token.
* $expired will be set to `true` if the reason for returning `false` is because the $token is recently expired. It
* will be false when the $token is either uncached or has been expired long enough to be removed from the internal
public function cached_captcha_score($token, $user, &$expired = false) {
$hash = $this->hash_captcha_token($token);
$score = $this->load_captcha_score($hash, $user);
$storedHashes = get_user_meta($user->ID, self::META_KEY_CAPTCHA_SCORES, true);
if (is_array($storedHashes)) {
$expired = in_array($hash, $storedHashes);
$this->clear_captcha_score($token, $user);
* Caches the $token/$score pair for $user, automatically pruning its cached list to the maximum allowable count
* @param float|false $score
public function cache_captcha_score($token, $score, $user) {
$storedHashes = get_user_meta($user->ID, self::META_KEY_CAPTCHA_SCORES, true);
if (is_array($storedHashes)) {
foreach ($storedHashes as $hash) {
$storedScore = $this->load_captcha_score($hash, $user);
if ($storedScore !== false) {
$hash = $this->hash_verification_token($token);
array_unshift($validHashes, $hash);
while (count($validHashes) > self::CAPTCHA_SCORE_LIMIT) {
$excessHash = array_pop($validHashes);
delete_transient($this->get_captcha_score_transient_key($excessHash));
$key = $this->get_captcha_score_transient_key($hash);
set_transient($key, array('user' => $user->ID, 'score' => $score), self::CAPTCHA_SCORE_CACHE_DURATION);
update_user_meta($user->ID, self::META_KEY_CAPTCHA_SCORES, $validHashes);
public function get_user_count() {
if (function_exists('get_user_count'))
return $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->users}");
public function has_large_user_base() {
return $this->get_user_count() >= self::LARGE_USER_BASE_THRESHOLD;
public function should_force_user_counts() {
return isset($_GET['wfls-show-user-counts']);
public function get_detailed_user_counts_if_enabled() {
$force = $this->should_force_user_counts();
if ($this->has_large_user_base() && !$force)
return $this->detailed_user_counts($force);