Skip to content

Commit

Permalink
Make it possible to only use SMTP for some sites in a multisite (#111)
Browse files Browse the repository at this point in the history
* make it possible to only use SMTP for some sites in a multisite

* change setting from string to array
  • Loading branch information
annlickander authored Sep 18, 2023
1 parent fbdab62 commit 7d6d16b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ configuration.
`BM_WP_SMTP_PASSWORD` - Define the SMTP e-mail account password to send through.
`BM_WP_SMTP_PORT` - Set which port the connection should be made through. Should be set as an integer. Defaults to `587`.
`BM_WP_SMTP_SECURITY` - Set the sending security for the SMTP server. Defaults to `tls`.
`BM_WP_SMTP_SITE_IDS` - Set side ids in an array to only use SMTP for some sites in a multisite. Defaults to work for all sites.

`BM_WP_POSTAL_DOMAIN` - Optionally customize the domain for the Postal install. Defaults to `https://postal.oderland.com`
`BM_WP_POSTAL_API_KEY` - Add the API key for the Postal service. Without it, Postal is not active.
Expand Down
21 changes: 21 additions & 0 deletions src/Modules/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public static function warn_improper_smtp_configuration(): void {
return;
}

if( ! self::should_send_for_this_site() ){
return;
}

if ( self::are_all_configs_set() ) {
return;
}
Expand All @@ -39,6 +43,7 @@ public static function warn_improper_smtp_configuration(): void {

public static function send_mail_via_smtp( PHPMailer $mailer ): void {

if( ! )
if ( ! self::should_send_via_smtp() ) {
return;
}
Expand All @@ -56,6 +61,22 @@ public static function send_mail_via_smtp( PHPMailer $mailer ): void {
$mailer->isSMTP();
}

protected static function should_send_for_this_site(): bool {
if( ! is_multisite() ){
return true;
}

if( ! defined( 'BM_WP_SMTP_SITE_IDS' ) ){
return true;
}

if( is_array( BM_WP_SMTP_SITE_IDS ) && in_array( get_current_blog_id(), BM_WP_SMTP_SITE_IDS ) ){
return true;
}

return false;
}

protected static function should_send_via_smtp(): bool {
if ( 'production' !== wp_get_environment_type() ) {
return self::should_send_smtp_outside_production();
Expand Down

0 comments on commit 7d6d16b

Please sign in to comment.