bbp_make_spam_user

Mark a users topics and replies as spam when the user is marked as spam.

Description

bbp_make_spam_user( (int) $user_id = 0 ); 

Parameters (1)

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

Usage

  1. if ( !function_exists( 'bbp_make_spam_user' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/users/capabilities.php'; 
  3.  
  4. // Optional. User ID to spam. Defaults to displayed user. 
  5. $user_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_make_spam_user($user_id); 
  9.  

Defined (1)

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

/includes/users/capabilities.php  
  1. function bbp_make_spam_user( $user_id = 0 ) { 
  2.  
  3. // Use displayed user if it's not yourself 
  4. if ( empty( $user_id ) && bbp_is_single_user() && !bbp_is_user_home() ) 
  5. $user_id = bbp_get_displayed_user_id(); 
  6.  
  7. // Bail if no user ID 
  8. if ( empty( $user_id ) ) 
  9. return false; 
  10.  
  11. // Bail if user ID is keymaster 
  12. if ( bbp_is_user_keymaster( $user_id ) ) 
  13. return false; 
  14.  
  15. // Arm the torpedos 
  16. global $wpdb; 
  17.  
  18. // Get the blog IDs of the user to mark as spam 
  19. $blogs = get_blogs_of_user( $user_id, true ); 
  20.  
  21. // If user has no blogs, they are a guest on this site 
  22. if ( empty( $blogs ) ) 
  23. $blogs[$wpdb->blogid] = array(); 
  24.  
  25. // Make array of post types to mark as spam 
  26. $post_types = array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ); 
  27. $post_types = "'" . implode( "', '", $post_types ) . "'"; 
  28.  
  29. // Loop through blogs and remove their posts 
  30. foreach ( (array) array_keys( $blogs ) as $blog_id ) { 
  31.  
  32. // Switch to the blog ID 
  33. switch_to_blog( $blog_id ); 
  34.  
  35. // Get topics and replies 
  36. $posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_status = '%s' AND post_type IN ( {$post_types} )", $user_id, bbp_get_public_status_id() ) ); 
  37.  
  38. // Loop through posts and spam them 
  39. if ( !empty( $posts ) ) { 
  40. foreach ( $posts as $post_id ) { 
  41.  
  42. // The routines for topics ang replies are different, so use the 
  43. // correct one based on the post type 
  44. switch ( get_post_type( $post_id ) ) { 
  45.  
  46. bbp_spam_topic( $post_id ); 
  47. break; 
  48.  
  49. bbp_spam_reply( $post_id ); 
  50. break; 
  51.  
  52. // Switch back to current blog 
  53. restore_current_blog(); 
  54.  
  55. // Success 
  56. return true;