Guest User

Untitled

a guest
Mar 26th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * ACF Form Lost Password: Register Form
  5. */
  6. acf_register_form(array(
  7. 'id' => 'hwk_ajax_acf_lost_password',
  8. 'post_id' => 'hwk_ajax_acf_lost_password',
  9. 'form_attributes' => array(
  10. 'class' => 'acf-form acf-form-ajax',
  11. ),
  12. 'field_groups' => array(41),
  13. 'updated_message' => 'Mot de passe envoyé',
  14. 'return' => '',
  15. 'submit_value' => 'Envoyer',
  16. 'html_submit_button' => '<input type="submit" class="acf-button button btn btn-secondary btn-lg" value="%s" /> &nbsp; <a href="/connexion">Se connecter</a>',
  17. ));
  18.  
  19. /**
  20. * ACF Form Login: Ajax
  21. */
  22. add_action('acf/validate_save_post', 'hwk_ajax_acf_lost_password_ajax');
  23. function hwk_ajax_acf_lost_password_ajax(){
  24. if(!wp_doing_ajax() || !isset($_POST['_acf_post_id']) || $_POST['_acf_post_id'] != 'hwk_ajax_acf_lost_password' || !acf_verify_nonce('acf_form'))
  25. return;
  26.  
  27. if((!$form = hwk_acf_form_get_form()) || (!$data = hwk_acf_form_get_data()))
  28. wp_send_json_success(array(
  29. 'valid' => 1,
  30. 'data' => array(
  31. 'error' => 'Une erreur est survenue. Veuillez réessayer ultérieurement.'
  32. )
  33. ));
  34.  
  35. $input = $data['input'];
  36. $key = $data['key'];
  37.  
  38. // Email
  39. $input['email'] = sanitize_email($input['email']);
  40. if(empty($input['email']))
  41. acf_add_validation_error('acf['.$key['email'].']', 'Email invalide');
  42.  
  43. $user = get_user_by('email', $input['email']);
  44. if(!$user)
  45. acf_add_validation_error('acf['.$key['email'].']', 'Email invalide');
  46.  
  47. // Errors
  48. if($errors = acf_get_validation_errors())
  49. wp_send_json_success(array(
  50. 'valid' => 0,
  51. 'errors' => $errors,
  52. ));
  53.  
  54. $user_data = $user;
  55.  
  56. // ———————————-
  57. // Start wp-login.php (line: 342)
  58. // ———————————-
  59. $user_login = $user_data->user_login;
  60. $user_email = $user_data->user_email;
  61. $key = get_password_reset_key( $user_data );
  62. if ( is_wp_error( $key ) ) {
  63. wp_send_json(array('error' => $key));
  64. }
  65. if ( is_multisite() ) {
  66. $site_name = get_network()->site_name;
  67. } else {
  68. /*
  69. * The blogname option is escaped with esc_html on the way into the database
  70. * in sanitize_option we want to reverse this for the plain text arena of emails.
  71. */
  72. $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
  73. }
  74. $message = __( 'Someone has requested a password reset for the following account:' ) . "\r\r";
  75. /* translators: %s: site name */
  76. $message .= sprintf( __( 'Site Name: %s'), $site_name ) . "\r\r";
  77. /* translators: %s: user login */
  78. $message .= sprintf( __( 'Username: %s'), $user_login ) . "\r\r";
  79. $message .= __( 'If this was a mistake, just ignore this email and nothing will happen.' ) . "\r\r";
  80. $message .= __( 'To reset your password, visit the following address:' ) . "\r\r";
  81. $message .= '<' . network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . ">\r";
  82. /* translators: Password reset email subject. %s: Site name */
  83. $title = sprintf( __( '[%s] Password Reset' ), $site_name );
  84. /**
  85. * Filters the subject of the password reset email.
  86. *
  87. * @since 2.8.0
  88. * @since 4.4.0 Added the `$user_login` and `$user_data` parameters.
  89. *
  90. * @param string $title Default email title.
  91. * @param string $user_login The username for the user.
  92. * @param WP_User $user_data WP_User object.
  93. */
  94. $title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data );
  95. /**
  96. * Filters the message body of the password reset mail.
  97. *
  98. * If the filtered message is empty, the password reset email will not be sent.
  99. *
  100. * @since 2.8.0
  101. * @since 4.1.0 Added `$user_login` and `$user_data` parameters.
  102. *
  103. * @param string $message Default mail message.
  104. * @param string $key The activation key.
  105. * @param string $user_login The username for the user.
  106. * @param WP_User $user_data WP_User object.
  107. */
  108. $message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
  109. if ( $message && !wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) )
  110. wp_send_json_success(array(
  111. 'valid' => 1,
  112. 'data' => array(
  113. 'error' => __('The email could not be sent.') . "<br />" . __('Possible reason: your host may have disabled the mail() function.')
  114. ),
  115. ));
  116.  
  117. // ———————————-
  118. // End wp-login.php
  119. // ———————————-
  120.  
  121. wp_send_json_success(array(
  122. 'valid' => 1,
  123. 'data' => hwk_acf_form_get_return($form),
  124. ));
  125. }
Add Comment
Please, Sign In to add comment