update_checker->get_update_count($updates);
if ($update_count === 0) {
return false;
}
$recipients = $this->get_recipient_emails($settings);
if (empty($recipients)) {
return false;
}
$subject = $this->get_email_subject($updates);
$message = $this->get_email_message($updates);
$headers = array(
'Content-Type: text/html; charset=UTF-8',
'From: ' . get_bloginfo('name') . ' <' . get_option('admin_email') . '>'
);
$success = true;
foreach ($recipients as $recipient) {
if (!wp_mail($recipient, $subject, $message, $headers)) {
$success = false;
}
}
return $success;
}
public function send_update_completion_notification($options) {
$settings = get_option('backhe_yis_settings', array());
if (empty($settings['email_enabled']) || $settings['email_enabled'] !== '1') {
return false;
}
$recipients = $this->get_recipient_emails($settings);
if (empty($recipients)) {
return false;
}
$type = $options['type'] ?? 'unknown';
$action = $options['action'] ?? 'unknown';
$updates_info = array();
if ($type === 'plugin' && isset($options['plugins'])) {
foreach ($options['plugins'] as $plugin) {
$plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin, false);
$updates_info[] = array(
'type' => 'Plugin',
'name' => $plugin_data['Name'],
'version' => $plugin_data['Version']
);
}
} elseif ($type === 'theme' && isset($options['themes'])) {
foreach ($options['themes'] as $theme) {
$theme_data = wp_get_theme($theme);
$updates_info[] = array(
'type' => 'Theme',
'name' => $theme_data->get('Name'),
'version' => $theme_data->get('Version')
);
}
} elseif ($type === 'core') {
$updates_info[] = array(
'type' => 'WordPress Core',
'name' => 'WordPress',
'version' => get_bloginfo('version')
);
}
if (empty($updates_info)) {
return false;
}
$subject = '[' . get_bloginfo('name') . '] ' . __('Updates erfolgreich installiert', 'admin-backend-and-update-helper');
$message = $this->get_update_completion_message($updates_info);
$headers = array(
'Content-Type: text/html; charset=UTF-8',
'From: ' . get_bloginfo('name') . ' <' . get_option('admin_email') . '>'
);
$success = true;
foreach ($recipients as $recipient) {
if (!wp_mail($recipient, $subject, $message, $headers)) {
$success = false;
}
}
return $success;
}
private function get_update_completion_message($updates_info) {
$site_name = get_bloginfo('name');
$site_url = home_url();
$html = '
✅ Updates erfolgreich installiert
' . esc_html($site_name) . '
|
🎉 ' . count($updates_info) . ' ' . _n('Update wurde', 'Updates wurden', count($updates_info), 'admin-backend-and-update-helper') . ' installiert
Die folgenden Komponenten wurden erfolgreich aktualisiert:
| Typ |
Name |
Version |
';
foreach ($updates_info as $update) {
$html .= '
| ' . esc_html($update['type']) . ' |
' . esc_html($update['name']) . ' |
' . esc_html($update['version']) . ' |
';
}
$html .= '
|
|
Admin Backend and Update Helper by YIS Media v' . backhe_yis_VERSION . '
Website: ' . esc_html($site_name) . '
Gesendet am: ' . date_i18n('d.m.Y H:i:s', current_time('timestamp')) . '
|
|
';
return $html;
}
public function get_recipient_emails($settings) {
$recipients = array();
$recipient_type = isset($settings['recipient_type']) ? $settings['recipient_type'] : 'admin';
switch ($recipient_type) {
case 'user':
$user_id = isset($settings['selected_user']) ? absint($settings['selected_user']) : 0;
if ($user_id > 0) {
$user = get_userdata($user_id);
if ($user) {
$recipients[] = $user->user_email;
}
}
break;
case 'custom':
$custom_email = isset($settings['custom_email']) ? sanitize_email($settings['custom_email']) : '';
if (!empty($custom_email) && is_email($custom_email)) {
$recipients[] = $custom_email;
}
$custom_email_2 = isset($settings['custom_email_2']) ? sanitize_email($settings['custom_email_2']) : '';
if (!empty($custom_email_2) && is_email($custom_email_2)) {
$recipients[] = $custom_email_2;
}
break;
case 'admin':
default:
$recipients[] = get_option('admin_email');
break;
}
return array_filter($recipients);
}
public function get_email_subject($updates) {
$plugin = Backhe_YIS_Media::get_instance();
$update_count = $plugin->update_checker->get_update_count($updates);
return sprintf(
'[%s] %d %s verfügbar',
get_bloginfo('name'),
$update_count,
_n('Update', 'Updates', $update_count, 'admin-backend-and-update-helper')
);
}
public function get_email_message($updates) {
$plugin = Backhe_YIS_Media::get_instance();
$update_count = $plugin->update_checker->get_update_count($updates);
$site_name = get_bloginfo('name');
$site_url = home_url();
$admin_url = admin_url('update-core.php');
$html = '
🔄 Update-Benachrichtigung
' . esc_html($site_name) . '
|
⚠️ ' . $update_count . ' ' . _n('Update', 'Updates', $update_count, 'admin-backend-and-update-helper') . ' verfügbar
Es ' . ($update_count === 1 ? 'ist' : 'sind') . ' neue Updates für deine WordPress-Website verfügbar.
';
// Core Updates
if (!empty($updates['core']) && count($updates['core']) > 0) {
$html .= '
🌐 WordPress Core (' . count($updates['core']) . ')
| Aktuelle Version |
Neue Version |
';
foreach ($updates['core'] as $core) {
$html .= '
| ' . esc_html($core['current_version']) . ' |
→ ' . esc_html($core['new_version']) . ' |
';
}
$html .= '
';
}
// Plugin Updates
if (!empty($updates['plugins']) && count($updates['plugins']) > 0) {
$html .= '
🔌 Plugins (' . count($updates['plugins']) . ')
| Plugin Name |
Aktuell |
Neu |
';
foreach ($updates['plugins'] as $plugin_update) {
$html .= '
| ' . esc_html($plugin_update['name']) . ' |
' . esc_html($plugin_update['current_version']) . ' |
→ ' . esc_html($plugin_update['new_version']) . ' |
';
}
$html .= '
';
}
// Theme Updates
if (!empty($updates['themes']) && count($updates['themes']) > 0) {
$html .= '
🎨 Themes (' . count($updates['themes']) . ')
| Theme Name |
Aktuell |
Neu |
';
foreach ($updates['themes'] as $theme) {
$html .= '
| ' . esc_html($theme['name']) . ' |
' . esc_html($theme['current_version']) . ' |
→ ' . esc_html($theme['new_version']) . ' |
';
}
$html .= '
';
}
// Translation Updates
if (!empty($updates['translations']) && count($updates['translations']) > 0) {
$html .= '
🌍 Übersetzungen (' . count($updates['translations']) . ')
' . count($updates['translations']) . ' ' . _n('Übersetzungsdatei', 'Übersetzungsdateien', count($updates['translations']), 'admin-backend-and-update-helper') . ' verfügbar
';
}
$html .= '
|
|
Diese E-Mail wurde automatisch von Admin Backend and Update Helper by YIS Media generiert
Website: ' . esc_html($site_name) . '
Gesendet am: ' . date_i18n('d.m.Y H:i:s', current_time('timestamp')) . '
|
|
';
return $html;
}
public function send_test_email($recipient, $recipient_2 = '') {
$recipients = array_filter(array($recipient, $recipient_2));
if (empty($recipients)) {
return false;
}
$site_name = get_bloginfo('name');
$subject = '[' . $site_name . '] Test-E-Mail von Admin Backend and Update Helper';
$message = '
✅ Test-E-Mail erfolgreich!
' . esc_html($site_name) . '
|
|
Hallo!
Dies ist eine Test-E-Mail von Admin Backend and Update Helper by YIS Media.
Wenn du diese E-Mail erhältst, funktioniert die E-Mail-Benachrichtigung korrekt! 🎉
✓ E-Mail-Konfiguration: Funktioniert einwandfrei
✓ Empfänger: ' . esc_html(implode(', ', $recipients)) . '
✓ Absender: ' . esc_html(get_option('admin_email')) . '
Du wirst ab jetzt automatisch benachrichtigt, wenn Updates für deine WordPress-Website verfügbar sind.
|
|
Admin Backend and Update Helper by YIS Media v' . backhe_yis_VERSION . '
Gesendet am: ' . date_i18n('d.m.Y H:i:s', current_time('timestamp')) . '
|
|
';
$headers = array(
'Content-Type: text/html; charset=UTF-8',
'From: ' . get_bloginfo('name') . ' <' . get_option('admin_email') . '>'
);
$success = true;
foreach ($recipients as $email) {
if (!wp_mail($email, $subject, $message, $headers)) {
$success = false;
}
}
return $success;
}
}