Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * ACF Form Lost Password: Register Form
- */
- acf_register_form(array(
- 'id' => 'hwk_ajax_acf_lost_password',
- 'post_id' => 'hwk_ajax_acf_lost_password',
- 'form_attributes' => array(
- 'class' => 'acf-form acf-form-ajax',
- ),
- 'field_groups' => array(41),
- 'updated_message' => 'Mot de passe envoyé',
- 'return' => '',
- 'submit_value' => 'Envoyer',
- 'html_submit_button' => '<input type="submit" class="acf-button button btn btn-secondary btn-lg" value="%s" /> <a href="/connexion">Se connecter</a>',
- ));
- /**
- * ACF Form Login: Ajax
- */
- add_action('acf/validate_save_post', 'hwk_ajax_acf_lost_password_ajax');
- function hwk_ajax_acf_lost_password_ajax(){
- if(!wp_doing_ajax() || !isset($_POST['_acf_post_id']) || $_POST['_acf_post_id'] != 'hwk_ajax_acf_lost_password' || !acf_verify_nonce('acf_form'))
- return;
- if((!$form = hwk_acf_form_get_form()) || (!$data = hwk_acf_form_get_data()))
- wp_send_json_success(array(
- 'valid' => 1,
- 'data' => array(
- 'error' => 'Une erreur est survenue. Veuillez réessayer ultérieurement.'
- )
- ));
- $input = $data['input'];
- $key = $data['key'];
- // Email
- $input['email'] = sanitize_email($input['email']);
- if(empty($input['email']))
- acf_add_validation_error('acf['.$key['email'].']', 'Email invalide');
- $user = get_user_by('email', $input['email']);
- if(!$user)
- acf_add_validation_error('acf['.$key['email'].']', 'Email invalide');
- // Errors
- if($errors = acf_get_validation_errors())
- wp_send_json_success(array(
- 'valid' => 0,
- 'errors' => $errors,
- ));
- $user_data = $user;
- // ———————————-
- // Start wp-login.php (line: 342)
- // ———————————-
- $user_login = $user_data->user_login;
- $user_email = $user_data->user_email;
- $key = get_password_reset_key( $user_data );
- if ( is_wp_error( $key ) ) {
- wp_send_json(array('error' => $key));
- }
- if ( is_multisite() ) {
- $site_name = get_network()->site_name;
- } else {
- /*
- * The blogname option is escaped with esc_html on the way into the database
- * in sanitize_option we want to reverse this for the plain text arena of emails.
- */
- $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
- }
- $message = __( 'Someone has requested a password reset for the following account:' ) . "\r\r";
- /* translators: %s: site name */
- $message .= sprintf( __( 'Site Name: %s'), $site_name ) . "\r\r";
- /* translators: %s: user login */
- $message .= sprintf( __( 'Username: %s'), $user_login ) . "\r\r";
- $message .= __( 'If this was a mistake, just ignore this email and nothing will happen.' ) . "\r\r";
- $message .= __( 'To reset your password, visit the following address:' ) . "\r\r";
- $message .= '<' . network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . ">\r";
- /* translators: Password reset email subject. %s: Site name */
- $title = sprintf( __( '[%s] Password Reset' ), $site_name );
- /**
- * Filters the subject of the password reset email.
- *
- * @since 2.8.0
- * @since 4.4.0 Added the `$user_login` and `$user_data` parameters.
- *
- * @param string $title Default email title.
- * @param string $user_login The username for the user.
- * @param WP_User $user_data WP_User object.
- */
- $title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data );
- /**
- * Filters the message body of the password reset mail.
- *
- * If the filtered message is empty, the password reset email will not be sent.
- *
- * @since 2.8.0
- * @since 4.1.0 Added `$user_login` and `$user_data` parameters.
- *
- * @param string $message Default mail message.
- * @param string $key The activation key.
- * @param string $user_login The username for the user.
- * @param WP_User $user_data WP_User object.
- */
- $message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
- if ( $message && !wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) )
- wp_send_json_success(array(
- 'valid' => 1,
- 'data' => array(
- 'error' => __('The email could not be sent.') . "<br />" . __('Possible reason: your host may have disabled the mail() function.')
- ),
- ));
- // ———————————-
- // End wp-login.php
- // ———————————-
- wp_send_json_success(array(
- 'valid' => 1,
- 'data' => hwk_acf_form_get_return($form),
- ));
- }
Add Comment
Please, Sign In to add comment