/** * Handles bulk management (mark as read/unread, delete) of notifications. * * @since 2.2.0 * * @return bool */ function bp_notifications_action_bulk_manage() { // Bail if not the read or unread screen. if (!bp_is_notifications_component() || !(bp_is_current_action('read') || bp_is_current_action('unread'))) { return false; } // Get the action. $action = !empty($_POST['notification_bulk_action']) ? $_POST['notification_bulk_action'] : ''; $nonce = !empty($_POST['notifications_bulk_nonce']) ? $_POST['notifications_bulk_nonce'] : ''; $notifications = !empty($_POST['notifications']) ? $_POST['notifications'] : ''; // Bail if no action or no IDs. if (!in_array($action, array('delete', 'read', 'unread')) || empty($notifications) || empty($nonce)) { return false; } // Check the nonce. if (!wp_verify_nonce($nonce, 'notifications_bulk_nonce')) { bp_core_add_message(__('There was a problem managing your notifications.', 'buddypress'), 'error'); return false; } $notifications = wp_parse_id_list($notifications); // Delete, mark as read or unread depending on the user 'action'. switch ($action) { case 'delete': foreach ($notifications as $notification) { bp_notifications_delete_notification($notification); } bp_core_add_message(__('Notifications deleted.', 'buddypress')); break; case 'read': foreach ($notifications as $notification) { bp_notifications_mark_notification($notification, false); } bp_core_add_message(__('Notifications marked as read', 'buddypress')); break; case 'unread': foreach ($notifications as $notification) { bp_notifications_mark_notification($notification, true); } bp_core_add_message(__('Notifications marked as unread.', 'buddypress')); break; } // Redirect. bp_core_redirect(bp_displayed_user_domain() . bp_get_notifications_slug() . '/' . bp_current_action() . '/'); }
/** * Set up the title for pages and <title>. * * @since 1.9.0 */ public function setup_title() { // Adjust title. if (bp_is_notifications_component()) { $bp = buddypress(); if (bp_is_my_profile()) { $bp->bp_options_title = __('Notifications', 'buddypress'); } else { $bp->bp_options_avatar = bp_core_fetch_avatar(array('item_id' => bp_displayed_user_id(), 'type' => 'thumb', 'alt' => sprintf(__('Profile picture of %s', 'buddypress'), bp_get_displayed_user_fullname()))); $bp->bp_options_title = bp_get_displayed_user_fullname(); } } parent::setup_title(); }
/** * Handle deleting single notifications. * * @since BuddyPress (1.9.0) * * @return boolean */ function bp_notifications_action_delete() { // Bail if not the read or unread screen if (!bp_is_notifications_component() || !(bp_is_current_action('read') || bp_is_current_action('unread'))) { return false; } // Get the action $action = !empty($_GET['action']) ? $_GET['action'] : ''; $nonce = !empty($_GET['_wpnonce']) ? $_GET['_wpnonce'] : ''; $id = !empty($_GET['notification_id']) ? $_GET['notification_id'] : ''; // Bail if no action or no ID if ('delete' !== $action || empty($id) || empty($nonce)) { return false; } // Check the nonce and delete the notification if (bp_verify_nonce_request('bp_notification_delete_' . $id) && bp_notifications_delete_notification($id)) { bp_core_add_message(__('Notification successfully deleted.', 'buddypress')); } else { bp_core_add_message(__('There was a problem deleting that notification.', 'buddypress'), 'error'); } // Redirect bp_core_redirect(bp_displayed_user_domain() . bp_get_notifications_slug() . '/' . bp_current_action() . '/'); }
/** * Is this a user's notifications page? * * Eg http://example.com/members/joe/notifications/ (or a subpage thereof). * * @since 1.9.0 * * @return bool True if the current page is a user's Notifications page. */ function bp_is_user_notifications() { return (bool) (bp_is_user() && bp_is_notifications_component()); }
/** * Is this a user's notifications page? * * Eg http://example.com/members/joe/notifications/ (or a subpage thereof). * * @since BuddyPress (1.9.0) * * @return bool True if the current page is a user's Notifications page. */ function bp_is_user_notifications() { if (bp_is_user() && bp_is_notifications_component()) { return true; } return false; }