bbp_buddypress_mark_notifications

Mark notifications as read when reading a topic.

Description

bbp_buddypress_mark_notifications( (string) $action = '' ); 

Parameters (1)

0. $action — Optional. (string) => ''
The action.

Usage

  1. if ( !function_exists( 'bbp_buddypress_mark_notifications' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/extend/buddypress/notifications.php'; 
  3.  
  4. // The action. 
  5. $action = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_buddypress_mark_notifications($action); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/extend/buddypress/notifications.php  
  1. function bbp_buddypress_mark_notifications( $action = '' ) { 
  2.  
  3. // Bail if no topic ID is passed 
  4. if ( empty( $_GET['topic_id'] ) ) { 
  5. return; 
  6.  
  7. // Bail if action is not for this function 
  8. if ( 'bbp_mark_read' !== $action ) { 
  9. return; 
  10.  
  11. // Get required data 
  12. $user_id = bp_loggedin_user_id(); 
  13. $topic_id = intval( $_GET['topic_id'] ); 
  14.  
  15. // Check nonce 
  16. if ( ! bbp_verify_nonce_request( 'bbp_mark_topic_' . $topic_id ) ) { 
  17. bbp_add_error( 'bbp_notification_topic_id', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', bbpress ) ); 
  18.  
  19. // Check current user's ability to edit the user 
  20. } elseif ( !current_user_can( 'edit_user', $user_id ) ) { 
  21. bbp_add_error( 'bbp_notification_permissions', __( '<strong>ERROR</strong>: You do not have permission to mark notifications for that user.', bbpress ) ); 
  22.  
  23. // Bail if we have errors 
  24. if ( ! bbp_has_errors() ) { 
  25.  
  26. // Attempt to clear notifications for the current user from this topic 
  27. $success = bp_notifications_mark_notifications_by_item_id( $user_id, $topic_id, bbp_get_component_name(), 'bbp_new_reply' ); 
  28.  
  29. // Do additional subscriptions actions 
  30. do_action( 'bbp_notifications_handler', $success, $user_id, $topic_id, $action ); 
  31.  
  32. // Redirect to the topic 
  33. $redirect = bbp_get_reply_url( $topic_id ); 
  34.  
  35. // Redirect 
  36. wp_safe_redirect( $redirect ); 
  37.  
  38. // For good measure 
  39. exit();