| @@ -1,65 +1,67 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * Emailer Class | |
| 5 | - */ | |
| 6 | -class WeForms_Emailer { | |
| 7 | - | |
| 8 | - /** | |
| 9 | - * The default gateway to send | |
| 10 | - * | |
| 11 | - * @var WeForms_Mailer_Contract|null | |
| 12 | - */ | |
| 13 | - private $gateway = null; | |
| 14 | - | |
| 15 | - public function __construct() { | |
| 16 | - require_once WEFORMS_INCLUDES . '/email/gateways/interface-mailer.php'; | |
| 17 | - | |
| 18 | - $this->gateway = $this->get_sending_gateway(); | |
| 19 | - } | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * Get available gateways | |
| 23 | - * | |
| 24 | - * @return array | |
| 25 | - */ | |
| 26 | - public function get_available_gateways() { | |
| 27 | - require_once WEFORMS_INCLUDES . '/email/gateways/class-emailer-wpmail.php'; | |
| 28 | - | |
| 29 | - $gateways = apply_filters( 'weforms_email_gateways', [ | |
| 30 | - 'wordpress' => new WeForms_Emailer_WPMail(), | |
| 31 | - ] ); | |
| 32 | - | |
| 33 | - return $gateways; | |
| 34 | - } | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * Get the sending gateway class | |
| 38 | - * | |
| 39 | - * @return WeForms_Mailer_Contract | |
| 40 | - */ | |
| 41 | - public function get_sending_gateway() { | |
| 42 | - $gateway = weforms_get_settings( 'email_gateway', 'WordPress' ); | |
| 43 | - $available_gateways = $this->get_available_gateways(); | |
| 44 | - | |
| 45 | - if ( array_key_exists( $gateway, $available_gateways ) ) { | |
| 46 | - return $available_gateways[ $gateway ]; | |
| 47 | - } | |
| 48 | - | |
| 49 | - return $available_gateways['wordpress']; | |
| 50 | - } | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * Send email via the gateway | |
| 54 | - * | |
| 55 | - * @param string $to Email addresses to send message | |
| 56 | - * @param string $subject Email subject | |
| 57 | - * @param string $body Message contents | |
| 58 | - * @param string $headers Optional. Files to attach. | |
| 59 | - * | |
| 60 | - * @return bool | |
| 61 | - */ | |
| 62 | - public function send( $to, $subject, $body, $headers ) { | |
| 63 | - return $this->gateway->send( $to, $subject, $body, $headers ); | |
| 64 | - } | |
| 65 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Emailer Class | |
| 5 | + */ | |
| 6 | +class WeForms_Emailer { | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * The default gateway to send | |
| 10 | + * | |
| 11 | + * @var null|WeForms_Mailer_Contract | |
| 12 | + */ | |
| 13 | + private $gateway = null; | |
| 14 | + | |
| 15 | + function __construct() { | |
| 16 | + | |
| 17 | + require_once WEFORMS_INCLUDES . '/email/gateways/interface-mailer.php'; | |
| 18 | + | |
| 19 | + $this->gateway = $this->get_sending_gateway(); | |
| 20 | + } | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * Get available gateways | |
| 24 | + * | |
| 25 | + * @return array | |
| 26 | + */ | |
| 27 | + public function get_available_gateways() { | |
| 28 | + require_once WEFORMS_INCLUDES . '/email/gateways/class-emailer-wpmail.php'; | |
| 29 | + | |
| 30 | + $gateways = apply_filters( 'weforms_email_gateways', array( | |
| 31 | + 'wordpress' => new WeForms_Emailer_WPMail() | |
| 32 | + ) ); | |
| 33 | + | |
| 34 | + return $gateways; | |
| 35 | + } | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * Get the sending gateway class | |
| 39 | + * | |
| 40 | + * @return WeForms_Mailer_Contract | |
| 41 | + */ | |
| 42 | + public function get_sending_gateway() { | |
| 43 | + $gateway = weforms_get_settings( 'email_gateway', 'wordpress' ); | |
| 44 | + $available_gateways = $this->get_available_gateways(); | |
| 45 | + | |
| 46 | + if ( array_key_exists( $gateway, $available_gateways ) ) { | |
| 47 | + return $available_gateways[ $gateway ]; | |
| 48 | + } | |
| 49 | + | |
| 50 | + return $available_gateways['wordpress']; | |
| 51 | + } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * Send email via the gateway | |
| 55 | + * | |
| 56 | + * @param string $to Email addresses to send message | |
| 57 | + * @param string $subject Email subject | |
| 58 | + * @param string $body Message contents | |
| 59 | + * @param string $headers Optional. Files to attach. | |
| 60 | + * | |
| 61 | + * @return bool | |
| 62 | + */ | |
| 63 | + public function send( $to, $subject, $body, $headers ) { | |
| 64 | + return $this->gateway->send( $to, $subject, $body, $headers ); | |
| 65 | + } | |
| 66 | + | |
| 67 | +} | |