PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta1
Elementor Website Builder – more than just a page builder v4.3.0-beta1
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 4.0.7 All 451 releases
elementor / modules / notifications / options.php

options.php in Elementor Website Builder – more than just a page builder 4.3.0-beta1, at modules/notifications/options.php

75 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\Notifications;
3
4 class Options {
5
6 public static function has_unread_notifications(): bool {
7 return ! empty( static::get_unread_notification_ids() );
8 }
9
10 public static function get_notifications_dismissed() {
11 $current_user = wp_get_current_user();
12
13 if ( ! $current_user ) {
14 return [];
15 }
16
17 $notifications_dismissed = get_user_meta( $current_user->ID, '_e_notifications_dismissed', true );
18
19 if ( ! is_array( $notifications_dismissed ) ) {
20 $notifications_dismissed = [];
21 }
22
23 return $notifications_dismissed;
24 }
25
26 public static function get_unread_count(): int {
27 return count( static::get_unread_notification_ids() );
28 }
29
30 public static function mark_notification_read( $notifications ): bool {
31 $current_user = wp_get_current_user();
32
33 if ( ! $current_user ) {
34 return false;
35 }
36
37 $notifications_dismissed = static::get_notifications_dismissed();
38
39 foreach ( $notifications as $notification ) {
40 if ( ! in_array( $notification['id'], $notifications_dismissed, true ) ) {
41 $notifications_dismissed[] = $notification['id'];
42 }
43 }
44
45 $notifications_dismissed = array_unique( $notifications_dismissed );
46
47 update_user_meta( $current_user->ID, '_e_notifications_dismissed', $notifications_dismissed );
48
49 delete_transient( "elementor_unread_notifications_{$current_user->ID}" );
50
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;
73 }
74 }
75