| @@ -2,10 +2,27 @@ | ||
| 2 | 2 | namespace Elementor\Modules\Notifications; |
| 3 | 3 | |
| 4 | 4 | class Options { |
| 5 | 5 | |
| 6 | - public static function has_unread_notifications(): bool { | |
| 7 | - return ! empty( static::get_unread_notification_ids() ); | |
| 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 ); | |
| 8 | 25 | } |
| 9 | 26 | |
| 10 | 27 | public static function get_notifications_dismissed() { |
| 11 | 28 | $current_user = wp_get_current_user(); |
| @@ -22,13 +39,9 @@ | ||
| 22 | 39 | |
| 23 | 40 | return $notifications_dismissed; |
| 24 | 41 | } |
| 25 | 42 | |
| 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 { | |
| 43 | + public static function mark_notification_read( $notifications ) : bool { | |
| 31 | 44 | $current_user = wp_get_current_user(); |
| 32 | 45 | |
| 33 | 46 | if ( ! $current_user ) { |
| 34 | 47 | return false; |
| @@ -48,27 +61,6 @@ | ||
| 48 | 61 | |
| 49 | 62 | delete_transient( "elementor_unread_notifications_{$current_user->ID}" ); |
| 50 | 63 | |
| 51 | 64 | 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 | 65 | } |
| 74 | 66 | } |