Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Notifier | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| notify | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Notifier Class |
| 4 | * |
| 5 | * @package ChoctawNation\CNHSA_Federation |
| 6 | */ |
| 7 | |
| 8 | namespace ChoctawNation\CNHSA_Federation\WP; |
| 9 | |
| 10 | /** |
| 11 | * Class Notifier |
| 12 | * |
| 13 | * Handles sending notification emails to specified addresses. |
| 14 | */ |
| 15 | class Notifier { |
| 16 | /** |
| 17 | * Array of email addresses to notify. |
| 18 | * |
| 19 | * @var string[] $emails |
| 20 | */ |
| 21 | public array $emails; |
| 22 | |
| 23 | /** |
| 24 | * Constructor |
| 25 | * |
| 26 | * @param string|string[] $emails A single email address or an array of email addresses to notify. |
| 27 | */ |
| 28 | public function __construct( $emails = '' ) { |
| 29 | $emails = is_array( $emails ) ? $emails : array( $emails ); |
| 30 | $emails = array_filter( $emails, 'is_email' ); |
| 31 | $this->emails = array_unique( array( ...$emails, get_option( 'admin_email' ) ) ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Send a notification email to the configured email addresses. |
| 36 | * |
| 37 | * @param string $subject The subject of the email. |
| 38 | * @param string $message The body of the email. |
| 39 | */ |
| 40 | public function notify( $subject, $message ) { |
| 41 | wp_mail( $this->emails, esc_textarea( $subject ), esc_html( $message ) ); |
| 42 | } |
| 43 | } |