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/clone/wp-conte.../plugins/wordpres.../admin
File: class-yoast-notification-center.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WPSEO plugin file.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WPSEO\Admin\Notifications
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
use Yoast\WP\SEO\Presenters\Abstract_Presenter;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Handles notifications storage and display.
[10] Fix | Delete
*/
[11] Fix | Delete
class Yoast_Notification_Center {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Option name to store notifications on.
[15] Fix | Delete
*
[16] Fix | Delete
* @var string
[17] Fix | Delete
*/
[18] Fix | Delete
public const STORAGE_KEY = 'yoast_notifications';
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* The singleton instance of this object.
[22] Fix | Delete
*
[23] Fix | Delete
* @var Yoast_Notification_Center
[24] Fix | Delete
*/
[25] Fix | Delete
private static $instance = null;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Holds the notifications.
[29] Fix | Delete
*
[30] Fix | Delete
* @var Yoast_Notification[][]
[31] Fix | Delete
*/
[32] Fix | Delete
private $notifications = [];
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Notifications there are newly added.
[36] Fix | Delete
*
[37] Fix | Delete
* @var array
[38] Fix | Delete
*/
[39] Fix | Delete
private $new = [];
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Notifications that were resolved this execution.
[43] Fix | Delete
*
[44] Fix | Delete
* @var int
[45] Fix | Delete
*/
[46] Fix | Delete
private $resolved = 0;
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* Internal storage for transaction before notifications have been retrieved from storage.
[50] Fix | Delete
*
[51] Fix | Delete
* @var array
[52] Fix | Delete
*/
[53] Fix | Delete
private $queued_transactions = [];
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Internal flag for whether notifications have been retrieved from storage.
[57] Fix | Delete
*
[58] Fix | Delete
* @var bool
[59] Fix | Delete
*/
[60] Fix | Delete
private $notifications_retrieved = false;
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Internal flag for whether notifications need to be updated in storage.
[64] Fix | Delete
*
[65] Fix | Delete
* @var bool
[66] Fix | Delete
*/
[67] Fix | Delete
private $notifications_need_storage = false;
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Construct.
[71] Fix | Delete
*/
[72] Fix | Delete
private function __construct() {
[73] Fix | Delete
[74] Fix | Delete
add_action( 'init', [ $this, 'setup_current_notifications' ], 1 );
[75] Fix | Delete
[76] Fix | Delete
add_action( 'all_admin_notices', [ $this, 'display_notifications' ] );
[77] Fix | Delete
[78] Fix | Delete
add_action( 'wp_ajax_yoast_get_notifications', [ $this, 'ajax_get_notifications' ] );
[79] Fix | Delete
[80] Fix | Delete
add_action( 'wpseo_deactivate', [ $this, 'deactivate_hook' ] );
[81] Fix | Delete
add_action( 'shutdown', [ $this, 'update_storage' ] );
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* Singleton getter.
[86] Fix | Delete
*
[87] Fix | Delete
* @return Yoast_Notification_Center
[88] Fix | Delete
*/
[89] Fix | Delete
public static function get() {
[90] Fix | Delete
[91] Fix | Delete
if ( self::$instance === null ) {
[92] Fix | Delete
self::$instance = new self();
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
return self::$instance;
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Dismiss a notification.
[100] Fix | Delete
*
[101] Fix | Delete
* @return void
[102] Fix | Delete
*/
[103] Fix | Delete
public static function ajax_dismiss_notification() {
[104] Fix | Delete
$notification_center = self::get();
[105] Fix | Delete
[106] Fix | Delete
if ( ! isset( $_POST['notification'] ) || ! is_string( $_POST['notification'] ) ) {
[107] Fix | Delete
die( '-1' );
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
$notification_id = sanitize_text_field( wp_unslash( $_POST['notification'] ) );
[111] Fix | Delete
[112] Fix | Delete
if ( empty( $notification_id ) ) {
[113] Fix | Delete
die( '-1' );
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are using the variable as a nonce.
[117] Fix | Delete
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['nonce'] ), $notification_id ) ) {
[118] Fix | Delete
die( '-1' );
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
$notification = $notification_center->get_notification_by_id( $notification_id );
[122] Fix | Delete
if ( ( $notification instanceof Yoast_Notification ) === false ) {
[123] Fix | Delete
[124] Fix | Delete
// Permit legacy.
[125] Fix | Delete
$options = [
[126] Fix | Delete
'id' => $notification_id,
[127] Fix | Delete
'dismissal_key' => $notification_id,
[128] Fix | Delete
];
[129] Fix | Delete
$notification = new Yoast_Notification( '', $options );
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
if ( self::maybe_dismiss_notification( $notification ) ) {
[133] Fix | Delete
die( '1' );
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
die( '-1' );
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Check if the user has dismissed a notification.
[141] Fix | Delete
*
[142] Fix | Delete
* @param Yoast_Notification $notification The notification to check for dismissal.
[143] Fix | Delete
* @param int|null $user_id User ID to check on.
[144] Fix | Delete
*
[145] Fix | Delete
* @return bool
[146] Fix | Delete
*/
[147] Fix | Delete
public static function is_notification_dismissed( Yoast_Notification $notification, $user_id = null ) {
[148] Fix | Delete
[149] Fix | Delete
$user_id = self::get_user_id( $user_id );
[150] Fix | Delete
$dismissal_key = $notification->get_dismissal_key();
[151] Fix | Delete
[152] Fix | Delete
// This checks both the site-specific user option and the meta value.
[153] Fix | Delete
$current_value = get_user_option( $dismissal_key, $user_id );
[154] Fix | Delete
[155] Fix | Delete
// Migrate old user meta to user option on-the-fly.
[156] Fix | Delete
if ( ! empty( $current_value )
[157] Fix | Delete
&& metadata_exists( 'user', $user_id, $dismissal_key )
[158] Fix | Delete
&& update_user_option( $user_id, $dismissal_key, $current_value ) ) {
[159] Fix | Delete
delete_user_meta( $user_id, $dismissal_key );
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
return ! empty( $current_value );
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
/**
[166] Fix | Delete
* Checks if the notification is being dismissed.
[167] Fix | Delete
*
[168] Fix | Delete
* @param Yoast_Notification $notification Notification to check dismissal of.
[169] Fix | Delete
* @param string $meta_value Value to set the meta value to if dismissed.
[170] Fix | Delete
*
[171] Fix | Delete
* @return bool True if dismissed.
[172] Fix | Delete
*/
[173] Fix | Delete
public static function maybe_dismiss_notification( Yoast_Notification $notification, $meta_value = 'seen' ) {
[174] Fix | Delete
[175] Fix | Delete
// Only persistent notifications are dismissible.
[176] Fix | Delete
if ( ! $notification->is_persistent() ) {
[177] Fix | Delete
return false;
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
// If notification is already dismissed, we're done.
[181] Fix | Delete
if ( self::is_notification_dismissed( $notification ) ) {
[182] Fix | Delete
return true;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
$dismissal_key = $notification->get_dismissal_key();
[186] Fix | Delete
$notification_id = $notification->get_id();
[187] Fix | Delete
[188] Fix | Delete
$is_dismissing = ( $dismissal_key === self::get_user_input( 'notification' ) );
[189] Fix | Delete
if ( ! $is_dismissing ) {
[190] Fix | Delete
$is_dismissing = ( $notification_id === self::get_user_input( 'notification' ) );
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
// Fallback to ?dismissal_key=1&nonce=bla when JavaScript fails.
[194] Fix | Delete
if ( ! $is_dismissing ) {
[195] Fix | Delete
$is_dismissing = ( self::get_user_input( $dismissal_key ) === '1' );
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
if ( ! $is_dismissing ) {
[199] Fix | Delete
return false;
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
$user_nonce = self::get_user_input( 'nonce' );
[203] Fix | Delete
if ( wp_verify_nonce( $user_nonce, $notification_id ) === false ) {
[204] Fix | Delete
return false;
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
return self::dismiss_notification( $notification, $meta_value );
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
/**
[211] Fix | Delete
* Dismisses a notification.
[212] Fix | Delete
*
[213] Fix | Delete
* @param Yoast_Notification $notification Notification to dismiss.
[214] Fix | Delete
* @param string $meta_value Value to save in the dismissal.
[215] Fix | Delete
*
[216] Fix | Delete
* @return bool True if dismissed, false otherwise.
[217] Fix | Delete
*/
[218] Fix | Delete
public static function dismiss_notification( Yoast_Notification $notification, $meta_value = 'seen' ) {
[219] Fix | Delete
// Dismiss notification.
[220] Fix | Delete
return update_user_option( get_current_user_id(), $notification->get_dismissal_key(), $meta_value ) !== false;
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
/**
[224] Fix | Delete
* Restores a notification.
[225] Fix | Delete
*
[226] Fix | Delete
* @param Yoast_Notification $notification Notification to restore.
[227] Fix | Delete
*
[228] Fix | Delete
* @return bool True if restored, false otherwise.
[229] Fix | Delete
*/
[230] Fix | Delete
public static function restore_notification( Yoast_Notification $notification ) {
[231] Fix | Delete
[232] Fix | Delete
$user_id = get_current_user_id();
[233] Fix | Delete
$dismissal_key = $notification->get_dismissal_key();
[234] Fix | Delete
[235] Fix | Delete
// Restore notification.
[236] Fix | Delete
$restored = delete_user_option( $user_id, $dismissal_key );
[237] Fix | Delete
[238] Fix | Delete
// Delete unprefixed user meta too for backward-compatibility.
[239] Fix | Delete
if ( metadata_exists( 'user', $user_id, $dismissal_key ) ) {
[240] Fix | Delete
$restored = delete_user_meta( $user_id, $dismissal_key ) && $restored;
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
return $restored;
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
/**
[247] Fix | Delete
* Clear dismissal information for the specified Notification.
[248] Fix | Delete
*
[249] Fix | Delete
* When a cause is resolved, the next time it is present we want to show
[250] Fix | Delete
* the message again.
[251] Fix | Delete
*
[252] Fix | Delete
* @param string|Yoast_Notification $notification Notification to clear the dismissal of.
[253] Fix | Delete
*
[254] Fix | Delete
* @return bool
[255] Fix | Delete
*/
[256] Fix | Delete
public function clear_dismissal( $notification ) {
[257] Fix | Delete
[258] Fix | Delete
global $wpdb;
[259] Fix | Delete
[260] Fix | Delete
if ( $notification instanceof Yoast_Notification ) {
[261] Fix | Delete
$dismissal_key = $notification->get_dismissal_key();
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
if ( is_string( $notification ) ) {
[265] Fix | Delete
$dismissal_key = $notification;
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
if ( empty( $dismissal_key ) ) {
[269] Fix | Delete
return false;
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
// Remove notification dismissal for all users.
[273] Fix | Delete
$deleted = delete_metadata( 'user', 0, $wpdb->get_blog_prefix() . $dismissal_key, '', true );
[274] Fix | Delete
[275] Fix | Delete
// Delete unprefixed user meta too for backward-compatibility.
[276] Fix | Delete
$deleted = delete_metadata( 'user', 0, $dismissal_key, '', true ) || $deleted;
[277] Fix | Delete
[278] Fix | Delete
return $deleted;
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
/**
[282] Fix | Delete
* Retrieves notifications from the storage and merges in previous notification changes.
[283] Fix | Delete
*
[284] Fix | Delete
* The current user in WordPress is not loaded shortly before the 'init' hook, but the plugin
[285] Fix | Delete
* sometimes needs to add or remove notifications before that. In such cases, the transactions
[286] Fix | Delete
* are not actually executed, but added to a queue. That queue is then handled in this method,
[287] Fix | Delete
* after notifications for the current user have been set up.
[288] Fix | Delete
*
[289] Fix | Delete
* @return void
[290] Fix | Delete
*/
[291] Fix | Delete
public function setup_current_notifications() {
[292] Fix | Delete
$this->retrieve_notifications_from_storage( get_current_user_id() );
[293] Fix | Delete
[294] Fix | Delete
foreach ( $this->queued_transactions as $transaction ) {
[295] Fix | Delete
list( $callback, $args ) = $transaction;
[296] Fix | Delete
[297] Fix | Delete
call_user_func_array( $callback, $args );
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
$this->queued_transactions = [];
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
/**
[304] Fix | Delete
* Add notification to the cookie.
[305] Fix | Delete
*
[306] Fix | Delete
* @param Yoast_Notification $notification Notification object instance.
[307] Fix | Delete
*
[308] Fix | Delete
* @return void
[309] Fix | Delete
*/
[310] Fix | Delete
public function add_notification( Yoast_Notification $notification ) {
[311] Fix | Delete
[312] Fix | Delete
$callback = [ $this, __FUNCTION__ ];
[313] Fix | Delete
$args = func_get_args();
[314] Fix | Delete
if ( $this->queue_transaction( $callback, $args ) ) {
[315] Fix | Delete
return;
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
// Don't add if the user can't see it.
[319] Fix | Delete
if ( ! $notification->display_for_current_user() ) {
[320] Fix | Delete
return;
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
$notification_id = $notification->get_id();
[324] Fix | Delete
$user_id = $notification->get_user_id();
[325] Fix | Delete
[326] Fix | Delete
// Empty notifications are always added.
[327] Fix | Delete
if ( $notification_id !== '' ) {
[328] Fix | Delete
[329] Fix | Delete
// If notification ID exists in notifications, don't add again.
[330] Fix | Delete
$present_notification = $this->get_notification_by_id( $notification_id, $user_id );
[331] Fix | Delete
if ( ! is_null( $present_notification ) ) {
[332] Fix | Delete
$this->remove_notification( $present_notification, false );
[333] Fix | Delete
}
[334] Fix | Delete
[335] Fix | Delete
if ( is_null( $present_notification ) ) {
[336] Fix | Delete
$this->new[] = $notification_id;
[337] Fix | Delete
}
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
// Add to list.
[341] Fix | Delete
$this->notifications[ $user_id ][] = $notification;
[342] Fix | Delete
[343] Fix | Delete
$this->notifications_need_storage = true;
[344] Fix | Delete
}
[345] Fix | Delete
[346] Fix | Delete
/**
[347] Fix | Delete
* Get the notification by ID and user ID.
[348] Fix | Delete
*
[349] Fix | Delete
* @param string $notification_id The ID of the notification to search for.
[350] Fix | Delete
* @param int|null $user_id The ID of the user.
[351] Fix | Delete
*
[352] Fix | Delete
* @return Yoast_Notification|null
[353] Fix | Delete
*/
[354] Fix | Delete
public function get_notification_by_id( $notification_id, $user_id = null ) {
[355] Fix | Delete
$user_id = self::get_user_id( $user_id );
[356] Fix | Delete
[357] Fix | Delete
$notifications = $this->get_notifications_for_user( $user_id );
[358] Fix | Delete
[359] Fix | Delete
foreach ( $notifications as $notification ) {
[360] Fix | Delete
if ( $notification_id === $notification->get_id() ) {
[361] Fix | Delete
return $notification;
[362] Fix | Delete
}
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
return null;
[366] Fix | Delete
}
[367] Fix | Delete
[368] Fix | Delete
/**
[369] Fix | Delete
* Display the notifications.
[370] Fix | Delete
*
[371] Fix | Delete
* @param bool $echo_as_json True when notifications should be printed directly.
[372] Fix | Delete
*
[373] Fix | Delete
* @return void
[374] Fix | Delete
*/
[375] Fix | Delete
public function display_notifications( $echo_as_json = false ) {
[376] Fix | Delete
[377] Fix | Delete
// Never display notifications for network admin.
[378] Fix | Delete
if ( is_network_admin() ) {
[379] Fix | Delete
return;
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
$sorted_notifications = $this->get_sorted_notifications();
[383] Fix | Delete
$notifications = array_filter( $sorted_notifications, [ $this, 'is_notification_persistent' ] );
[384] Fix | Delete
[385] Fix | Delete
if ( empty( $notifications ) ) {
[386] Fix | Delete
return;
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
array_walk( $notifications, [ $this, 'remove_notification' ] );
[390] Fix | Delete
[391] Fix | Delete
$notifications = array_unique( $notifications );
[392] Fix | Delete
if ( $echo_as_json ) {
[393] Fix | Delete
$notification_json = [];
[394] Fix | Delete
[395] Fix | Delete
foreach ( $notifications as $notification ) {
[396] Fix | Delete
$notification_json[] = $notification->render();
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: WPSEO_Utils::format_json_encode is safe.
[400] Fix | Delete
echo WPSEO_Utils::format_json_encode( $notification_json );
[401] Fix | Delete
[402] Fix | Delete
return;
[403] Fix | Delete
}
[404] Fix | Delete
[405] Fix | Delete
foreach ( $notifications as $notification ) {
[406] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: Temporarily disabled, see: https://github.com/Yoast/wordpress-seo-premium/issues/2510 and https://github.com/Yoast/wordpress-seo-premium/issues/2511.
[407] Fix | Delete
echo $notification;
[408] Fix | Delete
}
[409] Fix | Delete
}
[410] Fix | Delete
[411] Fix | Delete
/**
[412] Fix | Delete
* Remove notification after it has been displayed.
[413] Fix | Delete
*
[414] Fix | Delete
* @param Yoast_Notification $notification Notification to remove.
[415] Fix | Delete
* @param bool $resolve Resolve as fixed.
[416] Fix | Delete
*
[417] Fix | Delete
* @return void
[418] Fix | Delete
*/
[419] Fix | Delete
public function remove_notification( Yoast_Notification $notification, $resolve = true ) {
[420] Fix | Delete
[421] Fix | Delete
$callback = [ $this, __FUNCTION__ ];
[422] Fix | Delete
$args = func_get_args();
[423] Fix | Delete
if ( $this->queue_transaction( $callback, $args ) ) {
[424] Fix | Delete
return;
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
$index = false;
[428] Fix | Delete
[429] Fix | Delete
// ID of the user to show the notification for, defaults to current user id.
[430] Fix | Delete
$user_id = $notification->get_user_id();
[431] Fix | Delete
$notifications = $this->get_notifications_for_user( $user_id );
[432] Fix | Delete
[433] Fix | Delete
// Match persistent Notifications by ID, non persistent by item in the array.
[434] Fix | Delete
if ( $notification->is_persistent() ) {
[435] Fix | Delete
foreach ( $notifications as $current_index => $present_notification ) {
[436] Fix | Delete
if ( $present_notification->get_id() === $notification->get_id() ) {
[437] Fix | Delete
$index = $current_index;
[438] Fix | Delete
break;
[439] Fix | Delete
}
[440] Fix | Delete
}
[441] Fix | Delete
}
[442] Fix | Delete
else {
[443] Fix | Delete
$index = array_search( $notification, $notifications, true );
[444] Fix | Delete
}
[445] Fix | Delete
[446] Fix | Delete
if ( $index === false ) {
[447] Fix | Delete
return;
[448] Fix | Delete
}
[449] Fix | Delete
[450] Fix | Delete
if ( $notification->is_persistent() && $resolve ) {
[451] Fix | Delete
++$this->resolved;
[452] Fix | Delete
$this->clear_dismissal( $notification );
[453] Fix | Delete
}
[454] Fix | Delete
[455] Fix | Delete
unset( $notifications[ $index ] );
[456] Fix | Delete
$this->notifications[ $user_id ] = array_values( $notifications );
[457] Fix | Delete
[458] Fix | Delete
$this->notifications_need_storage = true;
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
/**
[462] Fix | Delete
* Removes a notification by its ID.
[463] Fix | Delete
*
[464] Fix | Delete
* @param string $notification_id The notification id.
[465] Fix | Delete
* @param bool $resolve Resolve as fixed.
[466] Fix | Delete
*
[467] Fix | Delete
* @return void
[468] Fix | Delete
*/
[469] Fix | Delete
public function remove_notification_by_id( $notification_id, $resolve = true ) {
[470] Fix | Delete
$notification = $this->get_notification_by_id( $notification_id );
[471] Fix | Delete
[472] Fix | Delete
if ( $notification === null ) {
[473] Fix | Delete
return;
[474] Fix | Delete
}
[475] Fix | Delete
[476] Fix | Delete
$this->remove_notification( $notification, $resolve );
[477] Fix | Delete
$this->notifications_need_storage = true;
[478] Fix | Delete
}
[479] Fix | Delete
[480] Fix | Delete
/**
[481] Fix | Delete
* Get the notification count.
[482] Fix | Delete
*
[483] Fix | Delete
* @param bool $dismissed Count dismissed notifications.
[484] Fix | Delete
*
[485] Fix | Delete
* @return int Number of notifications
[486] Fix | Delete
*/
[487] Fix | Delete
public function get_notification_count( $dismissed = false ) {
[488] Fix | Delete
[489] Fix | Delete
$notifications = $this->get_notifications_for_user( get_current_user_id() );
[490] Fix | Delete
$notifications = array_filter( $notifications, [ $this, 'filter_persistent_notifications' ] );
[491] Fix | Delete
[492] Fix | Delete
if ( ! $dismissed ) {
[493] Fix | Delete
$notifications = array_filter( $notifications, [ $this, 'filter_dismissed_notifications' ] );
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
return count( $notifications );
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function