| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDataAccess\Settings { |
| 4 |
|
| 5 |
use WPDataAccess\Utilities\WPDA_Mail; |
| 6 |
use WPDataAccess\Utilities\WPDA_Message_Box; |
| 7 |
use WPDataAccess\WPDA; |
| 8 |
|
| 9 |
class WPDA_Settings_Mail extends WPDA_Settings { |
| 10 |
|
| 11 |
protected function add_content() { |
| 12 |
|
| 13 |
if ( isset( $_REQUEST['action'] ) ) { |
| 14 |
$action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); // input var okay. |
| 15 |
|
| 16 |
// Security check. |
| 17 |
$wp_nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : ''; // input var okay. |
| 18 |
if ( ! wp_verify_nonce( $wp_nonce, 'wpda-mail-settings-' . WPDA::get_current_user_login() ) ) { |
| 19 |
wp_die( esc_attr__( 'ERROR: Not authorized', 'wp-data-access' ) ); |
| 20 |
} |
| 21 |
|
| 22 |
if ( 'save' === $action ) { |
| 23 |
|
| 24 |
$mail = array( |
| 25 |
'activate' => isset( $_POST['activate'] ) ? sanitize_text_field( wp_unslash( $_POST['activate'] ) ) : '', |
| 26 |
'host' => sanitize_text_field( wp_unslash( $_POST['host'] ) ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
| 27 |
'port' => sanitize_text_field( wp_unslash( $_POST['port'] ) ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
| 28 |
'authenticate' => isset( $_POST['authenticate'] ) ? sanitize_text_field( wp_unslash( $_POST['authenticate'] ) ) : '', |
| 29 |
'encryption' => sanitize_text_field( wp_unslash( $_POST['encryption'] ) ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
| 30 |
'skip_verify' => isset( $_POST['skip_verify'] ) ? sanitize_text_field( wp_unslash( $_POST['skip_verify'] ) ) : '', |
| 31 |
'username' => sanitize_text_field( wp_unslash( $_POST['username'] ) ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
| 32 |
'password' => sanitize_text_field( wp_unslash( $_POST['password'] ) ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
| 33 |
'debug' => sanitize_text_field( wp_unslash( $_POST['debug'] ) ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
| 34 |
); |
| 35 |
|
| 36 |
WPDA_Mail::update_option( $mail ); |
| 37 |
|
| 38 |
} elseif ( 'setdefaults' === $action ) { |
| 39 |
|
| 40 |
WPDA_Mail::delete_option(); |
| 41 |
} |
| 42 |
|
| 43 |
$msg = new WPDA_Message_Box( |
| 44 |
array( |
| 45 |
'message_text' => __( 'Settings saved', 'wp-data-access' ), |
| 46 |
) |
| 47 |
); |
| 48 |
$msg->box(); |
| 49 |
} |
| 50 |
|
| 51 |
$option = WPDA_Mail::get_option(); |
| 52 |
|
| 53 |
$activate = $option['activate'] ?? ''; |
| 54 |
$host = $option['host'] ?? ''; |
| 55 |
$port = $option['port'] ?? ''; |
| 56 |
$authenticate = $option['authenticate'] ?? ''; |
| 57 |
$encryption = $option['encryption'] ?? ''; |
| 58 |
$skip_verify = $option['skip_verify'] ?? ''; |
| 59 |
$username = $option['username'] ?? ''; |
| 60 |
$password = $option['password'] ?? ''; |
| 61 |
$debug = $option['debug'] ?? ''; |
| 62 |
|
| 63 |
?> |
| 64 |
|
| 65 |
<form |
| 66 |
id="wpda_settings_mail" |
| 67 |
method="post" |
| 68 |
action="?page=<?php echo esc_attr( $this->page ); ?>&tab=mail" |
| 69 |
> |
| 70 |
<table class="wpda-table-settings"> |
| 71 |
<tr> |
| 72 |
<th> |
| 73 |
SMTP Mail Server Settings |
| 74 |
<br/><br/> |
| 75 |
<label style="font-weight: normal"> |
| 76 |
<input |
| 77 |
type="checkbox" |
| 78 |
name="activate" |
| 79 |
<?php echo 'on' === $activate ? 'checked' : ''; ?> |
| 80 |
/> <?php esc_html_e( 'Activate', 'wp-data-access' ); ?> |
| 81 |
</label> |
| 82 |
</th> |
| 83 |
<td> |
| 84 |
SMTP mail server settings are used to send scheduled SQL Query Builder results. |
| 85 |
<br/><br/> |
| 86 |
Test your mail settings using the SEND TEST MAIL button before activating. |
| 87 |
</td> |
| 88 |
</tr> |
| 89 |
<tr> |
| 90 |
<th> |
| 91 |
Host |
| 92 |
</th> |
| 93 |
<td> |
| 94 |
<input |
| 95 |
type="text" |
| 96 |
name="host" |
| 97 |
value="<?php echo esc_attr( $host ); ?>" |
| 98 |
style="min-width: 300px" |
| 99 |
/> |
| 100 |
</td> |
| 101 |
</tr> |
| 102 |
<tr> |
| 103 |
<th> |
| 104 |
Port |
| 105 |
</th> |
| 106 |
<td> |
| 107 |
<input |
| 108 |
type="number" |
| 109 |
name="port" |
| 110 |
value="<?php echo esc_attr( $port ); ?>" |
| 111 |
style="min-width: 300px" |
| 112 |
/> |
| 113 |
</td> |
| 114 |
</tr> |
| 115 |
<tr> |
| 116 |
<th></th> |
| 117 |
<td> |
| 118 |
<label style="font-weight: bold"> |
| 119 |
<input |
| 120 |
type="checkbox" |
| 121 |
name="authenticate" |
| 122 |
<?php echo 'on' === $authenticate ? 'checked' : ''; ?> |
| 123 |
/> SMTP authentication |
| 124 |
</label> |
| 125 |
</td> |
| 126 |
</tr> |
| 127 |
<tr> |
| 128 |
<th> |
| 129 |
Username |
| 130 |
</th> |
| 131 |
<td> |
| 132 |
<input |
| 133 |
type="text" |
| 134 |
name="username" |
| 135 |
value="<?php echo esc_attr( $username ); ?>" |
| 136 |
style="min-width: 300px" |
| 137 |
/> |
| 138 |
</td> |
| 139 |
</tr> |
| 140 |
<tr> |
| 141 |
<th> |
| 142 |
Password |
| 143 |
</th> |
| 144 |
<td> |
| 145 |
<input |
| 146 |
type="password" |
| 147 |
name="password" |
| 148 |
value="<?php echo esc_attr( $password ); ?>" |
| 149 |
style="min-width: 300px" |
| 150 |
/> |
| 151 |
</td> |
| 152 |
</tr> |
| 153 |
<tr> |
| 154 |
<th> |
| 155 |
Encryption |
| 156 |
</th> |
| 157 |
<td> |
| 158 |
<label style="font-weight: bold"> |
| 159 |
<select name="encryption"> |
| 160 |
<option key="" value="" <?php echo '' === $encryption ? 'selected' : ''; ?>>none</option> |
| 161 |
<option key="ssl" value="ssl" <?php echo 'ssl' === $encryption ? 'selected' : ''; ?>>ssl</option> |
| 162 |
<option key="tls" value="tls" <?php echo 'tls' === $encryption ? 'selected' : ''; ?>>tls</option> |
| 163 |
</select> |
| 164 |
</label> |
| 165 |
</td> |
| 166 |
</tr> |
| 167 |
<tr> |
| 168 |
<th></th> |
| 169 |
<td> |
| 170 |
<label style="font-weight: bold"> |
| 171 |
<input |
| 172 |
type="checkbox" |
| 173 |
name="skip_verify" |
| 174 |
<?php echo 'on' === $skip_verify ? 'checked' : ''; ?> |
| 175 |
/> Skip peer verification |
| 176 |
</label><br> |
| 177 |
<p style="padding-bottom: 0; margin-bottom: 0"> |
| 178 |
Use for testing on development servers. <strong>Disable in production!</strong> |
| 179 |
</p> |
| 180 |
</td> |
| 181 |
</tr> |
| 182 |
<tr> |
| 183 |
<th> |
| 184 |
Test |
| 185 |
</th> |
| 186 |
<td> |
| 187 |
<input |
| 188 |
type="email" |
| 189 |
id="email" |
| 190 |
style="min-width: 300px" |
| 191 |
placeholder="example@domain.com" |
| 192 |
/> |
| 193 |
<button |
| 194 |
class="button button-primary" |
| 195 |
onclick="jQuery('#mailSpinner').show(); sendMail(jQuery('#email').val(), 'WP Data Acces', 'Test message from WP Data Access.', <?php echo '0' === $debug ? 'false' : 'true'; ?>); return false;" |
| 196 |
> |
| 197 |
SEND TEST MAIL |
| 198 |
</button> |
| 199 |
<span id="mailSpinner" style="font-size: 16px; margin-left: 2px; display: none;"> |
| 200 |
<i class="fa-solid fa-sync fa-spin"></i> |
| 201 |
</span> |
| 202 |
</td> |
| 203 |
</tr> |
| 204 |
<tr> |
| 205 |
<th> |
| 206 |
Debug mode |
| 207 |
</th> |
| 208 |
<td> |
| 209 |
<label> |
| 210 |
<select name="debug"> |
| 211 |
<option key="0" value="0" <?php echo '' === $debug || '1' === $debug ? 'selected' : ''; ?>>off</option> |
| 212 |
<option key="1" value="1" <?php echo '1' === $debug ? 'selected' : ''; ?>>client</option> |
| 213 |
<option key="2" value="2" <?php echo '2' === $debug ? 'selected' : ''; ?>>server</option> |
| 214 |
<option key="3" value="3" <?php echo '3' === $debug ? 'selected' : ''; ?>>connection</option> |
| 215 |
<option key="4" value="4" <?php echo '4' === $debug ? 'selected' : ''; ?>>all</option> |
| 216 |
</select> Save before sending a test mail. <strong>Turn off in production!</strong> |
| 217 |
</label> |
| 218 |
</td> |
| 219 |
</tr> |
| 220 |
<tr style="display: none;"> |
| 221 |
<th> |
| 222 |
Debug info |
| 223 |
</th> |
| 224 |
<td> |
| 225 |
<div id="debugInfoContainer"></div> |
| 226 |
</td> |
| 227 |
</tr> |
| 228 |
</table> |
| 229 |
|
| 230 |
<div class="wpda-table-settings-button"> |
| 231 |
<input type="hidden" name="action" value="save"/> |
| 232 |
<button type="submit" class="button button-primary"> |
| 233 |
<i class="fas fa-check wpda_icon_on_button"></i> |
| 234 |
<?php esc_html_e( 'Save Mail Settings', 'wp-data-access' ); ?> |
| 235 |
</button> |
| 236 |
<a href="javascript:void(0)" |
| 237 |
onclick="if (confirm('<?php esc_html_e( 'Reset to defaults?', 'wp-data-access' ); ?>')) { |
| 238 |
jQuery('input[name=\'action\']').val('setdefaults'); |
| 239 |
jQuery('#wpda_settings_mail').trigger('submit'); |
| 240 |
}" |
| 241 |
class="button button-secondary"> |
| 242 |
<i class="fas fa-times-circle wpda_icon_on_button"></i> |
| 243 |
<?php esc_html_e( 'Reset Mail Settings To Defaults', 'wp-data-access' ); ?> |
| 244 |
</a> |
| 245 |
</div> |
| 246 |
|
| 247 |
<?php wp_nonce_field( 'wpda-mail-settings-' . WPDA::get_current_user_login(), '_wpnonce', false ); ?> |
| 248 |
|
| 249 |
</form> |
| 250 |
|
| 251 |
<?php |
| 252 |
|
| 253 |
} |
| 254 |
|
| 255 |
} |
| 256 |
|
| 257 |
} |