Create a Post
API for sendConfirmationEmail
I would like to be able to invoke an API that resends a confirmation email to a user --- the same way I can do through the mailpoet subscribers page. The use case is a user subscribes to a newsletter, and tries to sign up again. Since they are an existing user I would like the ability to resend the confirmation email programmatically. I have made a patch that exposes sendConfirmationEmail as a published API. If you would integrate it everyone else could benefit and I wouldn't have to maintain it myself. diff --git a/mailpoet/lib/API/MP/v1/API.php b/mailpoet/lib/API/MP/v1/API.php index 04b14d2b9..d620f2d8a 100644 --- a/mailpoet/lib/API/MP/v1/API.php +++ b/mailpoet/lib/API/MP/v1/API.php @@ -100,6 +100,10 @@ class API { return $this->subscribers->getSubscribersCount($filter); } + public function sendConfirmationEmail($subscriberId) { + return $this->subscribers->sendConfirmationEmail($subscriberId); + } + public function isSetupComplete() { return !( $this->changelog->shouldShowWelcomeWizard() diff --git a/mailpoet/lib/API/MP/v1/Subscribers.php b/mailpoet/lib/API/MP/v1/Subscribers.php index 40230ecc3..4d0a99013 100644 --- a/mailpoet/lib/API/MP/v1/Subscribers.php +++ b/mailpoet/lib/API/MP/v1/Subscribers.php @@ -253,6 +253,30 @@ class Subscribers { return $this->subscriberListingRepository->getCount($listingDefinition); } + /** + * @throws APIException + */ + public function sendConfirmationEmail($subscriberId) { + $subscriber = $this->subscribersRepository->findOneById($subscriberId); + if ($subscriber instanceof SubscriberEntity) { + try { + if ($this->confirmationEmailMailer->sendConfirmationEmail($subscriber)) { + return; + } else { + throw new APIException( + sprintf(__('Confirmation email failed to send: %s', 'mailpoet'), + APIException::CONFIRMATION_FAILED_TO_SEND)); + } + } catch (\Exception $e) { + throw new APIException( + sprintf(__('Confirmation email failed to send: %s', 'mailpoet'), strtolower($e->getMessage())), + APIException::CONFIRMATION_FAILED_TO_SEND); + } + } else { + throw new APIException(__('The subscriber does not exist.', 'mailpoet'), APIException::SUBSCRIBER_NOT_EXISTS); + } + } + /** * @param array $filter { * Filters to retrieve subscribers.
Add more WP actions and filters
under review
Following WP actions would be great additions to integrate other plugins or custom logic: unconfirmed subscriber was created subscriber confirmed opt-in subscriber details updated subscriber was added to list subscriber was removed from list subscriber custom field was updated an email was sent to a subscriber subscriber opened an email subscriber clicked a link in an email And following WP filters that allow us to sanitize/modify content: save custom field value to DB get custom fields for manage-subscription-page (to allow us to sort/change labels or even remove fields from a form/page) newsletter full body rendered (like the filter "mailpoet_rendering_post_process", but after shortcodes were rendered, with $subscriber details) generate newsletter subject (allow us to customize the subject via a filter) ----- Note: Most of those actions aim towards the Automation feature-request and allows developers to customize the Subscriber workflow. The Filters allow us to customize the contents of the emails, based on user interaction. Sample use cases that I want to implement using those actions/filters: User opened an email but did not click the link: I want to add an extra sentence in the next email, via the filter. User was added to a list: I want to automatically generate a one-time-discount code for that user and store it in a custom field. The Manage-Subscription page should not display the custom field with the discount code, as the user is not allowed to change the value. User received two emails without opening them: I'd like to modify the email subject of the third email
Load More