File: //wordpress/plugins/wp-cloud-client/1.1.5/src/Mail/MailSettings.php
<?php
declare(strict_types=1);
namespace VPlugins\WPCloudClient\Mail;
use VPlugins\WPCloudClient\Settings\SettingsRepository;
/**
* Exposes a settings toggle to disable the wp_mail interceptor.
*
* Administrators can turn this off when a third-party SMTP plugin (e.g.
* SendGrid, Mailgun, WP Mail SMTP) is already handling email delivery and the
* interception would interfere.
*
* Ported from wsp-bootstrapper: plugins/includes/wsp-mail-settings.php
*/
final class MailSettings {
private const SECTION = 'wpcc_section_mail';
private const SLUG = 'wpcc-settings';
private const OPTION_KEY = 'wpcc_settings';
/**
* Constructor.
*
* @param SettingsRepository $settings Settings repository instance.
*/
public function __construct(
private readonly SettingsRepository $settings,
) {}
/**
* Register the mail settings section and field.
*/
public function register(): void {
add_settings_section(
self::SECTION,
__( 'Email History', 'wp-cloud-client' ),
static fn () => printf(
'<p>%s</p>',
esc_html__(
'WP Cloud Client intercepts outgoing emails to provide an Email History log in the dashboard. Disable this if you are using a third-party SMTP plugin that should handle all mail delivery.',
'wp-cloud-client',
),
),
self::SLUG,
);
add_settings_field(
'disable_mail_interceptor',
__( 'Disable Email Interceptor', 'wp-cloud-client' ),
function (): void {
$checked = $this->isDisabled();
printf(
'<label><input type="checkbox" id="disable_mail_interceptor" name="%s[disable_mail_interceptor]" value="1" %s /> %s</label>',
esc_attr( self::OPTION_KEY ),
checked( $checked, true, false ),
esc_html__( 'Disable email interception (Email History will not be available)', 'wp-cloud-client' ),
);
},
self::SLUG,
self::SECTION,
);
}
/**
* Whether the mail interceptor has been disabled in settings.
*
* @return bool
*/
public function isDisabled(): bool {
return (bool) ( $this->settings->all()['disable_mail_interceptor'] ?? false );
}
/**
* Sanitize the disable_mail_interceptor checkbox value.
* Called from SettingsPage::sanitize() before saving.
*
* @param mixed $input Raw form input.
* @return string '1' if checked, '' otherwise.
*/
public function sanitizeField( mixed $input ): string {
return ! empty( $input['disable_mail_interceptor'] ) ? '1' : '';
}
}