bp_activity_ham_all_user_data

Mark all of the user's activity as ham (not spam).

Description

bp_activity_ham_all_user_data( (int) $user_id = 0 ); 

Parameters (1)

0. $user_id — Optional. (int)
ID of the user whose activity is being hammed.

Usage

  1. if ( !function_exists( 'bp_activity_ham_all_user_data' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-functions.php'; 
  3.  
  4. // ID of the user whose activity is being hammed. 
  5. $user_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_activity_ham_all_user_data($user_id); 
  9.  

Defined (1)

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

/bp-activity/bp-activity-functions.php  
  1. function bp_activity_ham_all_user_data( $user_id = 0 ) { 
  2. global $wpdb; 
  3.  
  4. // Do not delete user data unless a logged in user says so. 
  5. if ( empty( $user_id ) || ! is_user_logged_in() ) { 
  6. return false; 
  7.  
  8. // Get all the user's activities. 
  9. $activities = bp_activity_get( array( 
  10. 'display_comments' => 'stream',  
  11. 'filter' => array( 'user_id' => $user_id ),  
  12. 'show_hidden' => true,  
  13. 'spam' => 'all' 
  14. ) ); 
  15.  
  16. $bp =buddypress); 
  17.  
  18. // Mark each as not spam. 
  19. foreach ( (array) $activities['activities'] as $activity ) { 
  20.  
  21. // Create an activity object. 
  22. $activity_obj = new BP_Activity_Activity; 
  23. foreach ( $activity as $k => $v ) { 
  24. $activity_obj->$k = $v; 
  25.  
  26. // Mark as not spam. 
  27. bp_activity_mark_as_ham( $activity_obj ); 
  28.  
  29. /** 
  30. * If Akismet is present, update the activity history meta. 
  31. * This is usually taken care of when BP_Activity_Activity::save() happens, but 
  32. * as we're going to be updating all the activity statuses directly, for efficiency,  
  33. * we need to update manually. 
  34. */ 
  35. if ( ! empty( $bp->activity->akismet ) ) { 
  36. $bp->activity->akismet->update_activity_ham_meta( $activity_obj ); 
  37.  
  38. // Tidy up. 
  39. unset( $activity_obj ); 
  40.  
  41. // Mark all of this user's activities as not spam. 
  42. $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 0 WHERE user_id = %d", $user_id ) ); 
  43.  
  44. /** 
  45. * Fires after all activity data from a user has been marked as ham. 
  46. * @since 1.6.0 
  47. * @param int $user_id ID of the user whose activity is being marked as ham. 
  48. * @param array $activities Array of activity items being marked as ham. 
  49. */ 
  50. do_action( 'bp_activity_ham_all_user_data', $user_id, $activities['activities'] );