PluginProbe ʕ •ᴥ•ʔ
Really Simple Security – Simple and Performant Security (formerly Really Simple SSL) / 9.5.7
Really Simple Security – Simple and Performant Security (formerly Really Simple SSL) v9.5.7
9.5.11 9.5.10.1 9.5.10 trunk 9.4.0 9.4.1 9.4.2 9.4.3 9.5.0 9.5.0.1 9.5.0.2 9.5.1 9.5.2 9.5.2.2 9.5.2.3 9.5.3 9.5.3.1 9.5.3.2 9.5.4 9.5.5 9.5.6 9.5.7 9.5.8 9.5.9
really-simple-ssl / mailer / class-mail-admin.php
really-simple-ssl / mailer Last commit date
templates 1 year ago class-mail-admin.php 10 months ago class-mail.php 7 months ago index.php 2 years ago
class-mail-admin.php
134 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit;
3
4 /**
5 * Class to send an e-mail
6 */
7
8 if ( !class_exists('rsssl_mailer_admin') ) {
9 class rsssl_mailer_admin {
10
11 public function __construct() {
12 add_filter( 'rsssl_five_minutes_cron', array( $this, 'maybe_send_mail' ) );
13 add_filter( 'rsssl_five_minutes_cron', array( $this, 'rsssl_clear_expired_tokens' ) );
14 add_action( 'admin_init', array( $this, 'maybe_verify_user_email' ) );
15 add_action( 'rsssl_after_save_field', array( $this, 'maybe_allow_restart_email_verification' ), 10, 4 );
16 }
17
18 /**
19 * @return void
20 *
21 * Clear expired verification tokens from DB
22 */
23 public function rsssl_clear_expired_tokens() {
24
25 $token_expiration = get_option( 'rsssl_email_verification_code_expiration' );
26 if ( $token_expiration > time() ) {
27 delete_option( 'rsssl_email_verification_code' );
28 delete_option( 'rsssl_email_verification_code_expiration' );
29 }
30 }
31
32 /**
33 * @return void
34 *
35 * Verify user e-mail
36 */
37 public function maybe_verify_user_email() {
38
39 if ( ! rsssl_user_can_manage() ) {
40 return;
41 }
42
43 if ( ! isset( $_GET['rsssl_verification_code'] ) || ! isset( $_GET['rsssl_nonce'] ) ) {
44 return;
45 }
46
47 // verify code
48 $user_id = get_current_user_id();
49 $nonce = $_GET['rsssl_nonce'];
50 if ( ! wp_verify_nonce( $nonce, 'rsssl_email_verification_' . $user_id ) ) {
51 return;
52 }
53
54 // Handle e-mail verification
55 $verification_code = $_GET['rsssl_verification_code'];
56 $verification_code = preg_replace( "/[^0-9]/", "", $verification_code );
57 $verification_code = substr( $verification_code, 0, 6 );
58
59 $current_time = time();
60 $saved_verification_code = get_option('rsssl_email_verification_code');
61 $saved_verification_expiration = get_option('rsssl_email_verification_code_expiration');
62
63 if ( $verification_code === $saved_verification_code && $saved_verification_expiration && $current_time < $saved_verification_expiration ) {
64 // If the verification code is correct and hasn't expired, update the verification status
65 update_option( 'rsssl_email_verification_status', 'completed', false );
66 update_option('rsssl_redirect_to_settings_page', true);
67 }
68 }
69
70 /**
71 * @return void
72 */
73 public function maybe_send_mail() {
74 if ( ! rsssl_get_option( 'send_notifications_email' ) ) {
75 return;
76 }
77
78 $fields = get_option( 'rsssl_email_warning_fields', [] );
79 $time_saved = get_option( 'rsssl_email_warning_fields_saved' );
80 if ( ! $time_saved ) {
81 return;
82 }
83
84 $thirty_minutes_ago = $time_saved < strtotime( "-10 minutes" );
85 $warning_blocks = array_column( $fields, 'email' );
86 if ( $thirty_minutes_ago && count( $warning_blocks ) > 0 ) {
87 //clear the option
88 delete_option( 'rsssl_email_warning_fields', [] );
89 delete_option( 'rsssl_email_warning_fields_saved' );
90 $mailer = new rsssl_mailer();
91 $mailer->warning_blocks = $warning_blocks;
92 $mailer->send_mail();
93 }
94 }
95
96 /**
97 * @return bool|void
98 *
99 * E-mail verification status callback
100 */
101 public function email_verification_completed() {
102 $status = get_option( 'rsssl_email_verification_status' );
103
104 if ( $status === 'started' ) {
105 return false;
106 }
107
108 if ( $status === 'completed' ) {
109 return true;
110 }
111
112 if ( $status === 'email_changed' ) {
113 return false;
114 }
115
116 }
117
118 /**
119 * @param $field_id
120 * @param $field_value
121 * @param $prev_value
122 * @param $field_type
123 *
124 * @return void
125 *
126 * Maybe allow the user to re-verify their e-mail address after the notifications e-mail address has changed
127 */
128 public function maybe_allow_restart_email_verification( $field_id, $field_value, $prev_value, $field_type ) {
129 if ( $field_id === 'notifications_email_address' && $field_value !== $prev_value && rsssl_user_can_manage() ) {
130 update_option( 'rsssl_email_verification_status', 'email_changed' );
131 }
132 }
133 }
134 }