bp_activity_action_spam_activity

Mark specific activity item as spam and redirect to previous page.

Description

bp_activity_action_spam_activity( (int) $activity_id = 0 ); 

Parameters (1)

0. $activity_id — Optional. (int)
Activity id to be deleted. Defaults to 0.

Usage

  1. if ( !function_exists( 'bp_activity_action_spam_activity' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-actions.php'; 
  3.  
  4. // Activity id to be deleted. Defaults to 0. 
  5. $activity_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_activity_action_spam_activity($activity_id); 
  9.  

Defined (1)

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

/bp-activity/bp-activity-actions.php  
  1. function bp_activity_action_spam_activity( $activity_id = 0 ) { 
  2. $bp =buddypress); 
  3.  
  4. // Not viewing activity, or action is not spam, or Akismet isn't present. 
  5. if ( !bp_is_activity_component() || !bp_is_current_action( 'spam' ) || empty( $bp->activity->akismet ) ) 
  6. return false; 
  7.  
  8. if ( empty( $activity_id ) && bp_action_variable( 0 ) ) 
  9. $activity_id = (int) bp_action_variable( 0 ); 
  10.  
  11. // Not viewing a specific activity item. 
  12. if ( empty( $activity_id ) ) 
  13. return false; 
  14.  
  15. // Is the current user allowed to spam items? 
  16. if ( !bp_activity_user_can_mark_spam() ) 
  17. return false; 
  18.  
  19. // Load up the activity item. 
  20. $activity = new BP_Activity_Activity( $activity_id ); 
  21. if ( empty( $activity->id ) ) 
  22. return false; 
  23.  
  24. // Check nonce. 
  25. check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id ); 
  26.  
  27. /** 
  28. * Fires before the marking activity as spam so plugins can modify things if they want to. 
  29. * @since 1.6.0 
  30. * @param int $activity_id Activity ID to be marked as spam. 
  31. * @param object $activity Activity object for the ID to be marked as spam. 
  32. */ 
  33. do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity ); 
  34.  
  35. // Mark as spam. 
  36. bp_activity_mark_as_spam( $activity ); 
  37. $activity->save(); 
  38.  
  39. // Tell the user the spamming has been successful. 
  40. bp_core_add_message( __( 'The activity item has been marked as spam and is no longer visible.', buddypress ) ); 
  41.  
  42. /** 
  43. * Fires after the marking activity as spam so plugins can act afterwards based on the activity. 
  44. * @since 1.6.0 
  45. * @param int $activity_id Activity ID that was marked as spam. 
  46. * @param int $user_id User ID associated with activity. 
  47. */ 
  48. do_action( 'bp_activity_action_spam_activity', $activity_id, $activity->user_id ); 
  49.  
  50. // Check for the redirect query arg, otherwise let WP handle things. 
  51. if ( !empty( $_GET['redirect_to'] ) ) 
  52. bp_core_redirect( esc_url( $_GET['redirect_to'] ) ); 
  53. else