PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | modules/notifications/options.php +26 -18 4.1.24.3.0-beta3 View file →
@@ -3,26 +3,9 @@
3 3
4 4 class Options {
5 5
6 6 public static function has_unread_notifications(): bool {
7 - $current_user = wp_get_current_user();
8 -
9 - if ( ! $current_user ) {
10 - return false;
11 - }
12 -
13 - $unread_notifications = get_transient( "elementor_unread_notifications_{$current_user->ID}" );
14 -
15 - if ( false === $unread_notifications ) {
16 - $notifications = API::get_notifications_by_conditions();
17 - $notifications_ids = wp_list_pluck( $notifications, 'id' );
18 -
19 - $unread_notifications = array_diff( $notifications_ids, static::get_notifications_dismissed() );
20 -
21 - set_transient( "elementor_unread_notifications_{$current_user->ID}", $unread_notifications, HOUR_IN_SECONDS );
22 - }
23 -
24 - return ! empty( $unread_notifications );
7 + return ! empty( static::get_unread_notification_ids() );
25 8 }
26 9
27 10 public static function get_notifications_dismissed() {
28 11 $current_user = wp_get_current_user();
@@ -39,8 +22,12 @@
39 22
40 23 return $notifications_dismissed;
41 24 }
42 25
26 + public static function get_unread_count(): int {
27 + return count( static::get_unread_notification_ids() );
28 + }
29 +
43 30 public static function mark_notification_read( $notifications ): bool {
44 31 $current_user = wp_get_current_user();
45 32
46 33 if ( ! $current_user ) {
@@ -61,6 +48,27 @@
61 48
62 49 delete_transient( "elementor_unread_notifications_{$current_user->ID}" );
63 50
64 51 return true;
52 + }
53 +
54 + private static function get_unread_notification_ids(): array {
55 + $current_user = wp_get_current_user();
56 +
57 + if ( ! $current_user ) {
58 + return [];
59 + }
60 +
61 + $unread_notifications = get_transient( "elementor_unread_notifications_{$current_user->ID}" );
62 +
63 + if ( false === $unread_notifications ) {
64 + $notifications = API::get_notifications_by_conditions();
65 + $notifications_ids = wp_list_pluck( $notifications, 'id' );
66 +
67 + $unread_notifications = array_diff( $notifications_ids, static::get_notifications_dismissed() );
68 +
69 + set_transient( "elementor_unread_notifications_{$current_user->ID}", $unread_notifications, HOUR_IN_SECONDS );
70 + }
71 +
72 + return $unread_notifications;
65 73 }
66 74 }