PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.6
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.6
1.8.13.1 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 All 212 releases
charitable / includes / endpoints / class-charitable-forgot-password-endpoint.php

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

180 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Forgot password endpoint.
4 *
5 * @package Charitable/Classes/Charitable_Forgot_Password_Endpoint
6 * @author 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.5.0
10 * @version 1.6.55
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Forgot_Password_Endpoint' ) ) :
18
19 /**
20 * Charitable_Forgot_Password_Endpoint
21 *
22 * @since 1.5.0
23 */
24 class Charitable_Forgot_Password_Endpoint extends Charitable_Endpoint {
25
26 /** Endpoint ID. */
27 const ID = 'forgot_password';
28
29 /**
30 * Object instantiation.
31 *
32 * @since 1.5.4
33 */
34 public function __construct() {
35 $this->cacheable = false;
36 }
37
38 /**
39 * Return the endpoint ID.
40 *
41 * @since 1.5.0
42 *
43 * @return string
44 */
45 public static function get_endpoint_id() {
46 return self::ID;
47 }
48
49 /**
50 * Add rewrite rules for the endpoint.
51 *
52 * @since 1.5.0
53 *
54 * @return void
55 */
56 public function setup_rewrite_rules() {
57 add_rewrite_endpoint( 'forgot_password', EP_PERMALINK );
58 add_rewrite_rule( '(.?.+?)(?:/([0-9]+))?/forgot-password/?$', 'index.php?pagename=$matches[1]&page=$matches[2]&forgot_password=1', 'top' );
59 }
60
61 /**
62 * Return the endpoint URL.
63 *
64 * @since 1.5.0
65 *
66 * @global WP_Rewrite $wp_rewrite
67 * @param array $args Mixed arguments.
68 * @return string
69 */
70 public function get_page_url( $args = array() ) {
71 global $wp_rewrite;
72
73 $login_page = charitable_get_permalink( 'login_page' );
74
75 /* If we are using the default WordPress login process, return the lostpassword URL. */
76 if ( wp_login_url() == $login_page ) {
77 return wp_lostpassword_url();
78 }
79
80 if ( $wp_rewrite->using_permalinks() ) {
81 return trailingslashit( $login_page ) . 'forgot-password/';
82 }
83
84 return esc_url_raw( add_query_arg( array( 'forgot_password' => 1 ), $login_page ) );
85 }
86
87 /**
88 * Return whether we are currently viewing the endpoint.
89 *
90 * @since 1.5.0
91 *
92 * @global WP_Query $wp_query
93 * @param array $args Mixed arguments.
94 * @return boolean
95 */
96 public function is_page( $args = array() ) {
97 global $wp_query;
98
99 $login_page = charitable_get_option( 'login_page', 'wp' );
100 $strict = ! array_key_exists( 'strict', $args ) || $args['strict'];
101
102 if ( 'wp' == $login_page ) {
103 return $strict ? false : wp_lostpassword_url() == charitable_get_current_url();
104 }
105
106 return $wp_query->is_main_query()
107 && array_key_exists( 'forgot_password', $wp_query->query_vars );
108 }
109
110 /**
111 * Whether the endpoint uses a custom template.
112 *
113 * @since 1.6.55
114 *
115 * @return boolean
116 */
117 public function uses_custom_template() {
118 return ! charitable_is_block_theme() && 'wp' !== charitable_get_option( 'login_page', 'wp' );
119 }
120
121 /**
122 * Prepare the template for the endpoint.
123 *
124 * @since 1.6.55
125 *
126 * @return void
127 */
128 public function setup_template() {
129 new Charitable_Ghost_Page(
130 'forgot-password-page',
131 array(
132 'title' => __( 'Forgot Password', 'charitable' ),
133 'content' => '<!-- Silence is golden -->',
134 )
135 );
136 }
137
138 /**
139 * Return the template to display for this endpoint.
140 *
141 * @since 1.5.0
142 *
143 * @param string $template The default template.
144 * @return array
145 */
146 public function get_template( $template ) {
147 return charitable_splice_template(
148 get_page_template_slug( charitable_get_option( 'login_page', 'wp' ) ),
149 array( 'forgot-password-page.php', 'page.php', 'singular.php', 'index.php' )
150 );
151 }
152
153 /**
154 * Get the content to display for the endpoint.
155 *
156 * @since 1.5.0
157 *
158 * @param string $content Default content.
159 * @return string
160 */
161 public function get_content( $content ) {
162 ob_start();
163
164 if ( isset( $_GET['email_sent'] ) ) {
165 charitable_template( 'account/forgot-password-sent.php' );
166 } else {
167 charitable_template(
168 'account/forgot-password.php',
169 array(
170 'form' => new Charitable_Forgot_Password_Form(),
171 )
172 );
173 }
174
175 return ob_get_clean();
176 }
177 }
178
179 endif;
180