Example #1
0
 /**
  * Send a comment a notification when their comment is rejected.
  *
  * This could be due to a deleted post, change in post status, or comments being closed.
  *
  * @param $user_id
  * @param $post_id
  */
 public static function send_rejected_notification($user_id, $post_id)
 {
     $comment_author = get_userdata($user_id);
     $post = get_post($post_id);
     $post_title = $post ? $post->post_title : __('a deleted post', 'Postmatic');
     $template_data = compact('comment_author', 'post', 'post_title');
     /**
      * Filter comment rejected email template data.
      *
      * @param array $template_data {
      *      @type WP_User $comment_author
      *      @type WP_Post $post
      *      @type string $post_title Post title or placeholder if post no longer exists
      * }
      */
     $template_data = apply_filters('prompt/comment_rejected_email/template_data', $template_data);
     $subject = sprintf(__('Unable to publish your reply to "%s"', 'Postmatic'), $post_title);
     $template = new Prompt_Template('comment-rejected-email.php');
     $batch = Prompt_Email_Batch::make_for_single_recipient(array('to_address' => $comment_author->user_email, 'subject' => $subject, 'html_content' => $template->render($template_data), 'message_type' => Prompt_Enum_Message_Types::ADMIN));
     /**
      * Filter comment rejected email.
      *
      * @param Prompt_Email_Batch $batch
      * @param array $template_data see prompt/comment_reject_email/template_data
      */
     $batch = apply_filters('prompt/comment_rejected_batch', $batch, $template_data);
     Prompt_Factory::make_mailer($batch)->send();
 }
 /**
  * @since 1.0.0
  */
 public function form_handler()
 {
     if (!empty($_POST['stylify_button'])) {
         $status = $this->stylify->refresh();
         $message = is_wp_error($status) ? $status->get_error_message() : __('Colors updated.', 'Postmatic');
         $class = is_wp_error($status) ? 'error' : 'updated';
         Prompt_Core::$options->set('site_styles', $this->stylify->get_styles());
         $this->add_notice($message, $class);
         return;
     }
     if (!empty($_POST['reset_site_styles_button'])) {
         Prompt_Core::$options->set('site_styles', array());
         $this->stylify = new Prompt_Stylify(array());
         $this->add_notice(__('Colors set to defaults.', 'Postmatic'));
         return;
     }
     if (!empty($_POST['send_test_email_button'])) {
         $to_address = sanitize_email($_POST['test_email_address']);
         if (!is_email($to_address)) {
             $this->add_notice(__('Test email was <strong>not sent</strong> to an invalid address.', 'Postmatic'), 'error');
             return;
         }
         $html_template = new Prompt_Template('test-email.php');
         $footnote = __('This is a test email sent by Postmatic. It is solely for demonstrating the Postmatic template and is not replyable. Also, that is not latin. <a href="https://en.wikipedia.org/wiki/Lorem_ipsum">It is Lorem ipsum</a>.', 'Postmatic');
         $batch = new Prompt_Email_Batch(array('subject' => __('This is a test email. By Postmatic.', 'Postmatic'), 'html_content' => $html_template->render(), 'message_type' => Prompt_Enum_Message_Types::ADMIN, 'footnote_html' => $footnote, 'footnote_text' => $footnote));
         $batch->add_individual_message_values(array('to_address' => $to_address));
         if (!is_wp_error(Prompt_Factory::make_mailer($batch)->send())) {
             $this->add_notice(__('Test email <strong>sent</strong>.', 'Postmatic'));
             return;
         }
     }
     parent::form_handler();
 }
Example #3
0
 /**
  * Send an email to a user who has had an account created for them.
  *
  * @param int|object $user
  * @param string $password
  * @param Prompt_Template $template
  */
 public static function send_new_user_notification($user, $password, $template)
 {
     $user = is_integer($user) ? get_userdata($user) : $user;
     $template_data = compact('user', 'password');
     /**
      * Filter new user email template data.
      *
      * @param array $template_data {
      * @type WP_User $user
      * @type string $password
      * }
      */
     $template_data = apply_filters('prompt/new_user_email/template_data', $template_data);
     $subject = sprintf(__('Welcome to %s', 'Postmatic'), get_option('blogname'));
     $batch = Prompt_Email_Batch::make_for_single_recipient(array('to_address' => $user->user_email, 'from_address' => get_option('admin_email'), 'subject' => $subject, 'html_content' => $template->render($template_data), 'message_type' => Prompt_Enum_Message_Types::ADMIN));
     /**
      * Filter new user email.
      *
      * @param Prompt_Email_Batch $batch
      * @param array $template_data {
      * @type WP_User $user
      * @type string $password
      * }
      */
     $batch = apply_filters('prompt/new_user_batch', $batch, $template_data);
     Prompt_Factory::make_mailer($batch)->send();
 }
Example #4
0
 /**
  * Schedule a retry if a temporary failure has occurred.
  *
  * @since 2.0.0
  *
  * @param array $response
  * @return bool Whether a retry has been rescheduled.
  */
 protected function reschedule($response)
 {
     $rescheduler = Prompt_Factory::make_rescheduler($response, $this->retry_wait_seconds);
     if ($rescheduler->found_temporary_error()) {
         $rescheduler->reschedule('prompt/post_mailing/send_notifications', array($this->batch->get_context()->get_post()->id(), 'reschedule'));
         return true;
     }
     return false;
 }
 /**
  * Schedule a retry if a temporary failure has occurred.
  *
  * @since 2.0.0
  *
  * @param array $response
  * @return bool Whether a retry has been rescheduled.
  */
 protected function reschedule($response)
 {
     $rescheduler = Prompt_Factory::make_rescheduler($response, $this->retry_wait_seconds);
     if ($rescheduler->found_temporary_error()) {
         $rescheduler->reschedule('prompt/subscription_mailing/send_agreements', array($this->batch->get_lists(), $this->batch->get_users_data(), $this->batch->get_message_data(), 0));
         return true;
     }
     return false;
 }
Example #6
0
 /**
  * Schedule a retry if a temporary failure has occurred.
  *
  * @since 2.0.0
  *
  * @param array $response
  * @return bool Whether a retry has been rescheduled.
  */
 protected function reschedule($response)
 {
     $rescheduler = Prompt_Factory::make_rescheduler($response, $this->retry_wait_seconds);
     if ($rescheduler->found_temporary_error()) {
         $this->batch->clear_for_retry();
         $rescheduler->reschedule('prompt/comment_mailing/send_notifications', array($this->comment->comment_ID, 'rescheduled', null));
         return true;
     }
     return false;
 }
 public function form_handler()
 {
     $environment = new Prompt_Environment();
     $user = wp_get_current_user();
     $email = Prompt_Email_Batch::make_for_single_recipient(array('to_address' => Prompt_Core::SUPPORT_EMAIL, 'from_address' => $user->user_email, 'from_name' => $user->display_name, 'subject' => sprintf(__('Diagnostics from %s', 'Postmatic'), html_entity_decode(get_option('blogname'))), 'html_content' => json_encode($environment->to_array()), 'message_type' => Prompt_Enum_Message_Types::ADMIN));
     $sent = Prompt_Factory::make_mailer($email)->send();
     if (is_wp_error($sent)) {
         Prompt_Logging::add_error('diagnostic_submission_error', __('Diagnostics could not be sent, please try a bug report.', 'Postmatic'), $sent);
         return;
     }
     $this->add_notice(__('Diagnostics <strong>sent</strong>.', 'Postmatic'));
 }
 protected function jetpack_import_content()
 {
     $jetpack_import = Prompt_Factory::make_jetpack_import();
     $jetpack_import->execute();
     $content = $jetpack_import->get_error() ? $jetpack_import->get_error()->get_error_message() : '';
     $results_format = _n('We have imported one subscriber. It is now safe to disable Jetpack commenting and subscriptions.', 'Imported %1$s subscribers. It is now safe to disable Jetpack commenting and subscriptions.', $jetpack_import->get_imported_count(), 'Postmatic');
     if ($jetpack_import->get_already_subscribed_count() > 0) {
         $results_format .= ' ' . _n('The one user we found was already subscribed.', 'The %2$s users we found were already subscribed.', $jetpack_import->get_already_subscribed_count(), 'Postmatic');
     }
     $content .= ' ' . sprintf($results_format, $jetpack_import->get_imported_count(), $jetpack_import->get_already_subscribed_count());
     return $content;
 }
Example #9
0
 /**
  * Make a reschedulable request to acknowledge updates.
  *
  * @since 1.3.0
  *
  * @param array $updates Array as returned by pull_updates
  * @param int $retry_wait_seconds Optional. One second default as this is a time-sensitive request.
  * @return bool|WP_Error status
  */
 public static function acknowledge_updates($updates, $retry_wait_seconds = 1)
 {
     $messenger = Prompt_Factory::make_inbound_messenger();
     $result = $messenger->acknowledge_updates($updates);
     $rescheduler = new Prompt_Rescheduler($result, $retry_wait_seconds);
     if ($rescheduler->found_temporary_error()) {
         $rescheduler->reschedule('prompt/inbound_handling/acknowledge_updates', array($updates));
         return $result;
     }
     if (is_wp_error($result)) {
         Prompt_Logging::add_wp_error($result);
     }
     return $result;
 }
Example #10
0
 /**
  * Report new errors.
  *
  * @since 2.0.0
  */
 public static function submit()
 {
     $user = wp_get_current_user();
     $last_submit_time = self::get_last_submission_time();
     update_option(self::$last_submit_option_name, time(), $autoload = false);
     $message = array('error_log' => self::get_log($last_submit_time, ARRAY_A));
     $environment = new Prompt_Environment();
     $message = array_merge($message, $environment->to_array());
     $email = Prompt_Email_Batch::make_for_single_recipient(array('to_address' => Prompt_Core::SUPPORT_EMAIL, 'from_address' => $user->exists() ? $user->user_email : get_option('admin_email'), 'from_name' => $user->exists() ? $user->display_name : '', 'subject' => sprintf('Error submission from %s', html_entity_decode(get_option('blogname'))), 'text_content' => json_encode($message), 'message_type' => Prompt_Enum_Message_Types::ADMIN));
     $sent = Prompt_Factory::make_mailer($email, Prompt_Enum_Email_Transports::LOCAL)->send();
     if (is_wp_error($sent) and Prompt_Core::$options->get('prompt_key')) {
         $sent = Prompt_Factory::make_mailer($email, Prompt_Enum_Email_Transports::API)->send();
     }
     return $sent;
 }
Example #11
0
 /**
  * @since 2.0.0
  */
 protected function forward()
 {
     $text = $this->get_message_text();
     $from_user = get_user_by('id', $this->from_user_id);
     $to_user = get_user_by('id', $this->to_user_id);
     $command = new Prompt_Forward_Command();
     $command->set_keys(array('', '', $this->to_user_id, $this->from_user_id));
     $template_data = array('sender' => $from_user, 'message' => $text);
     $html_template = new Prompt_Template('forward-email.php');
     $batch = Prompt_Email_Batch::make_for_single_recipient(array('to_address' => $to_user->user_email, 'from_name' => $from_user->display_name, 'subject' => $this->message->subject, 'html_content' => $html_template->render($template_data), 'message_type' => Prompt_Enum_Message_Types::ADMIN, 'reply_to' => array('trackable-address' => Prompt_Command_Handling::get_command_metadata($command))));
     Prompt_Factory::make_mailer($batch)->send();
 }
Example #12
0
 /**
  * Send email notifications for a post.
  *
  * @param WP_Post|int $post
  * @param string $chunk Optional identifier for this chunk (to avoid cron collisions)
  * @param int $retry_wait_seconds Minimum time to wait if a retry is necessary, null for default
  */
 public static function send_notifications($post, $chunk = '', $retry_wait_seconds = null)
 {
     $batch = new Prompt_Post_Email_Batch(new Prompt_Post_Rendering_Context($post));
     Prompt_Factory::make_mailer($batch, null, $chunk)->set_retry_wait_seconds($retry_wait_seconds)->send();
 }
 protected function send_notifications($recipient_ids)
 {
     $template_data = array('post' => $this->prompt_post, 'comment_header' => true);
     /**
      * Filter comment email template data.
      *
      * @param array $template_data {
      * @type Prompt_post $post
      * @type bool $comment_header
      * }
      */
     $template_data = apply_filters('prompt/comment_flood_email/template_data', $template_data);
     $html_template = new Prompt_Template('comment-flood-email.php');
     $text_template = new Prompt_Text_Template('comment-flood-email-text.php');
     $footnote_html = sprintf(__('You received this email because you\'re subscribed to %s.', 'Postmatic'), $this->prompt_post->subscription_object_label());
     $batch = new Prompt_Email_Batch(array('subject' => __('We\'re pausing comment notices for you.', 'Postmatic'), 'text_content' => $text_template->render($template_data), 'html_content' => $html_template->render($template_data), 'message_type' => Prompt_Enum_Message_Types::SUBSCRIPTION, 'reply_to' => '{{{reply_to}}}', 'footnote_html' => $footnote_html, 'footnote_text' => Prompt_Content_Handling::reduce_html_to_utf8($footnote_html)));
     foreach ($recipient_ids as $recipient_id) {
         $subscriber = get_userdata($recipient_id);
         if (!$subscriber or !$subscriber->user_email) {
             continue;
         }
         $command = new Prompt_Comment_Flood_Command();
         $command->set_post_id($this->prompt_post->id());
         $command->set_user_id($recipient_id);
         $batch->add_individual_message_values(array('to_address' => $subscriber->user_email, 'reply_to' => Prompt_Email_Batch::trackable_address(Prompt_Command_Handling::get_command_metadata($command))));
     }
     /**
      * Filter comment notification email batch.
      *
      * @param Prompt_Email_Batch $batch
      * @param array $template_data see prompt/comment_email/template_data
      */
     $batch = apply_filters('prompt/comment_flood_email_batch', $batch, $template_data);
     Prompt_Factory::make_mailer($batch)->send();
 }
Example #14
0
 /**
  * Handle post editor preview email requests.
  */
 public static function action_wp_ajax_prompt_post_delivery_preview()
 {
     $post_id = absint($_GET['post_id']);
     if (!$post_id) {
         wp_die(0);
     }
     $post = get_post($post_id);
     $context = new Prompt_Post_Rendering_Context($post);
     $context->setup();
     $batch = new Prompt_Post_Email_Batch($context);
     $batch->add_recipient(new Prompt_User(wp_get_current_user()));
     $context->reset();
     Prompt_Factory::make_post_adhoc_mailer($batch)->send();
     wp_send_json(array('message' => __('Preview email sent.', 'Postmatic')));
 }
Example #15
0
 /**
  * Schedule a retry if a temporary failure has occurred.
  *
  * @since 2.0.0
  *
  * @param array $response
  * @return bool Whether a retry has been rescheduled.
  */
 protected function reschedule($response)
 {
     $rescheduler = Prompt_Factory::make_rescheduler($response, $this->retry_wait_seconds);
     if ($rescheduler->found_temporary_error()) {
         $rescheduler->reschedule('prompt/mailing/send', array('batch' => $this->batch));
         return true;
     }
     return false;
 }
Example #16
0
 /**
  * Validate a key
  *
  * @since 1.0.0
  * @param string            $key
  * @return mixed|string|WP_Error
  */
 public function validate_key($key)
 {
     if (empty($key)) {
         return '';
     }
     $key = preg_replace('/\\s/', '', sanitize_text_field($key));
     $response = $this->api_client($key)->get_site();
     if (is_wp_error($response) or !in_array($response['response']['code'], array(200, 401, 503))) {
         return Prompt_Logging::add_error('key_http_error', __('There\'s a problem verifying your key. Please try later or report this error.', 'Postmatic'), $response);
     }
     if (503 == $response['response']['code']) {
         $message = sprintf(__('Postmatic service is temporarily unavailable, see <a href="%s">our twitter feed</a> for updates.', 'Postmatic'), Prompt_Enum_Urls::TWITTER);
         return new WP_Error('service_unavailable', $message);
     }
     if (401 == $response['response']['code']) {
         $message = sprintf(__('We didn\'t recognize the key "%s". Please make sure it exactly matches the key we supplied you. <a href="%s" target="_blank">Visit your Postmatic dashboard for assistance</a>. ', 'Postmatic'), $key, Prompt_Enum_Urls::MANAGE);
         return new WP_Error('invalid_key', $message);
     }
     $configuration = json_decode($response['body']);
     if (!self::site_matches($configuration->site->url)) {
         $message = sprintf(__('Your key was registered for a different site. Please request a key for this site\'s dedicated use, or <a href="%s" target="_blank">contact us</a> for assistance. Thanks!', 'Postmatic'), Prompt_Enum_Urls::BUG_REPORTS);
         return new WP_Error('wrong_key', $message);
     }
     if (Prompt_Core::$options->get('enable_digests') and !in_array(Prompt_Enum_Message_Types::DIGEST, $configuration->configuration->enabled_message_types)) {
         $configuration->configuration->enable_digests = false;
     }
     $configurator = Prompt_Factory::make_configurator($this->api_client());
     $configurator->update_configuration($configuration);
     return $key;
 }
 /**
  * @since 2.0.0
  */
 protected function send_post()
 {
     $post = get_post($this->post_id);
     $context = new Prompt_Post_Rendering_Context($post);
     $context->setup();
     $batch = new Prompt_Post_Email_Batch($context, array('excerpt_only' => false));
     $batch->add_recipient(new Prompt_User($this->user_id));
     $context->reset();
     Prompt_Factory::make_post_adhoc_mailer($batch)->send();
 }
Example #18
0
 public static function receive_pull_configuration()
 {
     self::validate_or_die();
     $configurator = Prompt_Factory::make_configurator();
     self::set_return_code_and_die($configurator->pull_configuration());
 }
Example #19
0
 /**
  * @since 2.0.0
  *
  * @param \Prompt_Email_Batch
  * @param int $retry_wait_seconds
  */
 public static function send($batch, $retry_wait_seconds)
 {
     Prompt_Factory::make_mailer($batch)->set_retry_wait_seconds($retry_wait_seconds)->send();
 }