> */ public const READERS = [WpMailSmtpReader::class, FluentSmtpReader::class]; /** * Delivery plugins without a reader yet (wordpress.org slugs, verified * 03.10.2026): when one is active the transport is not guessed. * * @var array */ public const OTHER_MAIL_PLUGINS = [ 'post-smtp', 'easy-wp-smtp', 'wp-smtp', 'smtp-mailer', 'gmail-smtp', 'mailgun', 'wp-ses', 'sendgrid-email-delivery-simplified', 'postmark-approved-wordpress-plugin', ]; /** * @param array|null $readers stand-ins in tests; null builds the real ones * @return array{plugin: array{slug: string, version: string, supported: bool}|null, transport: string|null, provider_configured: bool|null, errors_7d: int|null, sent_7d: int|null, logging_enabled: bool|null} */ public static function run(?array $readers = null, ?ReadBudget $budget = null): array { $budget = $budget ?? new ReadBudget(self::BUDGET_SECONDS); $readers = $readers ?? self::readers($budget); $empty = ['transport' => null, 'provider_configured' => null, 'errors_7d' => null, 'sent_7d' => null, 'logging_enabled' => null]; foreach ($readers as $reader) { if (! $reader->isActive()) { continue; } $version = $reader->version(); $supported = $version !== null && $reader->supports($version); $plugin = ['slug' => $reader->slug(), 'version' => $version ?? '0', 'supported' => $supported]; return ['plugin' => $plugin] + ($supported ? $reader->read() : $empty); } $other = self::activeOtherMailPlugin(); if ($other !== null) { return ['plugin' => $other + ['supported' => false]] + $empty; } if (self::wpMailOverridden()) { return ['plugin' => null] + $empty; } return ['plugin' => null, 'transport' => AbstractMailReader::TRANSPORT_PHP_MAIL, 'provider_configured' => false] + $empty; } /** * @return array */ public static function readers(ReadBudget $budget): array { return array_map(static function (string $class) use ($budget): MailReader { return new $class($budget); }, self::READERS); } /** * The first active delivery plugin from OTHER_MAIL_PLUGINS, with its * header version. * * @return array{slug: string, version: string}|null */ public static function activeOtherMailPlugin(): ?array { if (! function_exists('get_plugins') || ! function_exists('is_plugin_active')) { return null; } foreach ((array) get_plugins() as $file => $header) { $slug = strtolower(strpos($file, '/') !== false ? (string) strstr($file, '/', true) : (string) preg_replace('/\.php$/', '', $file)); if (in_array($slug, self::OTHER_MAIL_PLUGINS, true) && is_plugin_active($file)) { $version = is_array($header) && is_scalar($header['Version'] ?? null) ? substr(trim((string) $header['Version']), 0, 32) : ''; return ['slug' => $slug, 'version' => $version !== '' ? $version : '0']; } } return null; } /** * wp_mail() is pluggable: a theme, mu-plugin or host may replace it, * in which case the transport cannot be told from here. */ private static function wpMailOverridden(): bool { if (! function_exists('wp_mail')) { return false; } try { $file = (new \ReflectionFunction('wp_mail'))->getFileName(); } catch (\ReflectionException $exception) { return false; } return is_string($file) && substr(str_replace('\\', '/', $file), -24) !== 'wp-includes/pluggable.php'; } }