diff --git a/src/Abstracts/ConditionInterface.php b/src/Abstracts/ConditionInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..46cbf9fc2e3fe3d72fc3073f3a0aef212e7f37f6 --- /dev/null +++ b/src/Abstracts/ConditionInterface.php @@ -0,0 +1,12 @@ +<?php + +namespace WPDesk\Library\WPEmail\Abstracts; + +use WPDesk\View\Renderer\Renderer; + +interface ConditionInterface { + + + public function is_valid(): bool; + +} diff --git a/src/Abstracts/EmailGettersAbstract.php b/src/Abstracts/EmailGettersAbstract.php index a51023455d273efdfeace4a03112ac63659c7962..2c1fc7ad25fa875a13e6152a8242e1fb01e576f4 100644 --- a/src/Abstracts/EmailGettersAbstract.php +++ b/src/Abstracts/EmailGettersAbstract.php @@ -4,7 +4,7 @@ namespace WPDesk\Library\WPEmail\Abstracts; use WPDesk\View\Renderer\Renderer; -abstract class EmailGettersAbstract implements EmailGettersInterface, EmailSettersInterface { +abstract class EmailGettersAbstract implements EmailGettersInterface, ConditionInterface { /** * @var Renderer @@ -142,4 +142,8 @@ abstract class EmailGettersAbstract implements EmailGettersInterface, EmailSette return $this->renderer->render( dirname( __DIR__ ) . '/html/default.php', [ 'content' => $this->get_content(), 'heading' => $this->get_heading(), 'object' => $this->get_object() ] ); } + public function is_valid(): bool { + return true; + } + } diff --git a/src/EmailSender.php b/src/EmailSender.php index 2f5ea7615e310ce745548534afa2f2381aea5a7c..3511483f3931d8cffef79e4b08ddc8643cb6f5c5 100644 --- a/src/EmailSender.php +++ b/src/EmailSender.php @@ -2,6 +2,7 @@ namespace WPDesk\Library\WPEmail\Emails; +use WPDesk\Library\WPEmail\Abstracts\ConditionInterface; use WPDesk\Library\WPEmail\Abstracts\EmailGettersInterface; class EmailSender { @@ -81,9 +82,15 @@ class EmailSender { public function send() { foreach ( $this->get_emails() as $email ) { $this->before_wp_mail(); - wp_mail( - $email->get_recipients(), $email->get_subject(), $email->render(), $email->get_headers(), $email->get_attachments() - ); + + if( $email instanceof ConditionInterface ) { + if( $email->is_valid() ) { + wp_mail( + $email->get_recipients(), $email->get_subject(), $email->render(), $email->get_headers(), $email->get_attachments() + ); + } + } + $this->after_wp_mail(); } }