PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.3
Elementor Website Builder – more than just a page builder v3.35.3
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 3.35.3, at modules/notifications/options.php

67 lines 1.8 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 $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 );
25 }
26
27 public static function get_notifications_dismissed() {
28 $current_user = wp_get_current_user();
29
30 if ( ! $current_user ) {
31 return [];
32 }
33
34 $notifications_dismissed = get_user_meta( $current_user->ID, '_e_notifications_dismissed', true );
35
36 if ( ! is_array( $notifications_dismissed ) ) {
37 $notifications_dismissed = [];
38 }
39
40 return $notifications_dismissed;
41 }
42
43 public static function mark_notification_read( $notifications ): bool {
44 $current_user = wp_get_current_user();
45
46 if ( ! $current_user ) {
47 return false;
48 }
49
50 $notifications_dismissed = static::get_notifications_dismissed();
51
52 foreach ( $notifications as $notification ) {
53 if ( ! in_array( $notification['id'], $notifications_dismissed, true ) ) {
54 $notifications_dismissed[] = $notification['id'];
55 }
56 }
57
58 $notifications_dismissed = array_unique( $notifications_dismissed );
59
60 update_user_meta( $current_user->ID, '_e_notifications_dismissed', $notifications_dismissed );
61
62 delete_transient( "elementor_unread_notifications_{$current_user->ID}" );
63
64 return true;
65 }
66 }
67