bp_core_action_set_spammer_status

Catch a "Mark as Spammer/Not Spammer" click from the toolbar.

Description

bp_core_action_set_spammer_status( (int) $user_id = 0 ); 

When a site admin selects Mark as Spammer/Not Spammer from the admin menu this action will fire and mark or unmark the user and their blogs as spam. Must be a site admin for this function to run.

Note: no longer used in the current state. See the Settings component.

Parameters (1)

0. $user_id — Optional. (int)
User ID to mark as spam. Defaults to displayed user.

Usage

  1. if ( !function_exists( 'bp_core_action_set_spammer_status' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-actions.php'; 
  3.  
  4. // Optional. User ID to mark as spam. Defaults to displayed user. 
  5. $user_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_core_action_set_spammer_status($user_id); 
  9.  

Defined (1)

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

/bp-members/bp-members-actions.php  
  1. function bp_core_action_set_spammer_status( $user_id = 0 ) { 
  2.  
  3. // Only super admins can currently spam users (but they can't spam 
  4. // themselves). 
  5. if ( ! is_super_admin() || bp_is_my_profile() ) { 
  6. return; 
  7.  
  8. // Use displayed user if it's not yourself. 
  9. if ( empty( $user_id ) ) 
  10. $user_id = bp_displayed_user_id(); 
  11.  
  12. if ( bp_is_current_component( 'admin' ) && ( in_array( bp_current_action(), array( 'mark-spammer', 'unmark-spammer' ) ) ) ) { 
  13.  
  14. // Check the nonce. 
  15. check_admin_referer( 'mark-unmark-spammer' ); 
  16.  
  17. // To spam or not to spam. 
  18. $status = bp_is_current_action( 'mark-spammer' ) ? 'spam' : 'ham'; 
  19.  
  20. // The heavy lifting. 
  21. bp_core_process_spammer_status( $user_id, $status ); 
  22.  
  23. // Add feedback message. @todo - Error reporting. 
  24. if ( 'spam' == $status ) { 
  25. bp_core_add_message( __( 'User marked as spammer. Spam users are visible only to site admins.', buddypress ) ); 
  26. } else { 
  27. bp_core_add_message( __( 'User removed as spammer.', buddypress ) ); 
  28.  
  29. // Deprecated. Use bp_core_process_spammer_status. 
  30. $is_spam = 'spam' == $status; 
  31.  
  32. // Redirect back to where we came from.