bp_registration_options_form_actions

Process approved or denied users.

Description

bp_registration_options_form_actions(); 

Sends out the notifications and handles user deletion when applicable


Usage

  1. if ( !function_exists( 'bp_registration_options_form_actions' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bp-registration-options/includes/admin.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_registration_options_form_actions(); 
  7.  

Defined (1)

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

/includes/admin.php  
  1. function bp_registration_options_form_actions() { 
  2.  
  3. // Settings save. 
  4. if ( isset( $_POST['save_general'] ) ) { 
  5.  
  6. check_admin_referer( 'bp_reg_options_check' ); 
  7.  
  8. array( 
  9. 'set_moderate' => empty( $_POST['bp_moderate'] ) ? '' : $_POST['bp_moderate'],  
  10. 'set_private' => empty( $_POST['privacy_network'] ) ? '' : $_POST['privacy_network'],  
  11. 'enable_notifications' => empty( $_POST['enable_notifications'] ) ? '' : $_POST['enable_notifications'],  
  12. 'activate_message' => empty( $_POST['activate_message'] ) ? '' : $_POST['activate_message'],  
  13. 'approved_message' => empty( $_POST['approved_message'] ) ? '' : $_POST['approved_message'],  
  14. 'denied_message' => empty( $_POST['denied_message'] ) ? '' : $_POST['denied_message'],  
  15. 'admin_pending_message' => empty( $_POST['admin_pending_message'] ) ? '' : $_POST['admin_pending_message'],  
  16. 'user_pending_message' => empty( $_POST['user_pending_message'] ) ? '' : $_POST['user_pending_message'],  
  17. ); 
  18.  
  19. if ( isset( $_POST['reset_messages'] ) ) { 
  20.  
  21. check_admin_referer( 'bp_reg_options_check' ); 
  22.  
  23.  
  24. // Request submissions. 
  25. if ( isset( $_POST['moderate'] ) ) { 
  26.  
  27. check_admin_referer( 'bp_reg_options_check' ); 
  28.  
  29. $action = sanitize_text_field( $_POST['moderate'] ); 
  30.  
  31. $checked_members = array(); 
  32. $send = false; 
  33. $subject = ''; 
  34. $message = ''; 
  35.  
  36. if ( isset( $_POST['bp_member_check'] ) ) { 
  37. $checked_members = $_POST['bp_member_check']; 
  38.  
  39. if ( ! is_array( $checked_members ) ) { 
  40. $checked_members = array( $checked_members ); 
  41.  
  42. if ( 'deny' === $action ) { 
  43. $send = true; 
  44. $subject = __( 'Membership Denied', 'bp-registration-options' ); 
  45. $message = get_option( 'bprwg_denied_message' ); 
  46. if ( 'approve' === $action ) { 
  47. $send = true; 
  48. $subject = __( 'Membership Approved', 'bp-registration-options' ); 
  49. $message = get_option( 'bprwg_approved_message' ); 
  50.  
  51. foreach ( $checked_members as $user_id ) { 
  52.  
  53. // Grab our userdata object while we still have a user. 
  54. $user = get_userdata( $user_id ); 
  55. if ( 'deny' == $action || 'ban' == $action ) { 
  56.  
  57. /** 
  58. // Add our user to the IP ban option. 
  59. if ( 'Ban' == $action ) { 
  60.   
  61. $blockedIPs = get_option( 'bprwg_blocked_ips', array() ); 
  62. $blockedemails = get_option( 'bprwg_blocked_emails', array() ); 
  63. $blockedIPs[] = get_user_meta( $user_id, 'bprwg_ip_address', true); 
  64. $blockedemails[] = $user->data->user_email; 
  65. $successIP = update_option( 'bprwg_blocked_ips', $blockedIPs ); 
  66. $successEmail = update_option( 'bprwg_blocked_emails', $blockedemails ); 
  67. */ 
  68.  
  69. /** 
  70. * Fires before the user deletion when user denied. 
  71. * @since 4.2.0 
  72. * @param int $user_id User ID being deleted. 
  73. */ 
  74. do_action( 'bpro_hook_denied_user_before_delete', $user_id ); 
  75.  
  76. if ( is_multisite() ) { 
  77. wpmu_delete_user( $user_id ); 
  78. } else { 
  79. wp_delete_user( $user_id ); 
  80.  
  81. /** 
  82. * Fires after the user deletion when user denied. 
  83. * @since 4.2.0 
  84. * @param int $user_id User ID that was deleted. 
  85. */ 
  86. do_action( 'bpro_hook_denied_user_after_delete', $user_id ); 
  87.  
  88.  
  89. } elseif ( 'approve' === $action ) { 
  90. // Mark as not spam for BuddyPress Registration Options. 
  91. bp_registration_set_moderation_status( $user_id, 'false' ); 
  92. // Mark as not spam for BuddyPress Core. 
  93. bp_core_process_spammer_status( $user_id, 'ham' ); 
  94.  
  95. /** 
  96. * Fires after a user has been marked as approved. 
  97. * @since 4.2.0 
  98. * @param int $user_id ID of the approved user. 
  99. */ 
  100. do_action( 'bpro_hook_approved_user', $user_id ); 
  101.  
  102.  
  103. // Only send out message if one exists. 
  104. if ( $send ) { 
  105.  
  106. $mailme = array( 
  107. 'user_email' => $user->data->user_email,  
  108. 'user_subject' => $subject,  
  109. 'user_message' => str_replace( '[username]', $user->data->user_login, $message ),  
  110. ); 
  111.  
  112. /** 
  113. * Filters the email arguments before mailing. 
  114. * @since 4.2.0 
  115. * @param array $emailme Array of email arguments for wp_mail. 
  116. * @param object $user User object for user being moderated. 
  117. */ 
  118. $mailme_filtered = apply_filters( 'bpro_hook_before_email', $mailme, $user ); 
  119.  
  120.  
  121. wp_mail( $mailme_filtered['user_email'], $mailme_filtered['user_subject'], $mailme_filtered['user_message'] ); 
  122.