/** * @param WP_Post $post */ public function display($post) { if (!$this->prompt_post) { $this->prompt_post = new Prompt_Post($post); } if ($post->ID != $this->prompt_post->id()) { return; } $sent = (bool) $this->prompt_post->sent_recipient_ids(); if ($sent) { echo html('h3', __('This was the text version sent to subscribers.', 'Postmatic')); } $text = $this->prompt_post->get_custom_text(); if (!$sent and $text and 'publish' != $post->post_status) { echo self::render_form($text); return; } if ('publish' != $post->post_status) { echo html('input type="button" class="button prompt-customize-text"', array('value' => __('Customize', 'Postmatic'))); } if (empty($text) and 'auto-draft' != $post->post_status) { $context = new Prompt_Post_Rendering_Context($post); $text = $context->get_the_text_content(); $context->reset(); } echo html('pre class="prompt-custom-text"', $text); echo html('div class="prompt-custom-text-upgrade"', sprintf(__('This post will be sent as a multipart message. We have automatically generated a plaintext version for older email clients. You can adjust it if you need to.', 'Postmatic'), Prompt_Enum_Urls::PREMIUM)); }
public static function filter_response($response) { if (!isset($response['wp_autosave'])) { return $response; } $context = new Prompt_Post_Rendering_Context(intval($_POST['data']['wp_autosave']['post_id'])); $response['prompt_text_version'] = $context->get_the_text_content(); $context->reset(); return $response; }
/** * Builds an email without specific recipient info that can be used as a template for all recipients. * * The set_recipient method can be called to fill in recipient-specific fields. * * @since 2.0.0 * * @param Prompt_Post_Rendering_Context $context Rendering context for the target post * @param array $args { * @type bool $excerpt_only Override the excerpt only checkbox in the delivery metabox. * } */ public function __construct(Prompt_Post_Rendering_Context $context, $args = array()) { $this->context = $context; $context->setup(); $prompt_author = $context->get_author(); $prompt_post = $context->get_post(); $is_api_delivery = Prompt_Enum_Email_Transports::API == Prompt_Core::$options->get('email_transport'); $will_strip_content = (!$is_api_delivery and $context->has_fancy_content()); $subject = html_entity_decode($prompt_post->get_wp_post()->post_title, ENT_QUOTES); list($footnote_html, $footnote_text) = $this->footnote_content(); if ('draft' == $prompt_post->get_wp_post()->post_status) { /* translators: %s is a post title */ $subject = sprintf(__('PREVIEW of %s', 'Postmatic'), $subject); $footnote_html = $footnote_text = ''; } $excerpt_only = Prompt_Admin_Delivery_Metabox::excerpt_only($prompt_post->id()); if (isset($args['excerpt_only'])) { $excerpt_only = $args['excerpt_only']; } $this->comments = get_approved_comments($prompt_post->id()); $template_data = array('prompt_author' => $prompt_author, 'prompt_post' => $prompt_post, 'featured_image_src' => $context->get_the_featured_image_src(), 'excerpt_only' => $excerpt_only, 'the_text_content' => $context->get_the_text_content(), 'subject' => $subject, 'alternate_versions_menu' => $context->alternate_versions_menu(), 'is_api_delivery' => $is_api_delivery, 'will_strip_content' => $will_strip_content, 'comments' => $this->comments); /** * Filter new post email template data. * * @param array $template_data { * @type Prompt_User $prompt_author * @type Prompt_Post $prompt_post * @type array $featured_image_src url, width, height * @type bool $excerpt_only whether to include only the post excerpt * @type string $the_text_content * @type string $subject * @type bool $is_api_delivery * @type bool $will_strip_content * } */ $template_data = apply_filters('prompt/post_email/template_data', $template_data); $html_template = new Prompt_Template("new-post-email.php"); $text_template = new Prompt_Text_Template("new-post-email-text.php"); $batch_message_template = array('subject' => $subject, 'from_name' => '{{{from_name}}}', 'text_content' => $text_template->render($template_data), 'html_content' => $html_template->render($template_data), 'message_type' => Prompt_Enum_Message_Types::POST, 'reply_to' => '{{{reply_to}}}', 'footnote_html' => $footnote_html, 'footnote_text' => $footnote_text); $this->replyable = (comments_open($prompt_post->id()) and !$excerpt_only); if (!$this->replyable) { $batch_message_template['from_address'] = $prompt_author->get_wp_user()->user_email; } $default_values = array('from_name' => $this->to_utf8(get_option('blogname'))); $context->reset(); parent::__construct($batch_message_template, array(), $default_values); }