class.swpm-registration.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * Description of BRegistration
  4. *
  5. * @author nur
  6. */
  7. abstract class SwpmRegistration {
  8. protected $member_info = array();
  9. var $email_activation = false;
  10. protected static $_intance = null;
  11. //public abstract static function get_instance();
  12. protected function send_reg_email() {
  13. global $wpdb;
  14. if ( empty( $this->member_info ) ) {
  15. return false;
  16. }
  17. $member_info = $this->member_info;
  18. $settings = SwpmSettings::get_instance();
  19. $subject = $settings->get_value( 'reg-complete-mail-subject' );
  20. $body = $settings->get_value( 'reg-complete-mail-body' );
  21. if ( $this->email_activation ) {
  22. $swpm_user = SwpmMemberUtils::get_user_by_user_name( $member_info['user_name'] );
  23. $member_id = $swpm_user->member_id;
  24. $act_code = md5( uniqid() . $member_id );
  25. $enc_pass = SwpmUtils::crypt( $member_info['plain_password'] );
  26. $user_data = array(
  27. 'timestamp' => time(),
  28. 'act_code' => $act_code,
  29. 'plain_password' => $enc_pass,
  30. );
  31. $user_data = apply_filters( 'swpm_email_activation_data', $user_data );
  32. update_option( 'swpm_email_activation_data_usr_' . $member_id, $user_data, false );
  33. $body = $settings->get_value( 'email-activation-mail-body' );
  34. $subject = $settings->get_value( 'email-activation-mail-subject' );
  35. $activation_link = add_query_arg(
  36. array(
  37. 'swpm_email_activation' => '1',
  38. 'swpm_member_id' => $member_id,
  39. 'swpm_token' => $act_code,
  40. ),
  41. get_home_url()
  42. );
  43. // Allow hooks to change the value of activation_link
  44. $activation_link = apply_filters('swpm_send_reg_email_activation_link', $activation_link);
  45. $member_info['activation_link'] = $activation_link;
  46. }
  47. $from_address = $settings->get_value( 'email-from' );
  48. $login_link = $settings->get_value( 'login-page-url' );
  49. $headers = 'From: ' . $from_address . "\r\n";
  50. $member_info['membership_level_name'] = SwpmPermission::get_instance( $member_info['membership_level'] )->get( 'alias' );
  51. $member_info['password'] = $member_info['plain_password'];
  52. $member_info['login_link'] = $login_link;
  53. $values = array_values( $member_info );
  54. $keys = array_map( 'swpm_enclose_var', array_keys( $member_info ) );
  55. $body = html_entity_decode( $body );
  56. $body = str_replace( $keys, $values, $body );
  57. $swpm_user = SwpmMemberUtils::get_user_by_user_name( $member_info['user_name'] );
  58. $member_id = $swpm_user->member_id;
  59. $body = SwpmMiscUtils::replace_dynamic_tags( $body, $member_id ); //Do the standard merge var replacement.
  60. $email = sanitize_email( filter_input( INPUT_POST, 'email', FILTER_UNSAFE_RAW ) );
  61. if ( empty( $email ) ) {
  62. $email = $swpm_user->email;
  63. }
  64. $body = apply_filters( 'swpm_registration_complete_email_body', $body ); //This filter can be used to modify the registration complete email body dynamically.
  65. //Send notification email to the member
  66. $subject = apply_filters( 'swpm_email_registration_complete_subject', $subject );
  67. $body = apply_filters( 'swpm_email_registration_complete_body', $body ); //You can override the email to empty to disable this email.
  68. if ( ! empty( $body ) ) {
  69. SwpmMiscUtils::mail( trim( $email ), $subject, $body, $headers );
  70. SwpmLog::log_simple_debug( 'Member registration complete email sent to: ' . $email . '. From email address value used: ' . $from_address, true );
  71. } else {
  72. SwpmLog::log_simple_debug( 'NOTICE: Registration complete email body value is empty. Member registration complete email will NOT be sent.', true );
  73. }
  74. if ( $settings->get_value( 'enable-admin-notification-after-reg' ) && ! $this->email_activation ) {
  75. //Send notification email to the site admin
  76. $admin_notification = $settings->get_value( 'admin-notification-email' );
  77. $admin_notification = empty( $admin_notification ) ? $from_address : $admin_notification;
  78. $notify_emails_array = explode( ',', $admin_notification );
  79. $headers = 'From: ' . $from_address . "\r\n";
  80. $admin_notify_subject = $settings->get_value( 'reg-complete-mail-subject-admin' );
  81. if ( empty( $admin_notify_subject ) ) {
  82. $admin_notify_subject = 'Notification of New Member Registration';
  83. }
  84. $admin_notify_body = $settings->get_value( 'reg-complete-mail-body-admin' );
  85. if ( empty( $admin_notify_body ) ) {
  86. $admin_notify_body = "A new member has completed the registration.\n\n" .
  87. "Username: {user_name}\n" .
  88. "Email: {email}\n\n" .
  89. "Please login to the admin dashboard to view details of this user.\n\n" .
  90. "You can customize this email message from the Email Settings menu of the plugin.\n\n" .
  91. 'Thank You';
  92. }
  93. $additional_args = array( 'password' => $member_info['plain_password'] );
  94. $admin_notify_body = SwpmMiscUtils::replace_dynamic_tags( $admin_notify_body, $member_id, $additional_args ); //Do the standard merge var replacement.
  95. foreach ( $notify_emails_array as $to_email ) {
  96. $to_email = trim( $to_email );
  97. $admin_notify_subject = apply_filters( 'swpm_email_admin_notify_subject', $admin_notify_subject );
  98. $admin_notify_body = apply_filters( 'swpm_email_admin_notify_body', $admin_notify_body );
  99. SwpmMiscUtils::mail( $to_email, $admin_notify_subject, $admin_notify_body, $headers );
  100. SwpmLog::log_simple_debug( 'Admin notification email sent to: ' . $to_email, true );
  101. }
  102. }
  103. return true;
  104. }
  105. }
  106. function swpm_enclose_var( $n ) {
  107. return '{' . $n . '}';
  108. }