Advertisement
imath

#BP Admin's taking control of user activation process

May 12th, 2012
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.73 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: BP Register Control
  4. Plugin URI: http://imath.owni.fr/
  5. Description: redirect new user's notification to admin so he can control if the account will be activated or not.
  6. Version: 1.0
  7. Author: imath
  8. Author URI: http://imath.owni.fr
  9. License: GPLv2
  10. Network: true
  11. */
  12.  
  13.  
  14. function bp_rc_ask_wp_signups( $activate_url, $key=false ) {
  15.     global $wpdb;
  16.     if( empty( $key ) ) {
  17.         $parse_key = explode( '?key=', $activate_url);
  18.         $key = $parse_key[1];
  19.     }
  20.    
  21.     $user = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key) );
  22.    
  23.     return $user;
  24. }
  25.  
  26. add_filter( 'bp_core_signup_send_validation_email_to', 'bp_rc_redirect_to_admin', 1, 2 );
  27. add_filter( 'bp_core_signup_send_validation_email_subject', 'bp_rc_subject_redirect_to_admin', 1, 2 );
  28. add_filter( 'bp_core_signup_send_validation_email_message', 'bp_rc_message_redirect_to_admin', 1, 3 );
  29.  
  30. add_filter( 'bp_core_activation_signup_user_notification_to',   'bp_rc_redirect_to_admin', 1, 5 );
  31. add_filter( 'bp_core_activation_signup_user_notification_subject', 'bp_rc_subject_redirect_to_admin', 1, 5);
  32. add_filter( 'bp_core_activation_signup_user_notification_message', 'bp_rc_message_redirect_to_admin', 1, 5 );
  33.  
  34. function bp_rc_redirect_to_admin( $user_email, $user_id ) {
  35.     return get_option( 'admin_email' );
  36. }
  37.  
  38. function bp_rc_subject_redirect_to_admin( $subject, $user_id  ) {
  39.     $blogname = ( '' == get_option( 'blogname' ) ) ? __( 'BuddyPress', 'buddypress' ) : esc_html( get_option( 'blogname' ) );
  40.    
  41.     return sprintf(__('[%s] New User Registration'), $blogname);
  42. }
  43.  
  44. function bp_rc_message_redirect_to_admin( $message, $user_id, $activate_url, $key = false ) {
  45.     if ( is_multisite() )
  46.         $user = bp_rc_ask_wp_signups( $activate_url, $key );
  47.        
  48.     else
  49.         $user = get_userdata( $user_id );
  50.        
  51.     if( !empty( $key ) )
  52.         $activate_url = bp_get_activation_page() . "?key=$key";
  53.    
  54.     $message =  sprintf( __("Hi %s (%s) just registered.\n\nYou can activate his account by clicking here : %s"), $user->user_login, $user->user_email, $activate_url );
  55.    
  56.     return $message;
  57. }
  58.  
  59.  
  60.  
  61. add_action( 'bp_core_activated_user', 'bp_rc_send_user_account_is_activated', 1, 3 );
  62.  
  63. function bp_rc_send_user_account_is_activated( $user_id, $key, $user ) {
  64.     // if multisite, there's allready a notification sent
  65.     if(is_multisite())
  66.         return false;
  67.    
  68.     $user = get_userdata( $user_id );
  69.    
  70.     $to = $user->user_email;
  71.     $from_name = ( '' == get_option( 'blogname' ) ) ? __( 'BuddyPress', 'buddypress' ) : esc_html( get_option( 'blogname' ) );
  72.    
  73.     if( !empty( $user->display_name ) )
  74.         $user_nick = $user->display_name;
  75.     else
  76.         $user_nick = ucfirst( $user->user_login );
  77.    
  78.     // edit the message below to suit your needs !
  79.     $message = sprintf( __("Hi %s,\n\nYour are now a member of our website. Thanks for joining us !\n\n"), $user_nick );
  80.     $message .= sprintf( __("Where to go now ?\n\nYou can log in at %s with your login (%s) and the password you registered with"), esc_html( get_option( 'siteurl' ) ), $user->user_login );
  81.     $message .= sprintf( __("\n\nHoping to hear from you real soon :)\n\n"), esc_html( get_option( 'blogname' ) ) );
  82.    
  83.     // edit the subject below to suit your needs !
  84.     $subject = '[' . $from_name . '] ' . __( 'Your account is now active!', 'buddypress' );
  85.    
  86.    
  87.     wp_mail( $to, $subject, $message );
  88.  
  89. }
  90.  
  91. add_action('bp_after_registration_confirmed', 'bp_rc_override_bp_screen_message');
  92.  
  93. function bp_rc_override_bp_screen_message() {
  94.    
  95.     // edit the message below to suit your needs
  96.     $message = "Thanks for registrating, your account will soon be activated by the Admin of this website..";
  97.     ?>
  98.     <script type="text/javascript">
  99.    
  100.     jQuery(document).ready(function($){
  101.         $('#signup_form p').html('<?php echo $message;?>');
  102.     });
  103.    
  104.     </script>
  105.     <?php
  106. }
  107. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement