| @@ -29,9 +29,12 @@ | ||
| 29 | 29 | */ |
| 30 | 30 | public function __construct() { |
| 31 | 31 | add_action( 'tutor_action_tutor_retrieve_password', array( $this, 'tutor_retrieve_password' ) ); |
| 32 | 32 | add_action( 'tutor_action_tutor_process_reset_password', array( $this, 'tutor_process_reset_password' ) ); |
| 33 | + | |
| 34 | + add_action( 'tutor_reset_password_notification', array( $this, 'reset_password_notification' ), 10, 2 ); | |
| 33 | 35 | add_filter( 'tutor_lostpassword_url', array( $this, 'lostpassword_url' ) ); |
| 36 | + add_filter( 'lostpassword_url', array( $this, 'lostpassword_url' ), 99 ); | |
| 34 | 37 | } |
| 35 | 38 | |
| 36 | 39 | /** |
| 37 | 40 | * Retrieve Password |
| @@ -36,17 +39,16 @@ | ||
| 36 | 39 | /** |
| 37 | 40 | * Retrieve Password |
| 38 | 41 | * |
| 39 | 42 | * @since 1.4.3 |
| 40 | - * | |
| 41 | 43 | * @return void|bool |
| 42 | 44 | */ |
| 43 | 45 | public function tutor_retrieve_password() { |
| 44 | 46 | tutils()->checking_nonce(); |
| 45 | - | |
| 47 | + | |
| 46 | 48 | /** |
| 47 | 49 | * To check spam or other logic before form process. |
| 48 | - * | |
| 50 | + * | |
| 49 | 51 | * @since 2.1.10 |
| 50 | 52 | */ |
| 51 | 53 | $before_form_process = apply_filters( 'tutor_before_retrieve_password_form_process', null ); |
| 52 | 54 | if ( is_wp_error( $before_form_process ) ) { |
| @@ -103,15 +105,31 @@ | ||
| 103 | 105 | tutor_flash_set( 'danger', $allow->get_error_message() ); |
| 104 | 106 | return false; |
| 105 | 107 | } |
| 106 | 108 | |
| 107 | - $errors = retrieve_password(); | |
| 108 | - if ( is_wp_error( $errors ) ) { | |
| 109 | - tutor_flash_set( 'danger', $errors->get_error_message() ); | |
| 110 | - return false; | |
| 111 | - } | |
| 109 | + // Get password reset key (function introduced in WordPress 4.4). | |
| 110 | + $key = get_password_reset_key( $user_data ); | |
| 112 | 111 | |
| 113 | - $html = '<p> ' . __( "We've sent an email to this account's email address. Click the link in the email to reset your password. If you don't see the email, check other places it might be, like your junk, spam, social, promotion or others folders.", 'tutor' ) . '</p>'; | |
| 112 | + // Send email notification. | |
| 113 | + do_action( 'tutor_reset_password_notification', $user_login, $key ); | |
| 114 | + } | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * Send notification for rest password | |
| 118 | + * | |
| 119 | + * @since 1.4.3 | |
| 120 | + * | |
| 121 | + * @param string $user_login username. | |
| 122 | + * @param string $reset_key reset key. | |
| 123 | + * | |
| 124 | + * @return void | |
| 125 | + */ | |
| 126 | + public function reset_password_notification( $user_login = '', $reset_key = '' ) { | |
| 127 | + $this->send_notification( $user_login, $reset_key ); | |
| 128 | + | |
| 129 | + $html = '<h3>' . __( 'Check your E-Mail', 'tutor' ) . '</h3>'; | |
| 130 | + $html .= '<p> ' . __( "We've sent an email to this account's email address. Click the link in the email to reset your password.", 'tutor' ) . '</p>'; | |
| 131 | + $html .= '<p>' . __( " If you don't see the email, check other places it might be, like your junk, spam, social, promotion or others folders.", 'tutor' ) . '</p>'; | |
| 114 | 132 | tutor_flash_set( 'success', $html ); |
| 115 | 133 | } |
| 116 | 134 | |
| 117 | 135 | /** |
| @@ -175,8 +193,44 @@ | ||
| 175 | 193 | |
| 176 | 194 | wp_safe_redirect( tutor_utils()->tutor_dashboard_url() ); |
| 177 | 195 | exit; |
| 178 | 196 | } |
| 197 | + } | |
| 198 | + | |
| 199 | + /** | |
| 200 | + * Send Password Reset E-Mail to user. | |
| 201 | + * We are sending directly right now, later we will introduce centralised E-Mail notification System... | |
| 202 | + * | |
| 203 | + * @since 1.4.3 | |
| 204 | + * | |
| 205 | + * @param string $user_login login username. | |
| 206 | + * @param string $reset_key password reset key. | |
| 207 | + * | |
| 208 | + * @return void | |
| 209 | + */ | |
| 210 | + public function send_notification( $user_login, $reset_key ) { | |
| 211 | + | |
| 212 | + $user_data = get_user_by( 'login', $user_login ); | |
| 213 | + | |
| 214 | + $variable = array( | |
| 215 | + 'user_login' => $user_login, | |
| 216 | + 'reset_key' => $reset_key, | |
| 217 | + 'user_id' => $user_data->ID, | |
| 218 | + ); | |
| 219 | + | |
| 220 | + $html = tutor_get_template_html( 'email.send-reset-password', $variable ); | |
| 221 | + /* translators: %s: site name */ | |
| 222 | + $subject = sprintf( __( 'Password Reset Request for %s', 'tutor' ), get_option( 'blogname' ) ); | |
| 223 | + | |
| 224 | + $header = 'Content-Type: text/html' . "\r\n"; | |
| 225 | + | |
| 226 | + add_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); | |
| 227 | + add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); | |
| 228 | + | |
| 229 | + wp_mail( $user_data->user_email, $subject, $html, $header ); | |
| 230 | + | |
| 231 | + remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); | |
| 232 | + remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); | |
| 179 | 233 | } |
| 180 | 234 | |
| 181 | 235 | /** |
| 182 | 236 | * Get e-mail from address |