/** * Unsubscribe the user from an author. * * @since 2.0.0 * * @param Prompt_User $author * @param bool|true $notify */ protected function author_unsubscribe(Prompt_User $author, $notify = true) { $author->unsubscribe($this->user_id); if ($notify) { Prompt_Subscription_Mailing::send_unsubscription_notification($this->user_id, $author); } }
/** * Unsubscribe from whatever the confirmation was for. * * @since 2.0.0 * * @param bool $notify */ protected function unsubscribe($notify = true) { /** @var Prompt_Interface_Subscribable $object */ $object = new $this->object_type($this->object_id); $object->unsubscribe($this->user_id); if ($notify) { Prompt_Subscription_Mailing::send_unsubscription_notification($this->user_id, $object); } }
protected function rejoin() { $prompt_post = new Prompt_Post($this->post_id); if ($prompt_post->is_subscribed($this->user_id)) { return; } $prompt_post->subscribe($this->user_id); Prompt_Subscription_Mailing::send_rejoin_notification($this->user_id, $prompt_post); return; }
public function execute() { if (!$this->validate()) { return; } $comment_id = $this->keys[0]; $comment = get_comment($comment_id); if (!$comment) { Prompt_Logging::add_error('register_subscribe_comment_invalid', __('Couldn\'t find the original registration information for a new user.', 'Postmatic'), array('keys' => $this->keys, 'message' => $this->message)); return; } $lists = $this->resolve_lists($comment); $user_data = get_comment_meta($comment_id, self::$user_data_meta_key, true); $email = $comment->comment_author_email; $subscriber = get_user_by('email', $email); $opted_in_list = $this->opted_in_list($lists); if (!$subscriber and !$opted_in_list) { if (self::stop_resending($comment)) { return; } Prompt_Subscription_Mailing::send_agreement($lists, $email, $user_data, $resend_command = $this); return; } if (!$opted_in_list) { // The user has already been created, probably via a different reply. Just ignore this nonsense reply. return; } $subscriber_id = $subscriber ? $subscriber->ID : Prompt_User_Handling::create_from_email($email); if (is_wp_error($subscriber_id)) { Prompt_Logging::add_error('register_subscribe_user_creation_failure', __('Failed to create a new user from an agreement reply email.', 'Postmatic'), array('keys' => $this->keys, 'user_data' => $user_data, 'message' => $this->message, 'error' => $subscriber_id)); return; } if (!$subscriber and $user_data) { $user_data['ID'] = $subscriber_id; wp_update_user($user_data); $origin = new Prompt_Subscriber_Origin(array('source_label' => $opted_in_list->subscription_object_label(), 'source_url' => $opted_in_list->subscription_url(), 'agreement' => $this->message)); $prompt_user = new Prompt_User($subscriber_id); $prompt_user->set_subscriber_origin($origin); do_action('prompt/register_subscribe_command/created_user', $prompt_user->get_wp_user()); } if (!$opted_in_list->is_subscribed($subscriber_id)) { $opted_in_list->subscribe($subscriber_id); Prompt_Subscription_Mailing::send_subscription_notification($subscriber_id, $opted_in_list); } // TODO: remove our pre registration comment? }
/** * Subscribe a commenter. * * @param object $comment */ public static function subscribe_commenter($comment) { $user_id = $comment->user_id; if (!$user_id) { $user = get_user_by('email', $comment->comment_author_email); $user_id = $user ? $user->ID : null; } $prompt_post = new Prompt_Post($comment->comment_post_ID); if (!$user_id) { $user_data = array('display_name' => $comment->comment_author, 'user_url' => $comment->comment_author_url); Prompt_Subscription_Mailing::send_agreement($prompt_post, $comment->comment_author_email, $user_data); return; } if (!$prompt_post->is_subscribed($user_id)) { $prompt_post->subscribe($user_id); Prompt_Subscription_Mailing::send_subscription_notification($user_id, $prompt_post); } }
/** * @since 1.0.0 * * @param array $recipients * @param string $subject * @param string $message */ public function schedule_invites($recipients, $subject, $message) { $users_data = array(); $address_index = array(); $failures = array(); $lists = Prompt_Subscribing::get_signup_lists(); $current_user = wp_get_current_user(); foreach ($recipients as $recipient) { $to_address = Prompt_Email_Batch::address($recipient); $lower_case_to_address = strtolower($to_address); if (isset($address_index[$lower_case_to_address])) { $failures[] = __('Duplicate email address', 'Postmatic') . ': ' . $recipient; continue; } if (!is_email($to_address)) { $failures[] = __('Invalid email address', 'Postmatic') . ': ' . $recipient; continue; } $user = get_user_by('email', $to_address); if ($user and $this->is_subscribed_to_any($user->ID, $lists)) { $failures[] = __('Already subscribed', 'Postmatic') . ': ' . $recipient; continue; } $address_index[$lower_case_to_address] = true; $to_name = Prompt_Email_Batch::name($recipient); $users_data[] = array('user_email' => $to_address, 'display_name' => $to_name); } if (!empty($users_data)) { $message_data = array('subject' => html_entity_decode($subject, ENT_QUOTES), 'invite_introduction' => $message, 'message_type' => Prompt_Enum_Message_Types::INVITATION, 'from_name' => $current_user->display_name . ' - ' . get_option('blogname')); Prompt_Subscription_Mailing::schedule_agreements($lists, $users_data, $message_data); $confirmation_format = _n('Success. %d invite sent.', 'Success. %d invites sent.', count($users_data), 'Postmatic'); $this->add_notice(sprintf($confirmation_format, count($users_data))); } if (!empty($failures)) { $failure_notice = __('Something went wrong and these invites were not sent: ', 'Postmatic') . '<br/>' . implode('<br/>', $failures); $this->add_notice($failure_notice, 'error'); } }
/** * @since 2.0.0 * @param bool|false $notify */ protected function unsubscribe($notify = true) { if (empty($this->subscribable_class)) { return; } /** @var Prompt_Interface_Subscribable $list */ $list = new $this->subscribable_class($this->subscribable_id); if (!$list->is_subscribed($this->from_user_id)) { return; } $list->unsubscribe($this->from_user_id); if ($notify) { Prompt_Subscription_Mailing::send_unsubscription_notification($this->from_user_id, $list); } }
/** * @param Prompt_Interface_Subscribable|Prompt_Interface_Subscribable[] $lists * @param WP_User $subscriber * @return string Response */ protected static function subscribe($lists, $subscriber) { $lists = is_array($lists) ? $lists : array($lists); foreach ($lists as $list) { $list->subscribe($subscriber->ID); Prompt_Subscription_Mailing::send_subscription_notification($subscriber->ID, $list); } return __('<strong>Confirmation email sent. Please check your email for further instructions.</strong>', 'Postmatic'); }
/** * Unsubscribe an email address from a list. * * @since 1.0.0 * * @param string $email_address The address to unsubscribe * @param Prompt_Interface_Subscribable $list Optional, default is site-wide new posts. * @return string The resulting status, one of: * Prompt_Api::NEVER_SUBSCRIBED we don't recognize the email address * Prompt_Api::ALREADY_UNSUBSCRIBED * Prompt_Api::CONFIRMATION_SENT */ public static function unsubscribe($email_address, Prompt_Interface_Subscribable $list = null) { $user = get_user_by('email', $email_address); if (!$user) { return self::NEVER_SUBSCRIBED; } $list = $list ? $list : new Prompt_Site(); if (!$list->is_subscribed($user->ID)) { return self::ALREADY_UNSUBSCRIBED; } $list->unsubscribe($user->ID); Prompt_Subscription_Mailing::send_unsubscription_notification($user->ID, $list); return self::CONFIRMATION_SENT; }