bps_bp_spam_stop

Checks for bp message spam.

Description

bps_bp_spam_stop(); 

Usage

  1. if ( !function_exists( 'bps_bp_spam_stop' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-messages-spam-blocker/plugin.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bps_bp_spam_stop(); 
  7.  

Defined (1)

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

/plugin.php  
  1. function bps_bp_spam_stop() { 
  2. $current_user = wp_get_current_user(); 
  3. if (!user_can($current_user, 'edit_users')) { 
  4. $abort = false; 
  5. $timeDiff = time() - strtotime($current_user->user_registered); 
  6.  
  7. if ($timeDiff < (60 * 60 * $hours)) { 
  8. bp_core_add_message(sprintf(__('We want to protect other users from spam. New members are only allowed to send messages to other users when their registration is not older than %d hours. Please wait until this time is over and then feel free to write messages to other members!', 'buddypress-messages-spamblocker'), $hours), error); 
  9. $abort = true; 
  10. } else { 
  11. // exclude friends from spam mechanism 
  12. if (function_exists(friends_get_friend_user_ids)) { 
  13. $friendsArray = friends_get_friend_user_ids($current_user->ID); 
  14. } else { 
  15. $friendsArray = array(); 
  16.  
  17. // last 5 Minutes max 6 messages 
  18. if (!bps_bp_spam_stop_helper_check(5, apply_filters('buddypress_messages_spamblocker_5m', 6), $friendsArray)) { 
  19. $abort = true; 
  20. // last 10 Minutes max 10 messages 
  21. else if (!bps_bp_spam_stop_helper_check(10, apply_filters('buddypress_messages_spamblocker_10m', 10), $friendsArray)) { 
  22. $abort = true; 
  23. // last 30 Minutes max 20 messages 
  24. else if (!bps_bp_spam_stop_helper_check(30, apply_filters('buddypress_messages_spamblocker_30m', 20), $friendsArray)) { 
  25. $abort = true; 
  26. // last 60 Minutes max 30 messages 
  27. else if (!bps_bp_spam_stop_helper_check(60, apply_filters('buddypress_messages_spamblocker_60m', 30), $friendsArray)) { 
  28. $abort = true; 
  29. // last 12h Minutes max 35 messages 
  30. else if (!bps_bp_spam_stop_helper_check((60 * 12), apply_filters('buddypress_messages_spamblocker_12h', 35), $friendsArray)) { 
  31. $abort = true; 
  32. // last 24h Minutes max 40 messages 
  33. else if (!bps_bp_spam_stop_helper_check((60 * 24), apply_filters('buddypress_messages_spamblocker_24d', 40), $friendsArray)) { 
  34. $abort = true; 
  35. // last 48h Minutes max 50 messages 
  36. else if (!bps_bp_spam_stop_helper_check((60 * 48), apply_filters('buddypress_messages_spamblocker_48d', 50), $friendsArray)) { 
  37. $abort = true; 
  38.  
  39. if ($abort) { 
  40. bp_core_add_message(__('We want to avoid SPAM. You are only allowed to start a limited number of new conversations in a given period. You can add your recipients as friends. There are no restrictions for new conversations you start with your friends!', 'buddypress-messages-spamblocker'), error); 
  41. // Check results 
  42. if ($abort) { 
  43. global $bp; 
  44. $url = bp_loggedin_user_domain() . bp_get_messages_slug(); 
  45. $url = apply_filters('buddypress_messages_spamblocker_blockedURL', $url); 
  46. wp_redirect($url); 
  47. exit;