/** * Mark new message notification when member reads a message thread directly. * * @since BuddyPress (1.9.0) */ function bp_messages_screen_conversation_mark_notifications() { if (bp_is_active('notifications')) { global $thread_template; // get unread PM notifications for the user $new_pm_notifications = BP_Notifications_Notification::get(array('user_id' => bp_loggedin_user_id(), 'component_name' => buddypress()->messages->id, 'component_action' => 'new_message', 'is_new' => 1)); $unread_message_ids = wp_list_pluck($new_pm_notifications, 'item_id'); // no unread PMs, so stop! if (empty($unread_message_ids)) { return; } // get the unread message ids for this thread only $message_ids = array_intersect($unread_message_ids, wp_list_pluck($thread_template->thread->messages, 'id')); // mark each notification for each PM message as read foreach ($message_ids as $message_id) { bp_notifications_mark_notifications_by_item_id(bp_loggedin_user_id(), (int) $message_id, buddypress()->messages->id, 'new_message'); } } }
/** * Mark notifications read when a member accepts a group invitation. * * @since 1.9.0 * * @param int $user_id ID of the user. * @param int $group_id ID of the group. */ function bp_groups_accept_invite_mark_notifications($user_id, $group_id) { if (bp_is_active('notifications')) { bp_notifications_mark_notifications_by_item_id($user_id, $group_id, buddypress()->groups->id, 'group_invite'); } }
/** * Mark at-mention notification as read when user visits the activity with the mention. * * @since 2.0.0 * * @param BP_Activity_Activity $activity Activity object. */ function bp_activity_remove_screen_notifications_single_activity_permalink($activity) { if (!bp_is_active('notifications')) { return; } if (!is_user_logged_in()) { return; } // Mark as read any notifications for the current user related to this activity item. bp_notifications_mark_notifications_by_item_id(bp_loggedin_user_id(), $activity->id, buddypress()->activity->id, 'new_at_mention'); }
/** * Mark notification(s) as read * * @package WP Idea Stream * @subpackage buddypress/notifications * * @since 2.0.0 * * @uses wp_idea_stream_is_single_idea() to check if viewing the single template of an idea * @uses bp_notifications_mark_notifications_by_item_id() to mark notifications as read * @uses bp_loggedin_user_id() to get the logged in user ID * @uses wp_idea_stream_get_single_idea_id() to get the ID of the idea being viewed * @uses buddypress() to get BuddyPress instance * @uses wp_idea_stream_get_post_type() to get the ideas post type identifier * @uses bp_is_user() to check a user's profile is displayed * @uses bp_is_current_component( 'ideastream' ) to check it's an IdeaStream part of the profile * @uses bp_notifications_mark_notifications_by_type() to mark notifications as read */ function wp_idea_stream_buddypress_comments_mark_notifications_read() { if (!empty($_GET['notif'])) { if (wp_idea_stream_is_single_idea()) { bp_notifications_mark_notifications_by_item_id(bp_loggedin_user_id(), wp_idea_stream_get_single_idea_id(), buddypress()->ideastream->id, 'new_' . wp_idea_stream_get_post_type() . '_comment'); bp_notifications_mark_notifications_by_item_id(bp_loggedin_user_id(), wp_idea_stream_get_single_idea_id(), buddypress()->ideastream->id, 'new_' . wp_idea_stream_get_post_type() . '_rate'); } if (bp_is_user() && bp_is_current_component('ideastream')) { bp_notifications_mark_notifications_by_type(bp_loggedin_user_id(), buddypress()->ideastream->id, 'new_' . wp_idea_stream_get_post_type() . '_comment'); bp_notifications_mark_notifications_by_type(bp_loggedin_user_id(), buddypress()->ideastream->id, 'new_' . wp_idea_stream_get_post_type() . '_rate'); } } }
/** * Mark notifications as read when reading a topic * * @since 2.5.0 bbPress (r5155) * * @return If not trying to mark a notification as read */ function bbp_buddypress_mark_notifications($action = '') { // Bail if no topic ID is passed if (empty($_GET['topic_id'])) { return; } // Bail if action is not for this function if ('bbp_mark_read' !== $action) { return; } // Get required data $user_id = bp_loggedin_user_id(); $topic_id = intval($_GET['topic_id']); // Check nonce if (!bbp_verify_nonce_request('bbp_mark_topic_' . $topic_id)) { bbp_add_error('bbp_notification_topic_id', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress')); // Check current user's ability to edit the user } elseif (!current_user_can('edit_user', $user_id)) { bbp_add_error('bbp_notification_permissions', __('<strong>ERROR</strong>: You do not have permission to mark notifications for that user.', 'bbpress')); } // Bail if we have errors if (!bbp_has_errors()) { // Attempt to clear notifications for the current user from this topic $success = bp_notifications_mark_notifications_by_item_id($user_id, $topic_id, bbp_get_component_name(), 'bbp_new_reply'); // Do additional subscriptions actions do_action('bbp_notifications_handler', $success, $user_id, $topic_id, $action); } // Redirect to the topic $redirect = bbp_get_reply_url($topic_id); // Redirect bbp_redirect($redirect); }
/** * Notify a member when another member accepts their virtual friendship request. * * @since 1.9.0 * * @param int $friendship_id The unique ID of the friendship. * @param int $initiator_user_id The friendship initiator user ID. * @param int $friend_user_id The friendship request receiver user ID. */ function bp_friends_add_friendship_accepted_notification($friendship_id, $initiator_user_id, $friend_user_id) { // Bail if notifications is not active. if (!bp_is_active('notifications')) { return; } // Remove the friend request notice. bp_notifications_mark_notifications_by_item_id($friend_user_id, $initiator_user_id, buddypress()->friends->id, 'friendship_request'); // Add a friend accepted notice for the initiating user. bp_notifications_add_notification(array('user_id' => $initiator_user_id, 'item_id' => $friend_user_id, 'secondary_item_id' => $friendship_id, 'component_name' => buddypress()->friends->id, 'component_action' => 'friendship_accepted', 'date_notified' => bp_core_current_time(), 'is_new' => 1)); }
/** * Mark notifications read when a member's group membership request is granted. * * @since 2.8.0 * * @param int $user_id ID of the user. * @param int $group_id ID of the group. */ function bp_groups_accept_request_mark_notifications($user_id, $group_id) { if (bp_is_active('notifications')) { // First null parameter marks read for all admins. bp_notifications_mark_notifications_by_item_id(null, $group_id, buddypress()->groups->id, 'new_membership_request', $user_id); } }
/** * Marks a compliment as read when 'bpc_read' is set. * * @since 0.0.2 * @package BuddyPress_Compliments * * @global object $bp BuddyPress instance. */ function bp_compliments_notifications_mark_compliments_as_read() { if (!bp_is_user() || !is_user_logged_in()) { return; } if (!isset($_GET['bpc_read']) || !isset($_GET['bpc_sender_id'])) { return; } $compliment_id = false; if (isset($_GET['c_id'])) { $compliment_id = (int) strip_tags(esc_sql($_GET['c_id'])); } $sender_id = (int) strip_tags(esc_sql($_GET['bpc_sender_id'])); if (!is_int($sender_id)) { return; } // mark notification as read if (bp_is_active('notifications')) { bp_notifications_mark_notifications_by_item_id(bp_loggedin_user_id(), $sender_id, buddypress()->compliments->id, 'new_compliment'); // check if we're not on BP 1.9 // if so, delete notification since marked functionality doesn't exist } elseif (!class_exists('BP_Core_Login_Widget')) { global $bp; bp_core_delete_notifications_by_item_id(bp_loggedin_user_id(), $sender_id, buddypress()->compliments->id, 'new_compliment'); } // Redirect if ($compliment_id) { bp_core_redirect(bp_displayed_user_domain() . BP_COMPLIMENTS_SLUG . '/?c_id=' . $compliment_id); } else { bp_core_redirect(bp_displayed_user_domain() . BP_COMPLIMENTS_SLUG . '/'); } }
/** * Mark notification as read when a logged-in user visits their follower's profile. * * This is a new feature in BuddyPress 1.9. * * @since 1.2.1 */ function bp_follow_notifications_mark_follower_profile_as_read() { if (!isset($_GET['bpf_read'])) { return; } // mark notification as read if (bp_is_active('notifications')) { bp_notifications_mark_notifications_by_item_id(bp_loggedin_user_id(), bp_displayed_user_id(), buddypress()->follow->id, 'new_follow'); // check if we're not on BP 1.9 // if so, delete notification since marked functionality doesn't exist } elseif (!class_exists('BP_Core_Login_Widget')) { global $bp; bp_core_delete_notifications_by_item_id(bp_loggedin_user_id(), bp_displayed_user_id(), $bp->follow->id, 'new_follow'); } }
/** * Mark screen notifications * * @package Rendez Vous * @subpackage Notifications * * @since Rendez Vous (1.0.0) */ function rendez_vous_remove_current_attend_notifications() { if (!isset($_GET['rdv']) || !isset($_GET['n'])) { return; } $bp = buddypress(); /** * Removing all for the current user & current rendez-vous */ bp_notifications_mark_notifications_by_item_id(bp_loggedin_user_id(), $_GET['rdv'], buddypress()->rendez_vous->id, false); }
/** * @group bp_notifications_get_unread_notification_count * @group cache */ public function test_bp_notifications_get_unread_notification_count_cache() { $u1 = $this->factory->user->create(); $u2 = $this->factory->user->create(); $this->factory->notification->create(array('component_name' => 'messages', 'component_action' => 'new_message', 'item_id' => 99, 'user_id' => $u2, 'secondary_item_id' => $u1, 'is_new' => true)); // prime cache bp_notifications_get_unread_notification_count($u2); // mark the created notification as read bp_notifications_mark_notifications_by_item_id($u2, 99, 'messages', 'new_message', $u1); // now grab the updated notification count $n = bp_notifications_get_unread_notification_count($u2); // assert $this->assertEquals(0, $n); }
function likebtn_bbp_buddypress_mark_notifications() { global $wp; $action = ''; if (isset($_GET['action'])) { $action = $_GET['action']; } // Bail if action is not for this function if ('likebtn_bp_mark_read' !== $action) { return; } if (empty($_GET['likebtn_bp_params']) || empty($_GET['_wpnonce'])) { return; } $params = json_decode(base64_decode($_GET['likebtn_bp_params']), true); if (empty($params['item_id']) || empty($params['secondary_item_id']) || empty($params['component_action'])) { return; } // Get required data $user_id = bp_loggedin_user_id(); $errors = false; $none_name = 'likebtn_bp_mark_read_' . md5($params['component_action'] . $params['item_id'] . $params['secondary_item_id']); // Check nonce if (!wp_verify_nonce($_GET['_wpnonce'], $none_name)) { $errors = true; } elseif (!current_user_can('edit_user', $user_id)) { // Check current user's ability to edit the user $errors = true; } // Bail if we have errors if (!$errors) { // Attempt to clear notifications for the current user from this topic $success = bp_notifications_mark_notifications_by_item_id($user_id, $params['item_id'], LIKEBTN_BP_COMPONENT_NAME, $params['component_action'], $params['secondary_item_id']); } // Redirect url $current_url = add_query_arg($wp->query_string, '', home_url($wp->request)); $redirect_url = add_query_arg(array('likebtn_bp_params' => false, 'action' => false, '_wpnonce' => false), $current_url); // Redirect wp_safe_redirect($redirect_url); // For good measure exit; }