Mail settings implemented

This commit is contained in:
Thomas Günther 2024-07-31 21:20:57 +02:00
parent 923d76c085
commit 33287c4b40
7 changed files with 253 additions and 21 deletions

View File

@ -16,6 +16,7 @@ use Bdp\Modules\EventParticipants\Controllers\MainController as EventsMain;
use Bdp\Modules\KompassSettings\Controllers\SettingsPage as KomnpassSettings;
use Bdp\Modules\LimitLoginAttempts\Controllers\OptionsPage as OptionsPageAlias;
use Bdp\Modules\Mail\Controllers\MailController;
use Bdp\Modules\Mail\Controllers\MailSettingsController;
use Bdp\Modules\Security\Security;
use Bdp\Modules\Seo\Seo;
@ -135,6 +136,8 @@ if (false === (bool)get_option('user_can_register', false)) {
</style>
<?php
}
}
MailSettingsController::set_smtp_if_required();
}

View File

@ -12,7 +12,8 @@ function bdp_update_login_style() {
function bdp_update_dashboard_style() {
if (true === (bool)get_option( 'use_mareike_theme', false )) {
wp_enqueue_style( 'custom-dashboard-styles', BDP_LV_PLUGIN_URL . '/assets/mareike.css' );
#wp_enqueue_style( 'custom-dashboard-styles', BDP_LV_PLUGIN_URL . '/assets/mareike.css' );
wp_enqueue_style( 'custom-dashboard-styles', BDP_LV_PLUGIN_URL . '/assets/wordpress-bdp.css' );
} else {
wp_enqueue_style( 'custom-dashboard-styles', BDP_LV_PLUGIN_URL . '/assets/wordpress-bdp.css' );
}

View File

@ -14,6 +14,16 @@ class SettingsPage
['Bdp\Modules\KompassSettings\Controllers\SettingsPage', 'kompass_settings_page_new']
);
add_submenu_page('options-general.php',
'Mail',
'Mail',
'manage_options',
'kompass-mail-settings',
['Bdp\Modules\Mail\Controllers\MailSettingsController', 'settings_form']
);
}
public function __construct()
{
@ -23,14 +33,6 @@ class SettingsPage
'manage_options',
BDP_LV_PLUGIN_SLUG . '-Kompass-settings',
[$this, 'option_page'],2048);
add_options_page(
__('Mail', BDP_LV_PLUGIN_SLUG) . ' - ' . __('Settings', BDP_LV_PLUGIN_SLUG),
__('Mail', BDP_LV_PLUGIN_SLUG) . ' - ' . __('Settings', BDP_LV_PLUGIN_SLUG),
'manage_options',
BDP_LV_PLUGIN_SLUG . '-Kompass-mail-settings',
[$this, 'mail_option_page'],2048);
}

View File

@ -18,16 +18,6 @@ class MailController
'dashicons-email',
4
);
/*$mailCompose = new MailCompose();
add_submenu_page(
'kompass-mail',
__('Templates', BDP_LV_PLUGIN_SLUG),
__('Templates', BDP_LV_PLUGIN_SLUG),
'send_mails',
'kompass-mail-compose',
[$mailCompose, '__construct'],
1);*/
}
public function router()

View File

@ -0,0 +1,71 @@
<?php
/**
* File: class-mailsettingscontroller.php
*
*
* @since 2024-07-31
* @license GPL-3.0-or-later
*
* @package mareike/
*/
namespace Bdp\Modules\Mail\Controllers;
class MailSettingsController {
public static function set_smtp_if_required() {
$smtp_host = get_option('kompass_smtp_host', null); // SMTP-Host
$smtp_port = get_option('kompass_smtp_port', null); // SMTP-Port
$smtp_username = get_option('kompass_smtp_user', null); // SMTP-Benutzername
$smtp_password = get_option('kompass_smtp_pass', null); // SMTP-Passwort
$smtp_secure = 'tls'; // Verschlüsselung (tls oder ssl)
if (false !== (bool)get_option('kompass_use_smtp', false) &&
null !== $smtp_host &&
null !== $smtp_port &&
null !== $smtp_username &&
null !== $smtp_password) {
add_action( 'phpmailer_init', function ( $phpmailer ) use ( $smtp_host, $smtp_port, $smtp_username, $smtp_password, $smtp_secure ) {
$phpmailer->isSMTP();
$phpmailer->Host = $smtp_host;
$phpmailer->Port = $smtp_port;
$phpmailer->SMTPAuth = true;
$phpmailer->Username = $smtp_username;
$phpmailer->Password = $smtp_password;
$sender = get_option('kompass_smtp_sender', null);
$sender_name = get_option('kompass_smtp_sender-name', null);
if (null !== $sender && null !== $sender_name)
$phpmailer->setFrom( $sender, $sender_name );
#$phpmailer->SMTPSecure = $smtp_secure;
} );
}
}
public static function settings_form() {
if (isset($_POST['save'])) {
update_option('kompass_use_smtp', false);
if (isset($_POST['use_smtp'])) update_option('kompass_use_smtp', true);
update_option('kompass_smtp_host', sanitize_text_field(wp_unslash($_POST['smtp-host'])));
update_option('kompass_smtp_port', sanitize_text_field(wp_unslash($_POST['smtp-port'])));
update_option('kompass_smtp_user', sanitize_text_field(wp_unslash($_POST['smtp-user'])));
update_option('kompass_smtp_pass', sanitize_text_field(wp_unslash($_POST['smtp-pass'])));
update_option('kompass_smtp_sender', sanitize_text_field(wp_unslash($_POST['smtp-sender'])));
update_option('kompass_smtp_sender-name', sanitize_text_field(wp_unslash($_POST['smtp-sender-name'])));
kompass_print_message_box('Die Einstellungen wurden gespeichert.');
}
require BDP_LV_PLUGIN_DIR . '/settings/views/mail-settings.php';
}
}

View File

@ -36,7 +36,11 @@ class SaveRegistration {
wp_mail($user->user_email, 'Bitte bestätige deine Anmeldung', 'Hallo, bitte bestätige deine Anmeldung über den folgenden Link: ' . $activation_link);
// Notify admin
wp_mail(get_option('admin_email'), 'New User Registration', 'A new user has registered: ' . $user->user_login . PHP_EOL . 'First name:' . $user->first_name . PHP_EOL . 'Last name:' . $user->last_name );
wp_mail(get_option('admin_email'), 'New User Registration', 'A new user has registered: ' . PHP_EOL .
'Username: ' . $user->user_login . PHP_EOL .
'First name: ' . $user->first_name . PHP_EOL .
'Last name: ' . $user->last_name . PHP_EOL .
'E-Mail: ' . $user->user_email);
}
public static function activate_user() {
@ -72,5 +76,19 @@ class SaveRegistration {
<p style="font-size:16px; color:#00796b;">Vielen Dank für deine Registrierung. Bitte überprüfen deine E-Mails, um deine Registrierung zu bestätigen.</p>
</div>';
}
if ((isset($_GET['action']) && $_GET['action'] === 'laostpassword') ||
isset($_GET['checkemail']) && $_GET['checkemail'] === 'confirm'
){
echo '<div class="custom-message" style="text-align:center; margin:20px auto; padding:10px; background-color:#e0f7fa; border:1px solid #00796b; border-radius:5px; max-width:600px;">
<p style="font-size:16px; color:#00796b;">Insofern der Account existiert, hast du soeben weitere Anweisungen per E-Mail erhalten.</p>
</div>';
}
if (isset($_GET['action']) && $_GET['action'] === 'resetpass') {
echo '<div class="custom-message" style="text-align:center; margin:20px auto; padding:10px; background-color:#e0f7fa; border:1px solid #00796b; border-radius:5px; max-width:600px;">
<p style="font-size:16px; color:#00796b;">Dein Passwort wurde erfolgreich geändert.</p>
</div>';
}
}
}

View File

@ -0,0 +1,147 @@
<form action="<?php echo esc_url(admin_url('options-general.php?page=kompass-mail-settings')); ?>" method="post">
<input type="hidden" name="save" value="1">
<h2>E-Mail Einstellungen</h2>
<table>
<tr>
<td style="font-weight: bold; padding: 10px;">SMTP zum senden Verwenden</td>
<td>
<div class="switch-container">
<input name="use_smtp" <?php if (false !== (bool)get_option( 'kompass_use_smtp', false )) echo ' checked ';?> type="checkbox" id="use_smtp" class="switch">
<label for="use_smtp" class="switch-label">
<span class="switch-inner" data-on="ON" data-off="OFF"></span>
<span class="switch-switch"></span>
</label>
</div>
</td>
</tr>
</table>
<table id="smtp_settings" <?php if (false === (bool)get_option( 'kompass_use_smtp', false )) echo ' style="display: none;" ';?>>
<tr>
<td style="font-weight: bold; padding: 10px;">SMTP-Host</td>
<td>
<input style="width: 500px;" type="text" name="smtp-host" value="<?php echo esc_html(get_option('kompass_smtp_host', '')); ?>" /> :
<input style="width: 50px;" type="text" name="smtp-port" value="<?php echo esc_html(get_option('kompass_smtp_port', '25')); ?>" />
</td>
</tr>
<tr>
<td style="font-weight: bold; padding: 10px;">SMTP-User</td>
<td>
<input style="width: 562px;" type="text" name="smtp-user" value="<?php echo esc_html(get_option('kompass_smtp_user', '')); ?>" />
</td>
</tr>
<tr>
<td style="font-weight: bold; padding: 10px;">SMTP-Passwort</td>
<td>
<input style="width: 562px;" type="text" name="smtp-pass" value="<?php echo esc_html(get_option('kompass_smtp_pass', '')); ?>" />
</td>
</tr>
<tr>
<td style="font-weight: bold; padding: 10px;">SMTP-Sender email</td>
<td>
<input style="width: 562px;" type="text" name="smtp-sender" value="<?php echo esc_html(get_option('kompass_smtp_sender', '')); ?>" />
</td>
</tr>
<tr>
<td style="font-weight: bold; padding: 10px;">SMTP-Sender name</td>
<td>
<input style="width: 562px;" type="text" name="smtp-sender-name" value="<?php echo esc_html(get_option('kompass_smtp_sender-name', '')); ?>" />
</td>
</tr>
</table>
<br /><br />
<input type="submit" class="button-primary" value="Speichern">
</form>
<style>
.switch-container {
position: relative;
padding: 0;
}
.switch {
visibility: hidden; /* Checkbox unsichtbar machen */
}
.switch-label {
display: block;
width: 70px;
height: 34px;
background-color: #ccc;
border-radius: 34px;
position: relative;
cursor: pointer;
transition: background-color 0.3s ease;
}
.switch-inner {
position: absolute;
width: 100%;
height: 100%;
border-radius: 34px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
font-size: 12px;
color: white;
box-sizing: border-box;
transition: background-color 0.3s ease;
}
.switch-inner::before,
.switch-inner::after {
content: attr(data-off);
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.switch-inner::after {
content: attr(data-on);
right: 10px;
opacity: 0;
}
.switch-switch {
position: absolute;
top: 3px;
left: 3px;
width: 28px;
height: 28px;
background-color: #fff;
border-radius: 50%;
transition: transform 0.3s ease, background-color 0.3s ease;
}
.switch:checked + .switch-label {
background-color: #4CAF50;
}
.switch:checked + .switch-label .switch-inner::before {
opacity: 0;
}
.switch:checked + .switch-label .switch-inner::after {
opacity: 1;
}
.switch:checked + .switch-label .switch-switch {
transform: translateX(36px);
}
</style>
<script>
// script.js
document.getElementById('use_smtp').addEventListener('change', function() {
if (this.checked) {
document.getElementById('smtp_settings').style.display='block';
} else {
document.getElementById('smtp_settings').style.display='none';
}
});
</script>