bbp_buddypress_mark_notifications( $action = '' )
Mark notifications as read when reading a topic
Description
Return
(If) not trying to mark a notification as read
Source
File: bp-forums/notifications.php
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?', 'buddyboss' ) );
// 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.', 'buddyboss' ) );
}
// 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
wp_safe_redirect( $redirect );
// For good measure
exit();
}
Changelog
| Version | Description |
|---|---|
| bbPress (r5155) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.