Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordfenc.../modules/login-se.../classes/controll...
File: notices.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WordfenceLS;
[2] Fix | Delete
[3] Fix | Delete
use WordfenceLS\Text\Model_HTML;
[4] Fix | Delete
[5] Fix | Delete
class Controller_Notices {
[6] Fix | Delete
const USER_META_KEY = 'wfls_notices';
[7] Fix | Delete
const PERSISTENT_NOTICE_DISMISS_PREFIX = 'wfls-dismiss-';
[8] Fix | Delete
const PERSISTENT_NOTICE_WOOCOMMERCE_INTEGRATION = 'wfls-woocommerce-integration-notice';
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Returns the singleton Controller_Notices.
[12] Fix | Delete
*
[13] Fix | Delete
* @return Controller_Notices
[14] Fix | Delete
*/
[15] Fix | Delete
public static function shared() {
[16] Fix | Delete
static $_shared = null;
[17] Fix | Delete
if ($_shared === null) {
[18] Fix | Delete
$_shared = new Controller_Notices();
[19] Fix | Delete
}
[20] Fix | Delete
return $_shared;
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
private $persistentNotices = array();
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Adds an admin notice to the display queue. If $user is provided, it will show only for that user, otherwise it
[27] Fix | Delete
* will show for all administrators.
[28] Fix | Delete
*
[29] Fix | Delete
* @param string $severity
[30] Fix | Delete
* @param string|Model_HTML $message
[31] Fix | Delete
* @param bool|string $category If not false, notices with the same category will be removed prior to adding this one.
[32] Fix | Delete
* @param bool|\WP_User $user If not false, the user that the notice should show for.
[33] Fix | Delete
*/
[34] Fix | Delete
public function add_notice($severity, $message, $category = false, $user = false) {
[35] Fix | Delete
$notices = $this->_notices($user);
[36] Fix | Delete
foreach ($notices as $id => $n) {
[37] Fix | Delete
if ($category !== false && isset($n['category']) && $n['category'] == $category) { //Same category overwrites previous entry
[38] Fix | Delete
unset($notices[$id]);
[39] Fix | Delete
}
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
$id = Model_Crypto::uuid();
[43] Fix | Delete
$notices[$id] = array(
[44] Fix | Delete
'severity' => $severity,
[45] Fix | Delete
'messageHTML' => Model_HTML::esc_html($message),
[46] Fix | Delete
);
[47] Fix | Delete
[48] Fix | Delete
if ($category !== false) {
[49] Fix | Delete
$notices[$id]['category'] = $category;
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
$this->_save_notices($notices, $user);
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Removes a notice using one of two possible search methods:
[57] Fix | Delete
*
[58] Fix | Delete
* 1. If $id matches. $category is ignored but only notices for $user are checked.
[59] Fix | Delete
* 2. If $category matches. Only notices for $user are checked.
[60] Fix | Delete
*
[61] Fix | Delete
* @param bool|int $id
[62] Fix | Delete
* @param bool|string $category
[63] Fix | Delete
* @param bool|\WP_User $user
[64] Fix | Delete
*/
[65] Fix | Delete
public function remove_notice($id = false, $category = false, $user = false) {
[66] Fix | Delete
if ($id === false && $category === false) {
[67] Fix | Delete
return;
[68] Fix | Delete
}
[69] Fix | Delete
else if ($id !== false) {
[70] Fix | Delete
$category = false;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
$notices = $this->_notices($user);
[74] Fix | Delete
foreach ($notices as $nid => $n) {
[75] Fix | Delete
if ($id == $nid) { //ID match
[76] Fix | Delete
unset($notices[$nid]);
[77] Fix | Delete
break;
[78] Fix | Delete
}
[79] Fix | Delete
else if ($id !== false) {
[80] Fix | Delete
continue;
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
if ($category !== false && isset($n['category']) && $category == $n['category']) { //Category match
[84] Fix | Delete
unset($notices[$nid]);
[85] Fix | Delete
}
[86] Fix | Delete
}
[87] Fix | Delete
$this->_save_notices($notices, $user);
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* Returns whether or not a notice exists for the given user.
[92] Fix | Delete
*
[93] Fix | Delete
* @param bool|\WP_User $user
[94] Fix | Delete
* @return bool
[95] Fix | Delete
*/
[96] Fix | Delete
public function has_notice($user) {
[97] Fix | Delete
$notices = $this->_notices($user);
[98] Fix | Delete
return !!count($notices) || $this->has_persistent_notices();
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
/**
[102] Fix | Delete
* Enqueues a user's notices. For administrators this also includes global notices.
[103] Fix | Delete
*
[104] Fix | Delete
* @return bool Whether any notices were enqueued.
[105] Fix | Delete
*/
[106] Fix | Delete
public function enqueue_notices() {
[107] Fix | Delete
$user = wp_get_current_user();
[108] Fix | Delete
if ($user->ID == 0) {
[109] Fix | Delete
return false;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
$added = false;
[113] Fix | Delete
$notices = array();
[114] Fix | Delete
if (Controller_Permissions::shared()->can_manage_settings($user)) {
[115] Fix | Delete
$globalNotices = $this->_notices(false);
[116] Fix | Delete
$notices = array_merge($notices, $globalNotices);
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
$userNotices = $this->_notices($user);
[120] Fix | Delete
$notices = array_merge($notices, $userNotices);
[121] Fix | Delete
[122] Fix | Delete
foreach ($notices as $nid => $n) {
[123] Fix | Delete
$notice = new Model_Notice($nid, $n['severity'], $n['messageHTML'], $n['category']);
[124] Fix | Delete
if (is_multisite()) {
[125] Fix | Delete
add_action('network_admin_notices', array($notice, 'display_notice'));
[126] Fix | Delete
}
[127] Fix | Delete
else {
[128] Fix | Delete
add_action('admin_notices', array($notice, 'display_notice'));
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
$added = true;
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
return $added;
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
/**
[138] Fix | Delete
* Utility
[139] Fix | Delete
*/
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* Returns the notices for a user if provided, otherwise the global notices.
[143] Fix | Delete
*
[144] Fix | Delete
* @param bool|\WP_User $user
[145] Fix | Delete
* @return array
[146] Fix | Delete
*/
[147] Fix | Delete
protected function _notices($user) {
[148] Fix | Delete
if ($user instanceof \WP_User) {
[149] Fix | Delete
$notices = get_user_meta($user->ID, self::USER_META_KEY, true);
[150] Fix | Delete
return array_filter((array) $notices);
[151] Fix | Delete
}
[152] Fix | Delete
return Controller_Settings::shared()->get_array(Controller_Settings::OPTION_GLOBAL_NOTICES);
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
/**
[156] Fix | Delete
* Saves the notices.
[157] Fix | Delete
*
[158] Fix | Delete
* @param array $notices
[159] Fix | Delete
* @param bool|\WP_User $user
[160] Fix | Delete
*/
[161] Fix | Delete
protected function _save_notices($notices, $user) {
[162] Fix | Delete
if ($user instanceof \WP_User) {
[163] Fix | Delete
update_user_meta($user->ID, self::USER_META_KEY, $notices);
[164] Fix | Delete
return;
[165] Fix | Delete
}
[166] Fix | Delete
Controller_Settings::shared()->set_array(Controller_Settings::OPTION_GLOBAL_NOTICES, $notices, true);
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
public function get_persistent_notice_ids() {
[170] Fix | Delete
return array(
[171] Fix | Delete
self::PERSISTENT_NOTICE_WOOCOMMERCE_INTEGRATION
[172] Fix | Delete
);
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
private static function get_persistent_notice_dismiss_key($noticeId) {
[176] Fix | Delete
return self::PERSISTENT_NOTICE_DISMISS_PREFIX . $noticeId;
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
public function register_persistent_notice($noticeId) {
[180] Fix | Delete
$this->persistentNotices[] = $noticeId;
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
public function has_persistent_notices() {
[184] Fix | Delete
return count($this->persistentNotices) > 0;
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
public function dismiss_persistent_notice($userId, $noticeId) {
[188] Fix | Delete
if (!in_array($noticeId, $this->get_persistent_notice_ids(), true))
[189] Fix | Delete
return false;
[190] Fix | Delete
update_user_option($userId, self::get_persistent_notice_dismiss_key($noticeId), true, true);
[191] Fix | Delete
return true;
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
public function is_persistent_notice_dismissed($userId, $noticeId) {
[195] Fix | Delete
return (bool) get_user_option(self::get_persistent_notice_dismiss_key($noticeId), $userId);
[196] Fix | Delete
}
[197] Fix | Delete
}
[198] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function