/** * @group cache */ public function test_cache_invalidation_all_for_user_on_update_id() { $u = $this->factory->user->create(); $n1 = $this->factory->notification->create(array('component_name' => 'groups', 'user_id' => $u)); $this->factory->notification->create(array('component_name' => 'messages', 'user_id' => $u)); // prime cache $count = bp_notifications_get_unread_notification_count($u); // just to be sure... $this->assertEquals(2, $count, 'Cache count should be 2 before invalidation.'); // mark one notification as read BP_Notifications_Notification::update(array('is_new' => false), array('id' => $n1)); $this->assertFalse(wp_cache_get('all_for_user_' . $u, 'bp_notifications')); }
/** * Mark all notifications read/unread from a user. * * Used when clearing out all notifications for a user, when deleted or spammed. * * @todo This function assumes that items with the user_id in the item_id slot * are associated with that user. However, this will only be true with * certain components (such as Friends). Use with caution! * * @since BuddyPress (1.9.0) * * @param int $user_id ID of the user whose associated items are being deleted. * @param int $is_new 0 for read, 1 for unread * @param string $component_name Name of the associated component. * @param string $component_action Name of the associated action. * @param int $is_new 0 for read, 1 for unread. * @return bool True on success, false on failure. */ function bp_notifications_mark_notifications_from_user($user_id, $component_name, $component_action, $is_new = false) { return BP_Notifications_Notification::update(array('is_new' => $is_new), array('item_id' => $user_id, 'component_name' => $component_name, 'component_action' => $component_action)); }
/** * Mark non-mention notifications as read when user visits our read permalink. * * In particular, 'update_reply' and 'comment_reply' notifications are handled * here. See {@link bp_activity_format_notifications()} for more info. * * @since 2.6.0 */ function bp_activity_remove_screen_notifications_for_non_mentions() { if (false === is_singular() || false === is_user_logged_in() || empty($_GET['nid'])) { return; } // Mark notification as read. BP_Notifications_Notification::update(array('is_new' => false), array('user_id' => bp_loggedin_user_id(), 'id' => (int) $_GET['nid'])); }
/** * Marks notification connected to post as read * @param array|int $post * @return void */ public function mark_notification_as_read($post) { if (!is_single($post)) { return; } if (is_object($post)) { $post_id = $post->ID; } elseif (is_array($post)) { $post_id = $post['ID']; } elseif (is_numeric($post)) { $post_id = $post; } if (isset($post_id)) { BP_Notifications_Notification::update(array('is_new' => false), array('user_id' => get_current_user_id(), 'item_id' => $post_id, 'secondary_item_id' => get_current_blog_id(), 'component_name' => $this->id, 'component_action' => 'new_post_' . $post_id)); } }
/** * Mark a notification. * * @since 1.0.0 * * @param int|bool $user_id The ID of the user associated with the notification. * @param int|bool $item_id The ID of the item associated with the notification. * @param int|bool $secondary_item_id The ID of the secondary item associated with the notification. * @param string|bool $component_action The action associated with the notification. * @param bool $is_new The notification's status. */ function crowdmentions_mark_notification($user_id = false, $item_id = false, $secondary_item_id = false, $component_action = false, $is_new = true) { $data = array('is_new' => $is_new); $where = array('user_id' => $user_id, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'component_action' => $component_action, 'component_name' => crowdmentions_get_component_name()); BP_Notifications_Notification::update($data, $where); }