PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.5
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.5
1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 All 211 releases
charitable / includes / forms / class-charitable-forgot-password-form.php

class-charitable-forgot-password-form.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.5, at includes/forms/class-charitable-forgot-password-form.php

151 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class that manages the display and processing of the forgot password form.
4 *
5 * @package Charitable/Classes/Charitable_Forgot_Password_Form
6 * @author Rafe Colton, David Bisset
7 * @copyright Copyright (c) 2022, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.4.0
10 * @version 1.5.1
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Forgot_Password_Form' ) ) :
18
19 /**
20 * Charitable_Forgot_Password_Form
21 *
22 * @since 1.4.0
23 */
24 class Charitable_Forgot_Password_Form extends Charitable_Form {
25
26 /**
27 * Nonce action.
28 *
29 * @since 1.4.0
30 *
31 * @var string
32 */
33 protected $nonce_action = 'charitable_forgot_password';
34
35 /**
36 * Nonce name.
37 *
38 * @since 1.4.0
39 *
40 * @var string
41 */
42 protected $nonce_name = '_charitable_forgot_password_nonce';
43
44 /**
45 * Form action.
46 *
47 * @since 1.4.0
48 *
49 * @var string
50 */
51 protected $form_action = 'retrieve_password';
52
53 /**
54 * Create class object.
55 *
56 * @since 1.4.0
57 *
58 * @param array $args User-defined shortcode attributes.
59 */
60 public function __construct() {
61 $this->id = uniqid();
62
63 /* For backwards-compatibility */
64 add_action( 'charitable_form_field', array( $this, 'render_field' ), 10, 6 );
65 }
66
67 /**
68 * Forgot password fields to be displayed.
69 *
70 * @since 1.4.0
71 *
72 * @return array
73 */
74 public function get_fields() {
75 $fields = apply_filters( 'charitable_forgot_password_fields', array(
76 'user_login' => array(
77 'label' => __( 'Email Address', 'charitable' ),
78 'type' => 'email',
79 'required' => true,
80 'priority' => 10,
81 ),
82 ) );
83
84 uasort( $fields, 'charitable_priority_sort' );
85
86 return $fields;
87 }
88
89 /**
90 * Send the password reset email.
91 *
92 * @since 1.4.0
93 *
94 * @return bool|WP_Error True: when finish. WP_Error on error
95 */
96 public static function retrieve_password() {
97 $form = new Charitable_Forgot_Password_Form();
98
99 if ( ! $form->validate_nonce() || ! $form->validate_honeypot() ) {
100 charitable_get_notices()->add_error( __( 'Unfortunately, we were unable to verify your form submission. Please reload the page and try again.', 'charitable' ) );
101 return;
102 }
103
104 if ( empty( $_POST['user_login'] ) ) {
105 charitable_get_notices()->add_error( __( '<strong>ERROR</strong>: Enter a username or email address.', 'charitable' ) );
106 return;
107 } elseif ( strpos( $_POST['user_login'], '@' ) ) {
108 $user = get_user_by( 'email', trim( $_POST['user_login'] ) );
109 } else {
110 $login = trim( $_POST['user_login'] );
111 $user = get_user_by( 'login', $login );
112 }
113
114 do_action( 'lostpassword_post' );
115
116 /* If we are missing user data, proceed no further. */
117 if ( ! $user ) {
118 charitable_get_notices()->add_error( __( '<strong>ERROR</strong>: Invalid username or email.', 'charitable' ) );
119 return;
120 }
121
122 /* Prepare the email. */
123 $email = new Charitable_Email_Password_Reset( array( 'user' => $user ) );
124
125 /* Make sure that the reset link was generated correctly. */
126 if ( is_wp_error( $email->get_reset_link() ) ) {
127 charitable_get_notices()->add_errors_from_wp_error( $email->get_reset_link() );
128 return;
129 }
130
131 $sent = $email->send();
132
133 if ( ! $sent ) {
134 charitable_get_notices()->add_error( __( 'We were unable to send your password reset email.', 'charitable' ) );
135 return;
136 }
137
138 charitable_get_notices()->add_success( __( 'Your password reset request has been received. Please check your email for a link to reset your password.', 'charitable' ) );
139
140 charitable_get_session()->add_notices();
141
142 $redirect_url = esc_url_raw( charitable_get_permalink( 'login_page' ) );
143
144 wp_safe_redirect( $redirect_url );
145
146 exit();
147 }
148 }
149
150 endif;
151