bp_activity_mark_as_spam

Mark an activity item as spam.

Description

bp_activity_mark_as_spam( (BP_Activity_Activity) &$activity, (string) $source = 'by_a_person' ); 

Parameters (2)

0. $activity (BP_Activity_Activity) => &$activity
The activity item to be spammed.
1. $source — Optional. (string) => 'by_a_person'
Default is by_a_person (ie, a person has manually marked the activity as spam). BP core also accepts by_akismet..

Usage

  1. if ( !function_exists( 'bp_activity_mark_as_spam' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-functions.php'; 
  3.  
  4. // The activity item to be spammed. 
  5. $activity = &$activity; 
  6. $source = 'by_a_person'; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = bp_activity_mark_as_spam($activity, $source); 
  10.  

Defined (1)

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

/bp-activity/bp-activity-functions.php  
  1. function bp_activity_mark_as_spam( &$activity, $source = 'by_a_person' ) { 
  2. $bp =buddypress); 
  3.  
  4. $activity->is_spam = 1; 
  5.  
  6. // Clear the activity stream first page cache. 
  7. wp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); 
  8.  
  9. // Clear the activity comment cache for this activity item. 
  10. wp_cache_delete( $activity->id, 'bp_activity_comments' ); 
  11.  
  12. // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity. 
  13. if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) { 
  14. remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4 ); 
  15.  
  16. // Build data package for Akismet. 
  17. $activity_data = BP_Akismet::build_akismet_data_package( $activity ); 
  18.  
  19. // Tell Akismet this is spam. 
  20. $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'spam' ); 
  21.  
  22. // Update meta. 
  23. add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_spam_meta' ), 1, 1 ); 
  24.  
  25. /** 
  26. * Fires at the end of the process to mark an activity item as spam. 
  27. * @since 1.6.0 
  28. * @param BP_Activity_Activity $activity Activity item being marked as spam. 
  29. * @param string $source Source of determination of spam status. For example 
  30. * "by_a_person" or "by_akismet". 
  31. */ 
  32. do_action( 'bp_activity_mark_as_spam', $activity, $source );