Guest User

Untitled

a guest
Dec 6th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. if ( !function_exists('wp_new_user_notification') ) :
  2. /**
  3. * Notify the blog admin of a new user, normally via email.
  4. *
  5. * @since 2.0
  6. *
  7. * @param int $user_id User ID
  8. * @param string $plaintext_pass Optional. The user's plaintext password
  9. */
  10. function wp_new_user_notification($user_id, $plaintext_pass = '') {
  11. $user = new WP_User($user_id);
  12.  
  13. $user_login = stripslashes($user->user_login);
  14. $user_email = stripslashes($user->user_email);
  15.  
  16. // The blogname option is escaped with esc_html on the way into the database in sanitize_option
  17. // we want to reverse this for the plain text arena of emails.
  18. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  19.  
  20. $message = sprintf(__('New user registration on your site %s:'), $blogname) . "rnrn";
  21. $message .= sprintf(__('Username: %s'), $user_login) . "rnrn";
  22. $message .= sprintf(__('E-mail: %s'), $user_email) . "rn";
  23.  
  24. @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
  25.  
  26. if ( empty($plaintext_pass) )
  27. return;
  28.  
  29. $message = sprintf(__('Username: %s'), $user_login) . "rn";
  30. $message .= sprintf(__('Password: %s'), $plaintext_pass) . "rn";
  31. $message .= wp_login_url() . "rn";
  32.  
  33. // wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message)
  34.  
  35. }
  36. endif;
  37.  
  38. if ( !function_exists( 'wp_new_user_notification' ) ) :
  39. function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
  40. return;
  41. }
  42. endif;
  43.  
  44. if ( !function_exists( 'wp_new_user_notification' ) ) :
  45. function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
  46. $user = get_userdata( $user_id );
  47.  
  48. $user_login = stripslashes($user->user_login);
  49. $user_email = stripslashes($user->user_email);
  50.  
  51. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  52.  
  53. if ( empty($plaintext_pass) ) {
  54. return;
  55. }
  56.  
  57. $message = sprintf(__('Username: %s'), $user_login) . "rn";
  58. $message .= sprintf(__('Password: %s'), $plaintext_pass) . "rn";
  59. $message .= wp_login_url() . "rn";
  60.  
  61. wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
  62. }
  63. endif;
  64.  
  65. add_action( 'register_post', 'maybe_stop_notifications', 10, 3 );
  66.  
  67. function maybe_stop_notifications ( $sanitized_user_login, $user_email, $errors ) {
  68.  
  69. if( empty( $errors->get_error_code() )) {
  70.  
  71. remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
  72.  
  73. }
  74. }
  75.  
  76. if ( !function_exists('wp_new_user_notification') ) {
  77. function wp_new_user_notification( ) {}
  78. }
Add Comment
Please, Sign In to add comment