refactor: flatten src/AKSRT → src (drop theme-identifier dir)
Move all domain folders from src/AKSRT/{Domain} to src/{Domain}; remap
Composer PSR-4 "AKSRT\\": "src/"; update audit script + README + ADR
paths; remove dead tools/build-psr4-map.php (scanned deleted inc/classes).
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
namespace AKSRT\Settings;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class Mail {
|
||||
|
||||
/** 所有邮件事件类型常量 */
|
||||
public const EMAIL_EVENTS = [
|
||||
'reg_verify_link',
|
||||
'reg_verify_code',
|
||||
'reg_success',
|
||||
'password_reset',
|
||||
'change_code',
|
||||
'change_notice',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取邮件事件配置
|
||||
*
|
||||
* @param string $event 事件类型,留空返回全部
|
||||
* @return array
|
||||
*/
|
||||
public static function get_email_event_config(string $event = ''): array {
|
||||
$s = Settings::get_all();
|
||||
|
||||
$global = [
|
||||
'footer_text' => sanitize_text_field((string) ($s['email_footer_text'] ?? '')),
|
||||
'site_branding' => !isset($s['email_site_branding']) || !empty($s['email_site_branding']),
|
||||
'template_mode' => in_array($s['email_template_mode'] ?? 'plain', ['plain', 'html'], true)
|
||||
? ($s['email_template_mode'] ?? 'plain') : 'plain',
|
||||
];
|
||||
|
||||
if ($event === '') {
|
||||
$events = [];
|
||||
foreach (self::EMAIL_EVENTS as $ev) {
|
||||
$events[$ev] = self::build_email_event_entry($s, $ev);
|
||||
}
|
||||
return ['global' => $global, 'events' => $events];
|
||||
}
|
||||
|
||||
if (!in_array($event, self::EMAIL_EVENTS, true)) {
|
||||
return ['enabled' => true, 'subject' => '', 'content' => '', 'html' => false, 'global' => $global];
|
||||
}
|
||||
|
||||
return array_merge(self::build_email_event_entry($s, $event), ['global' => $global]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮件事件是否启用
|
||||
*/
|
||||
public static function is_email_event_enabled(string $event): bool {
|
||||
if (!in_array($event, self::EMAIL_EVENTS, true)) {
|
||||
return true;
|
||||
}
|
||||
$s = Settings::get_all();
|
||||
return !isset($s["email_{$event}_enabled"]) || !empty($s["email_{$event}_enabled"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过邮件事件体系发送邮件
|
||||
*/
|
||||
public static function send_event_email(
|
||||
string $event,
|
||||
string $to,
|
||||
string $default_subject,
|
||||
string $default_content,
|
||||
array $placeholders = []
|
||||
): bool {
|
||||
if (!self::is_email_event_enabled($event)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cfg = self::get_email_event_config($event);
|
||||
|
||||
$subject = ($cfg['subject'] !== '') ? $cfg['subject'] : $default_subject;
|
||||
$subject = strtr($subject, $placeholders);
|
||||
|
||||
$content = ($cfg['content'] !== '') ? $cfg['content'] : $default_content;
|
||||
$content = strtr($content, $placeholders);
|
||||
|
||||
$branding = Settings::get_mail_branding();
|
||||
$footer = $cfg['global']['footer_text'];
|
||||
if ($footer === '' && $branding['description'] !== '') {
|
||||
$footer = $branding['description'];
|
||||
}
|
||||
if ($footer === '') {
|
||||
$footer = get_bloginfo('name');
|
||||
}
|
||||
if ($footer !== '') {
|
||||
$content .= "\n\n— " . $footer;
|
||||
if ($branding['description'] !== '' && $footer !== $branding['description']) {
|
||||
$content .= "\n" . $branding['description'];
|
||||
}
|
||||
}
|
||||
|
||||
$is_html = $cfg['html'] || ($cfg['global']['template_mode'] === 'html');
|
||||
$headers = [$is_html ? 'Content-Type: text/html; charset=UTF-8' : 'Content-Type: text/plain; charset=UTF-8'];
|
||||
|
||||
return wp_mail($to, $subject, $content, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建单个邮件事件条目
|
||||
*/
|
||||
private static function build_email_event_entry(array $s, string $event): array {
|
||||
return [
|
||||
'enabled' => !isset($s["email_{$event}_enabled"]) || !empty($s["email_{$event}_enabled"]),
|
||||
'subject' => sanitize_text_field((string) ($s["email_{$event}_subject"] ?? '')),
|
||||
'content' => sanitize_textarea_field((string) ($s["email_{$event}_content"] ?? '')),
|
||||
'html' => !empty($s["email_{$event}_html"]),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user