PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.2
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.2
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 / endpoints / class-charitable-reset-password-endpoint.php

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

182 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Password reset endpoint.
4 *
5 * @package Charitable/Classes/Charitable_Reset_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_Reset_Password_Endpoint' ) ) :
18
19 /**
20 * Charitable_Reset_Password_Endpoint
21 *
22 * @since 1.5.0
23 */
24 class Charitable_Reset_Password_Endpoint extends Charitable_Endpoint {
25
26 /** Endpoint ID. */
27 const ID = 'reset_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( 'reset_password', EP_PERMALINK );
58 add_rewrite_rule( '(.?.+?)(?:/([0-9]+))?/reset-password/?$', 'index.php?pagename=$matches[1]&page=$matches[2]&reset_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 false. */
76 if ( wp_login_url() == $login_page ) {
77 charitable_get_deprecated()->doing_it_wrong(
78 __FUNCTION__,
79 __( 'Password reset link should not be called when using the default WordPress login.', 'charitable' ),
80 '1.4.0'
81 );
82
83 return false;
84 }
85
86 /* Get the base URL. */
87 if ( $wp_rewrite->using_permalinks() ) {
88 return trailingslashit( $login_page ) . 'reset-password/';
89 }
90
91 return esc_url_raw( add_query_arg( array( 'reset_password' => 1 ), $login_page ) );
92 }
93
94 /**
95 * Return whether we are currently viewing the endpoint.
96 *
97 * @since 1.5.0
98 *
99 * @global WP_Query $wp_query
100 * @param array $args Mixed set of arguments.
101 * @return boolean
102 */
103 public function is_page( $args = array() ) {
104 global $wp_query;
105
106 $login_page = charitable_get_option( 'login_page', 'wp' );
107
108 if ( 'wp' == $login_page ) {
109 return false;
110 }
111
112 return $wp_query->is_main_query()
113 && array_key_exists( 'reset_password', $wp_query->query_vars );
114 }
115
116 /**
117 * Whether the endpoint uses a custom template.
118 *
119 * @since 1.6.55
120 *
121 * @return boolean
122 */
123 public function uses_custom_template() {
124 return ! charitable_is_block_theme() && 'wp' !== charitable_get_option( 'login_page', 'wp' );
125 }
126
127 /**
128 * Prepare the template for the endpoint.
129 *
130 * @since 1.6.55
131 *
132 * @return void
133 */
134 public function setup_template() {
135 new Charitable_Ghost_Page(
136 'reset-password-page',
137 array(
138 'title' => __( 'Reset Password', 'charitable' ),
139 'content' => '<!-- Silence is golden -->',
140 )
141 );
142 }
143
144 /**
145 * Return the template to display for this endpoint.
146 *
147 * @since 1.5.0
148 *
149 * @param string $template The default template.
150 * @return array
151 */
152 public function get_template( $template ) {
153 return charitable_splice_template(
154 get_page_template_slug( charitable_get_option( 'login_page', 'wp' ) ),
155 array( 'reset-password-page.php', 'page.php', 'singular.php', 'index.php' )
156 );
157 }
158
159 /**
160 * Get the content to display for the endpoint.
161 *
162 * @since 1.5.0
163 *
164 * @param string $content The page content.
165 * @return string
166 */
167 public function get_content( $content ) {
168 ob_start();
169
170 charitable_template(
171 'account/reset-password.php',
172 array(
173 'form' => new Charitable_Reset_Password_Form(),
174 )
175 );
176
177 return ob_get_clean();
178 }
179 }
180
181 endif;
182