bp_activity_spam_all_user_data

Mark all of the user's activity as spam.

Description

bp_activity_spam_all_user_data( (int) $user_id = 0 ); 

Parameters (1)

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

Usage

  1. if ( !function_exists( 'bp_activity_spam_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 spammed. 
  5. $user_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_activity_spam_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_spam_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. ) ); 
  14.  
  15. $bp =buddypress); 
  16.  
  17. // Mark each as spam. 
  18. foreach ( (array) $activities['activities'] as $activity ) { 
  19.  
  20. // Create an activity object. 
  21. $activity_obj = new BP_Activity_Activity; 
  22. foreach ( $activity as $k => $v ) { 
  23. $activity_obj->$k = $v; 
  24.  
  25. // Mark as spam. 
  26. bp_activity_mark_as_spam( $activity_obj ); 
  27.  
  28. /** 
  29. * If Akismet is present, update the activity history meta. 
  30. * This is usually taken care of when BP_Activity_Activity::save() happens, but 
  31. * as we're going to be updating all the activity statuses directly, for efficiency,  
  32. * we need to update manually. 
  33. */ 
  34. if ( ! empty( $bp->activity->akismet ) ) { 
  35. $bp->activity->akismet->update_activity_spam_meta( $activity_obj ); 
  36.  
  37. // Tidy up. 
  38. unset( $activity_obj ); 
  39.  
  40. // Mark all of this user's activities as spam. 
  41. $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 1 WHERE user_id = %d", $user_id ) ); 
  42.  
  43. /** 
  44. * Fires after all activity data from a user has been marked as spam. 
  45. * @since 1.6.0 
  46. * @param int $user_id ID of the user whose activity is being marked as spam. 
  47. * @param array $activities Array of activity items being marked as spam. 
  48. */ 
  49. do_action( 'bp_activity_spam_all_user_data', $user_id, $activities['activities'] );