bp_core_process_spammer_status

Process a spammed or unspammed user.

Description

bp_core_process_spammer_status( (int) $user_id, (string) $status, (bool) $do_wp_cleanup = true ); 

This function is called from three places:

- in bp_settings_action_capabilities() (from the front-end) - by bp_core_mark_user_spam_admin() (from wp-admin) - bp_core_mark_user_ham_admin() (from wp-admin)

Parameters (3)

0. $user_id (int)
The ID of the user being spammed/hammed.
1. $status (string)
'spam' if being marked as spam, ham otherwise.
2. $do_wp_cleanup — Optional. (bool) => true
True to force the cleanup of WordPress content and status, otherwise false. Generally, this should only be false if WordPress is expected to have performed this cleanup independently, as when hooked to make_spam_user..

Usage

  1. if ( !function_exists( 'bp_core_process_spammer_status' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-functions.php'; 
  3.  
  4. // The ID of the user being spammed/hammed. 
  5. $user_id = -1; 
  6.  
  7. // 'spam' if being marked as spam, 'ham' otherwise. 
  8. $status = ''; 
  9. $do_wp_cleanup = true; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = bp_core_process_spammer_status($user_id, $status, $do_wp_cleanup); 
  13.  

Defined (1)

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

/bp-members/bp-members-functions.php  
  1. function bp_core_process_spammer_status( $user_id, $status, $do_wp_cleanup = true ) { 
  2. global $wpdb; 
  3.  
  4. // Bail if no user ID. 
  5. if ( empty( $user_id ) ) { 
  6. return; 
  7.  
  8. // Bail if user ID is super admin. 
  9. if ( is_super_admin( $user_id ) ) { 
  10. return; 
  11.  
  12. // Get the functions file. 
  13. if ( is_multisite() ) { 
  14. require_once( ABSPATH . 'wp-admin/includes/ms.php' ); 
  15.  
  16. $is_spam = ( 'spam' == $status ); 
  17.  
  18. // Only you can prevent infinite loops. 
  19.  
  20. // Force the cleanup of WordPress content and status for multisite configs. 
  21. if ( $do_wp_cleanup ) { 
  22.  
  23. // Get the blogs for the user. 
  24. $blogs = get_blogs_of_user( $user_id, true ); 
  25.  
  26. foreach ( (array) array_values( $blogs ) as $details ) { 
  27.  
  28. // Do not mark the main or current root blog as spam. 
  29. if ( 1 == $details->userblog_id || bp_get_root_blog_id() == $details->userblog_id ) { 
  30. continue; 
  31.  
  32. // Update the blog status. 
  33. update_blog_status( $details->userblog_id, 'spam', $is_spam ); 
  34.  
  35. // Finally, mark this user as a spammer. 
  36. if ( is_multisite() ) { 
  37. update_user_status( $user_id, 'spam', $is_spam ); 
  38.  
  39. // Update the user status. 
  40. $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $user_id ) ); 
  41.  
  42. // Clean user cache. 
  43. clean_user_cache( $user_id ); 
  44.  
  45. if ( ! is_multisite() ) { 
  46. // Call multisite actions in single site mode for good measure. 
  47. if ( true === $is_spam ) { 
  48.  
  49. /** 
  50. * Fires at end of processing spammer in Dashboard if not multisite and user is spam. 
  51. * @since 1.5.0 
  52. * @param int $value user ID. 
  53. */ 
  54. do_action( 'make_spam_user', $user_id ); 
  55. } else { 
  56.  
  57. /** 
  58. * Fires at end of processing spammer in Dashboard if not multisite and user is not spam. 
  59. * @since 1.5.0 
  60. * @param int $value user ID. 
  61. */ 
  62. do_action( 'make_ham_user', $user_id ); 
  63.  
  64. // Hide this user's activity. 
  65. if ( ( true === $is_spam ) && bp_is_active( 'activity' ) ) { 
  66.  
  67. // We need a special hook for is_spam so that components can delete data at spam time. 
  68. if ( true === $is_spam ) { 
  69.  
  70. /** 
  71. * Fires at the end of the process spammer process if the user is spam. 
  72. * @since 1.5.0 
  73. * @param int $value Displayed user ID. 
  74. */ 
  75. } else { 
  76.  
  77. /** 
  78. * Fires at the end of the process spammer process if the user is not spam. 
  79. * @since 1.5.0 
  80. * @param int $value Displayed user ID. 
  81. */ 
  82. do_action( 'bp_make_ham_user', $user_id ); 
  83.  
  84. /** 
  85. * Fires at the end of the process for hanlding spammer status. 
  86. * @since 1.5.5 
  87. * @param int $user_id ID of the processed user. 
  88. * @param bool $is_spam The determined spam status of processed user. 
  89. */ 
  90. do_action( 'bp_core_process_spammer_status', $user_id, $is_spam ); 
  91.  
  92. // Put things back how we found them. 
  93.  
  94. return true;