Abilities
5 days ago
Admin
5 days ago
Compatibility
5 days ago
Helpers
5 days ago
Integrations
5 days ago
Providers
5 days ago
Queue
5 days ago
Reports
5 days ago
Tasks
5 days ago
TestEmail
5 days ago
UsageTracking
5 days ago
WPCLI
5 days ago
AbstractConnection.php
5 days ago
Conflicts.php
5 days ago
Connect.php
5 days ago
Connection.php
5 days ago
ConnectionInterface.php
5 days ago
ConnectionsManager.php
5 days ago
Core.php
5 days ago
DBRepair.php
5 days ago
Debug.php
5 days ago
EmailSendingDebug.php
5 days ago
Geo.php
5 days ago
MailCatcher.php
5 days ago
MailCatcherInterface.php
5 days ago
MailCatcherTrait.php
5 days ago
MailCatcherV6.php
5 days ago
Migration.php
5 days ago
MigrationAbstract.php
5 days ago
Migrations.php
5 days ago
OptimizedEmailSending.php
5 days ago
Options.php
5 days ago
Processor.php
5 days ago
SiteHealth.php
5 days ago
Upgrade.php
5 days ago
Uploads.php
5 days ago
WP.php
5 days ago
WPMailArgs.php
5 days ago
WPMailInitiator.php
5 days ago
OptimizedEmailSending.php
60 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPMailSMTP; |
| 4 | |
| 5 | /** |
| 6 | * OptimizedEmailSending class. |
| 7 | * |
| 8 | * @since 4.0.0 |
| 9 | */ |
| 10 | class OptimizedEmailSending { |
| 11 | |
| 12 | /** |
| 13 | * The slug of the option that toggles optimized email sending. |
| 14 | * |
| 15 | * @since 4.0.0 |
| 16 | */ |
| 17 | const SETTINGS_SLUG = 'optimize_email_sending_enabled'; |
| 18 | |
| 19 | /** |
| 20 | * Register hooks. |
| 21 | * |
| 22 | * @since 4.0.0 |
| 23 | */ |
| 24 | public function hooks() { |
| 25 | |
| 26 | if ( self::is_enabled() ) { |
| 27 | // Enable the queue. |
| 28 | add_filter( 'wp_mail_smtp_queue_is_enabled', '__return_true' ); |
| 29 | |
| 30 | // Avoid enqueueing emails if current request |
| 31 | // is a cron request, a CLI request, |
| 32 | // or an ActionScheduler task as 3rd party plugins might |
| 33 | // be carrying out their own sending optimizations |
| 34 | // through it. |
| 35 | if ( |
| 36 | ! ( defined( 'WP_CLI' ) && WP_CLI ) && |
| 37 | ! wp_doing_cron() && |
| 38 | ! doing_action( 'action_scheduler_run_queue' ) |
| 39 | ) { |
| 40 | // Start enqueueing emails. |
| 41 | add_filter( 'wp_mail_smtp_mail_catcher_send_enqueue_email', '__return_true' ); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Whether optimized email sending is enabled. |
| 48 | * |
| 49 | * @since 4.0.0 |
| 50 | * |
| 51 | * @return bool |
| 52 | */ |
| 53 | public static function is_enabled() { |
| 54 | |
| 55 | $value = Options::init()->get( 'general', self::SETTINGS_SLUG ); |
| 56 | |
| 57 | return (bool) $value; |
| 58 | } |
| 59 | } |
| 60 |