| 1 |
<?php |
| 2 |
|
| 3 |
class easy_basic_authentication_emailalert_class { |
| 4 |
|
| 5 |
public function __construct() |
| 6 |
{ |
| 7 |
|
| 8 |
} |
| 9 |
|
| 10 |
public function is_enabled() { |
| 11 |
return get_option( 'basic_auth_plugin_alert_enable' )&&filter_var(get_option( 'basic_auth_plugin_alertemail' ), FILTER_VALIDATE_EMAIL); |
| 12 |
} |
| 13 |
|
| 14 |
public function sendAlert($access) { |
| 15 |
$to = get_option('basic_auth_plugin_alertemail'); |
| 16 |
$subject = __('Access Attempt', 'easy-basic-authentication'); |
| 17 |
|
| 18 |
$message = '<html><body>'; |
| 19 |
$message .= '<p>' . __('Hi', 'easy-basic-authentication') . ',</p>'; |
| 20 |
$message .= '<p>' . __('New access attempt detected:', 'easy-basic-authentication') . '</p>'; |
| 21 |
$message .= '<ul style="list-style-type: none; padding-left: 0;">'; |
| 22 |
$message .= '<li><strong>' . __('IP:', 'easy-basic-authentication') . '</strong> ' . esc_attr($access['REMOTE_ADDR']) . '</li>'; |
| 23 |
$message .= '<li><strong>' . __('Browser:', 'easy-basic-authentication') . '</strong> ' . esc_attr($access['HTTP_USER_AGENT']) . '</li>'; |
| 24 |
$message .= '<li><strong>' . __('Request URI:', 'easy-basic-authentication') . '</strong> ' . esc_attr($access['REQUEST_URI']) . '</li>'; |
| 25 |
$message .= '</ul>'; |
| 26 |
$message .= '<p>' . __('All text of the call:', 'easy-basic-authentication') . '</p>'; |
| 27 |
$message .= '<pre style="font-size: 0.8em; background-color: #f8f8f8; padding: 10px;">' . esc_html(wp_json_encode($access, JSON_PRETTY_PRINT)) . '</pre>'; |
| 28 |
$message .= '<p>' . __('You are receiving this email because you have installed Easy Basic Authentication on your website and enabled the email alert option.', 'easy-basic-authentication') . '</p>'; |
| 29 |
$message .= '</body></html>'; |
| 30 |
|
| 31 |
$site_email = get_option('admin_email'); |
| 32 |
|
| 33 |
$headers = array( |
| 34 |
'Content-Type: text/html; charset=UTF-8', |
| 35 |
'From: ' . $site_email, |
| 36 |
); |
| 37 |
|
| 38 |
// Invio dell'email |
| 39 |
wp_mail($to, $subject, $message, $headers); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
} |