Server IP : 104.21.14.48 / Your IP : 18.119.159.204 [ Web Server : Apache System : Linux b70eb322-3aee-0c53-7c82-0db91281f2c6.secureserver.net 6.1.90-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 2 12:09:22 EDT 2024 x86_64 User : root ( 0) PHP Version : 8.0.30.2 Disable Function : NONE Domains : 0 Domains MySQL : ON | cURL : ON | WGET : ON | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/wp-content/mu-plugins/vendor/godaddy/mwc-core/src/Email/ |
Upload File : |
<?php namespace GoDaddy\WordPress\MWC\Core\Email; use Exception; use GoDaddy\WordPress\MWC\Common\Components\Contracts\ConditionalComponentContract; use GoDaddy\WordPress\MWC\Common\Email\Contracts\EmailContract; use GoDaddy\WordPress\MWC\Common\Email\Contracts\EmailServiceContract; use GoDaddy\WordPress\MWC\Common\Email\Exceptions\EmailSendFailedException; use GoDaddy\WordPress\MWC\Common\Traits\CanGetNewInstanceTrait; use GoDaddy\WordPress\MWC\Core\Email\DataSources\Adapters\ScheduledEmailAdapter; use GoDaddy\WordPress\MWC\Core\Email\Http\EmailsServiceRequest; use GoDaddy\WordPress\MWC\Core\Email\Http\GraphQL\Mutations\CreateScheduledEmailMutation; use GoDaddy\WordPress\MWC\Core\Email\Models\EmailSender; use GoDaddy\WordPress\MWC\Core\Features\EmailNotifications\Contracts\RenderableEmailContract; use GoDaddy\WordPress\MWC\Core\Features\EmailNotifications\EmailNotifications; class EmailService implements EmailServiceContract, ConditionalComponentContract { use CanGetNewInstanceTrait; /** @var bool whether we can use this email service */ protected static $enabled = true; /** * Determines whether the email service can be used. * * @return bool */ public static function shouldLoad() : bool { return static::$enabled && static::isSenderAddressVerified(); } /** * Determines whether the configured sender address is verified. * * @return bool */ protected static function isSenderAddressVerified() : bool { if (! $emailAddress = EmailNotifications::getSenderAddress()) { return false; } return static::isEmailAddressVerified($emailAddress); } /** * Determines whether the given email address is verified. * * @param string $emailAddress email address to verify * @return bool */ protected static function isEmailAddressVerified(string $emailAddress) : bool { $emailSender = EmailSender::get($emailAddress); return $emailSender && $emailSender->isVerified(); } /** * Initializes the email service. */ public function load() { // TODO: Implement load() method. } /** * Sends an email. * * @param EmailContract $email * @throws EmailSendFailedException */ public function send(EmailContract $email) { if (! $email instanceof RenderableEmailContract) { throw new EmailSendFailedException(sprintf( '%1$s does not support sending an email of the class %2$s.', static::class, get_class($email) )); } $this->sendEmail($email); } /** * Sends an email using our emails service. * * @param RenderableEmailContract $email * @throws EmailSendFailedException */ protected function sendEmail(RenderableEmailContract $email) { try { $response = $this->buildRequest($email)->send(); } catch (Exception $exception) { throw new EmailSendFailedException($exception->getMessage(), $exception); } if ($response->isError()) { throw new EmailSendFailedException((string) $response->getErrorMessage()); } } /** * Prepares a GraphQL request object from the given email. * * @param RenderableEmailContract $email * @return EmailsServiceRequest * @throws Exception */ protected function buildRequest(RenderableEmailContract $email) : EmailsServiceRequest { return (new EmailsServiceRequest())->setOperation($this->buildMutation($email)); } /** * Prepares a {@see CreateScheduledEmailMutation} from the given email. * * @param RenderableEmailContract $email * @return CreateScheduledEmailMutation * @throws Exception */ protected function buildMutation(RenderableEmailContract $email) : CreateScheduledEmailMutation { return (new CreateScheduledEmailMutation())->setVariables([ 'input' => ScheduledEmailAdapter::getNewInstance($email)->convertFromSource(), ]); } }