bp_activity_delete

Delete activity item(s).

Description

bp_activity_delete( (string) $args = '' ); 

If you're looking to hook into one action that provides the ID(s) of the activity/activities deleted, then use:

add_action( bp_activity_deleted_activities,, my_function );

The action passes one parameter that is a single activity ID or an array of activity IDs depending on the number deleted.

If you are deleting an activity comment please use bp_activity_delete_comment();

Parameters (1)

0. $args — Optional. (string) => ''
To delete specific activity items, use $args = array( id => $ids ); Otherwise, to use filters for item deletion, the argument format is the same as BP_Activity_Activity::get(). See that method for a description.

Usage

  1. if ( !function_exists( 'bp_activity_delete' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-functions.php'; 
  3. $args = ''; 
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_activity_delete($args); 
  7.  

Defined (1)

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

/bp-activity/bp-activity-functions.php  
  1. function bp_activity_delete( $args = '' ) { 
  2.  
  3. // Pass one or more the of following variables to delete by those variables. 
  4. $args = bp_parse_args( $args, array( 
  5. 'id' => false,  
  6. 'action' => false,  
  7. 'content' => false,  
  8. 'component' => false,  
  9. 'type' => false,  
  10. 'primary_link' => false,  
  11. 'user_id' => false,  
  12. 'item_id' => false,  
  13. 'secondary_item_id' => false,  
  14. 'date_recorded' => false,  
  15. 'hide_sitewide' => false 
  16. ) ); 
  17.  
  18. /** 
  19. * Fires before an activity item proceeds to be deleted. 
  20. * @since 1.5.0 
  21. * @param array $args Array of arguments to be used with the activity deletion. 
  22. */ 
  23.  
  24. // Adjust the new mention count of any mentioned member. 
  25. bp_activity_adjust_mention_count( $args['id'], 'delete' ); 
  26.  
  27. $activity_ids_deleted = BP_Activity_Activity::delete( $args ); 
  28. if ( empty( $activity_ids_deleted ) ) { 
  29. return false; 
  30.  
  31. // Check if the user's latest update has been deleted. 
  32. $user_id = empty( $args['user_id'] ) 
  33. : $args['user_id']; 
  34.  
  35. $latest_update = bp_get_user_meta( $user_id, 'bp_latest_update', true ); 
  36. if ( !empty( $latest_update ) ) { 
  37. if ( in_array( (int) $latest_update['id'], (array) $activity_ids_deleted ) ) { 
  38. bp_delete_user_meta( $user_id, 'bp_latest_update' ); 
  39.  
  40. /** 
  41. * Fires after the activity item has been deleted. 
  42. * @since 1.0.0 
  43. * @param array $args Array of arguments used with the activity deletion. 
  44. */ 
  45.  
  46. /** 
  47. * Fires after the activity item has been deleted. 
  48. * @since 1.2.0 
  49. * @param array $activity_ids_deleted Array of affected activity item IDs. 
  50. */ 
  51. do_action( 'bp_activity_deleted_activities', $activity_ids_deleted ); 
  52.  
  53. wp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); 
  54.  
  55. return true;