diff --git src/bp-notifications/bp-notifications-cache.php src/bp-notifications/bp-notifications-cache.php
index 3d59e770f..981190052 100644
|
|
function bp_notifications_update_meta_cache( $notification_ids = false ) { |
43 | 43 | */ |
44 | 44 | function bp_notifications_clear_all_for_user_cache( $user_id = 0 ) { |
45 | 45 | wp_cache_delete( 'all_for_user_' . $user_id, 'bp_notifications' ); |
| 46 | wp_cache_delete( $user_id, 'bp_notifications_unread_count' ); |
46 | 47 | } |
47 | 48 | |
48 | 49 | /** |
diff --git src/bp-notifications/bp-notifications-functions.php src/bp-notifications/bp-notifications-functions.php
index 09831f9f1..dd20212ad 100644
|
|
function bp_notifications_check_notification_access( $user_id, $notification_id |
607 | 607 | * @return int Unread notification count. |
608 | 608 | */ |
609 | 609 | function bp_notifications_get_unread_notification_count( $user_id = 0 ) { |
610 | | $notifications = bp_notifications_get_all_notifications_for_user( $user_id ); |
611 | | $count = ! empty( $notifications ) ? count( $notifications ) : 0; |
| 610 | if ( empty( $user_id ) ) { |
| 611 | $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); |
| 612 | } |
| 613 | |
| 614 | $count = wp_cache_get( $user_id, 'bp_notifications_unread_count' ); |
| 615 | if ( false === $count ) { |
| 616 | $count = BP_Notifications_Notification::get_total_count( array( |
| 617 | 'user_id' => $user_id, |
| 618 | 'is_new' => true, |
| 619 | ) ); |
| 620 | wp_cache_set( $user_id, $count, 'bp_notifications_unread_count' ); |
| 621 | } |
612 | 622 | |
613 | 623 | /** |
614 | 624 | * Filters the count of unread notification items for a user. |
diff --git tests/phpunit/testcases/notifications/functions.php tests/phpunit/testcases/notifications/functions.php
index ee1b01a76..89b83fd14 100644
|
|
class BP_Tests_Notifications_Functions extends BP_UnitTestCase { |
35 | 35 | ) ); |
36 | 36 | |
37 | 37 | $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) ); |
| 38 | $this->assertFalse( wp_cache_get( $u, 'bp_notifications_unread_count' ) ); |
38 | 39 | } |
39 | 40 | |
40 | 41 | /** |
… |
… |
class BP_Tests_Notifications_Functions extends BP_UnitTestCase { |
61 | 62 | BP_Notifications_Notification::delete( array( 'id' => $n1, ) ); |
62 | 63 | |
63 | 64 | $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) ); |
| 65 | $this->assertFalse( wp_cache_get( $u, 'bp_notifications_unread_count' ) ); |
64 | 66 | } |
65 | 67 | |
66 | 68 | /** |
… |
… |
class BP_Tests_Notifications_Functions extends BP_UnitTestCase { |
91 | 93 | ); |
92 | 94 | |
93 | 95 | $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) ); |
| 96 | $this->assertFalse( wp_cache_get( $u, 'bp_notifications_unread_count' ) ); |
94 | 97 | } |
95 | 98 | |
96 | 99 | /** |
… |
… |
class BP_Tests_Notifications_Functions extends BP_UnitTestCase { |
121 | 124 | ); |
122 | 125 | |
123 | 126 | $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) ); |
| 127 | $this->assertFalse( wp_cache_get( $u, 'bp_notifications_unread_count' ) ); |
124 | 128 | } |
125 | 129 | |
126 | 130 | /** |