← All changes
|
includes/emails/class-charitable-email-email-verification.php
+87
-31
1.6.7
→
1.8.13
View file →
| @@ -2,13 +2,13 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Class that models the Email Verification email. |
| 4 | 4 | * |
| 5 | 5 | * @package Charitable/Classes/Charitable_Email_Email_Verification |
| 6 | - * @author Eric Daams | |
| 7 | - * @copyright Copyright (c) 2018, Studio 164a | |
| 6 | + * @author David Bisset | |
| 7 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 8 | 8 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 | 9 | * @since 1.5.0 |
| 10 | - * @version 1.5.0 | |
| 10 | + * @version 1.6.37 | |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | 14 | exit; |
| @@ -22,9 +22,9 @@ | ||
| 22 | 22 | * @since 1.5.0 |
| 23 | 23 | */ |
| 24 | 24 | class Charitable_Email_Email_Verification extends Charitable_Email { |
| 25 | 25 | |
| 26 | - /* @var string */ | |
| 26 | + /** Email ID */ | |
| 27 | 27 | const ID = 'email_verification'; |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Whether the email allows you to define the email recipients. |
| @@ -134,22 +134,25 @@ | ||
| 134 | 134 | * @param array $settings Email settings. |
| 135 | 135 | * @return array |
| 136 | 136 | */ |
| 137 | 137 | public function add_email_settings( $settings ) { |
| 138 | - return array_merge( $settings, array( | |
| 139 | - 'send_after_registration' => array( | |
| 140 | - 'type' => 'radio', | |
| 141 | - 'title' => __( 'Send after Registration', 'charitable' ), | |
| 142 | - 'help' => __( 'Whether to send an email verification message immediately after registration. If this is not set, users are only prompted to verify their email when they try to access their donation history.', 'charitable' ), | |
| 143 | - 'priority' => 22, | |
| 144 | - 'class' => 'wide', | |
| 145 | - 'default' => 1, | |
| 146 | - 'options' => array( | |
| 147 | - '1' => __( 'Yes', 'charitable' ), | |
| 148 | - '0' => __( 'No', 'charitable' ), | |
| 138 | + return array_merge( | |
| 139 | + $settings, | |
| 140 | + array( | |
| 141 | + 'send_after_registration' => array( | |
| 142 | + 'type' => 'radio', | |
| 143 | + 'title' => __( 'Send after Registration', 'charitable' ), | |
| 144 | + 'help' => __( 'Whether to send an email verification message immediately after registration. If this is not set, users are only prompted to verify their email when they try to access their donation history.', 'charitable' ), | |
| 145 | + 'priority' => 22, | |
| 146 | + 'class' => 'wide', | |
| 147 | + 'default' => 1, | |
| 148 | + 'options' => array( | |
| 149 | + '1' => __( 'Yes', 'charitable' ), | |
| 150 | + '0' => __( 'No', 'charitable' ), | |
| 151 | + ), | |
| 149 | 152 | ), |
| 150 | - ), | |
| 151 | - ) ); | |
| 153 | + ) | |
| 154 | + ); | |
| 152 | 155 | } |
| 153 | 156 | |
| 154 | 157 | /** |
| 155 | 158 | * Return the custom email fields for this email. |
| @@ -161,19 +164,25 @@ | ||
| 161 | 164 | public function email_fields() { |
| 162 | 165 | $fields = array( |
| 163 | 166 | 'confirmation_url' => array( |
| 164 | 167 | 'description' => __( 'The link the user needs to verify their email address.', 'charitable' ), |
| 165 | - 'preview' => add_query_arg( array( | |
| 166 | - 'key' => '123123123', | |
| 167 | - 'login' => 'adam123', | |
| 168 | - ), charitable_get_permalink( 'email_verification' ) ), | |
| 168 | + 'preview' => add_query_arg( | |
| 169 | + array( | |
| 170 | + 'key' => '123123123', | |
| 171 | + 'login' => 'adam123', | |
| 172 | + ), | |
| 173 | + charitable_get_permalink( 'email_verification' ) | |
| 174 | + ), | |
| 169 | 175 | ), |
| 170 | 176 | ); |
| 171 | 177 | |
| 172 | 178 | if ( $this->has_valid_user() ) { |
| 173 | - $fields = array_merge_recursive( $fields, array( | |
| 174 | - 'confirmation_url' => array( 'callback' => array( $this, 'get_confirmation_url' ) ), | |
| 175 | - ) ); | |
| 179 | + $fields = array_merge_recursive( | |
| 180 | + $fields, | |
| 181 | + array( | |
| 182 | + 'confirmation_url' => array( 'callback' => array( $this, 'get_confirmation_url' ) ), | |
| 183 | + ) | |
| 184 | + ); | |
| 176 | 185 | } |
| 177 | 186 | |
| 178 | 187 | return $fields; |
| 179 | 188 | } |
| @@ -193,10 +202,11 @@ | ||
| 193 | 202 | return $key; |
| 194 | 203 | } |
| 195 | 204 | |
| 196 | 205 | $args = array( |
| 197 | - 'key' => $key, | |
| 198 | - 'login' => rawurlencode( $this->user->user_login ), | |
| 206 | + 'key' => $key, | |
| 207 | + 'login' => rawurlencode( $this->user->user_login ), | |
| 208 | + 'charitable' => true, | |
| 199 | 209 | ); |
| 200 | 210 | |
| 201 | 211 | $redirect_url = $this->get_redirect_url(); |
| 202 | 212 | |
| @@ -218,9 +228,9 @@ | ||
| 218 | 228 | * @return string |
| 219 | 229 | */ |
| 220 | 230 | public function get_redirect_url() { |
| 221 | 231 | if ( ! isset( $this->redirect_url ) ) { |
| 222 | - $profile = charitable_get_option( 'profile_page', false ); | |
| 232 | + $profile = charitable_get_option( 'profile_page', false ); | |
| 223 | 233 | $this->redirect_url = $profile ? get_permalink( $profile ) : false; |
| 224 | 234 | } |
| 225 | 235 | |
| 226 | 236 | return $this->redirect_url; |
| @@ -238,8 +248,54 @@ | ||
| 238 | 248 | $this->redirect_url = $redirect_url; |
| 239 | 249 | } |
| 240 | 250 | |
| 241 | 251 | /** |
| 252 | + * Send the email, then record the time that it was sent. | |
| 253 | + * | |
| 254 | + * @since 1.6.32 | |
| 255 | + * | |
| 256 | + * @return boolean | |
| 257 | + */ | |
| 258 | + public function send() { | |
| 259 | + $sent = parent::send(); | |
| 260 | + | |
| 261 | + if ( $sent ) { | |
| 262 | + update_user_meta( $this->user->ID, '_charitable_email_verification_email_send_time', time() ); | |
| 263 | + } | |
| 264 | + | |
| 265 | + return $sent; | |
| 266 | + } | |
| 267 | + | |
| 268 | + /** | |
| 269 | + * Checks whether the email was sent recently. | |
| 270 | + * | |
| 271 | + * @since 1.6.32 | |
| 272 | + * | |
| 273 | + * @return boolean | |
| 274 | + */ | |
| 275 | + public function sent_recently() { | |
| 276 | + $send_time = get_user_meta( $this->user->ID, '_charitable_email_verification_email_send_time', true ); | |
| 277 | + | |
| 278 | + if ( ! $send_time ) { | |
| 279 | + return false; | |
| 280 | + } | |
| 281 | + | |
| 282 | + /** | |
| 283 | + * Change the amount of minutes to wait before resending | |
| 284 | + * the email (unless it's a force-resend). | |
| 285 | + * | |
| 286 | + * By default, this is set to wait 30 minutes. | |
| 287 | + * | |
| 288 | + * @since 1.6.32 | |
| 289 | + * | |
| 290 | + * @param boolean $seconds The number of seconds to wait. | |
| 291 | + */ | |
| 292 | + $threshold = apply_filters( 'charitable_email_verification_resend_threshold_time', 1800 ); | |
| 293 | + | |
| 294 | + return time() - $send_time < $threshold; | |
| 295 | + } | |
| 296 | + | |
| 297 | + /** | |
| 242 | 298 | * Return the default subject line for the email. |
| 243 | 299 | * |
| 244 | 300 | * @since 1.5.0 |
| 245 | 301 | * |
| @@ -276,13 +332,13 @@ | ||
| 276 | 332 | * @return string |
| 277 | 333 | */ |
| 278 | 334 | protected function get_default_body() { |
| 279 | 335 | ob_start(); |
| 280 | -?> | |
| 281 | -<p><?php _e( 'Welcome to [charitable_email show=site_name]', 'charitable' ) ?></p> | |
| 282 | -<p><?php _e( 'To complete your registration, please confirm your email address by clicking the link below:', 'charitable' ) ?></p> | |
| 336 | + ?> | |
| 337 | +<p><?php esc_html_e( 'Welcome to [charitable_email show=site_name]', 'charitable' ); ?></p> | |
| 338 | +<p><?php esc_html_e( 'To complete your registration, please confirm your email address by clicking the link below:', 'charitable' ); ?></p> | |
| 283 | 339 | <p><a href="[charitable_email show=confirmation_url]">[charitable_email show=confirmation_url]</a></p> |
| 284 | -<?php | |
| 340 | + <?php | |
| 285 | 341 | /** |
| 286 | 342 | * Filter the default email body. |
| 287 | 343 | * |
| 288 | 344 | * @since 1.5.0 |