/**
  * Unsubscribe from the post author or site.
  * @param boolean $notify
  * @return array
  */
 protected function unsubscribe($notify = true)
 {
     $prompt_post = new Prompt_Post($this->post_id);
     $prompt_author = new Prompt_User($prompt_post->get_wp_post()->post_author);
     if ($prompt_author->is_subscribed($this->user_id)) {
         $this->author_unsubscribe($prompt_author, $notify);
         return;
     }
     // The user was not subscribed to the post author, so unsubscribe them from the site.
     $prompt_site = new Prompt_Site();
     $prompt_site->unsubscribe($this->user_id);
     if ($notify) {
         Prompt_Subscription_Mailing::send_unsubscription_notification($this->user_id, $prompt_site);
     }
 }
 /**
  * Handle user requests from the invite settings tab.
  */
 public static function action_wp_ajax_prompt_get_invite_users()
 {
     $users = get_users(array('exclude' => Prompt_Site::all_subscriber_ids()));
     $post_subscriber_ids = Prompt_Post::all_subscriber_ids();
     $results = array();
     foreach ($users as $user) {
         if (empty($user->user_email)) {
             continue;
         }
         $results[] = array('name' => $user->display_name, 'address' => $user->user_email, 'roles' => $user->roles, 'is_post_subscriber' => in_array($user->ID, $post_subscriber_ids));
     }
     wp_send_json($results);
 }
 protected function import($subscriber)
 {
     $existing_user = get_user_by('email', $subscriber['email_address']);
     $prompt_site = new Prompt_Site();
     if ($existing_user and $prompt_site->is_subscribed($existing_user->ID)) {
         $this->already_subscribed_count++;
         return;
     }
     if ($existing_user) {
         $subscriber_id = $existing_user->ID;
     } else {
         $subscriber_id = Prompt_User_Handling::create_from_email($subscriber['email_address']);
     }
     $prompt_site->subscribe($subscriber_id);
     $prompt_user = new Prompt_User($subscriber_id);
     $origin = new Prompt_Subscriber_Origin(array('source_label' => 'Jetpack Import', 'source_url' => scbUtil::get_current_url()));
     $prompt_user->set_subscriber_origin($origin);
     $this->imported_count++;
 }
Exemple #4
0
 /**
  * @since 1.0.0
  * @return array
  */
 public static function all_subscriber_ids()
 {
     // Currently just the default site subscribers
     $site = new Prompt_Site();
     return $site->subscriber_ids();
 }
Exemple #5
0
 /**
  * Get the IDs of users who should receive an email when this post is published.
  *
  * This includes both subscribers to the author and to the site.
  *
  * Post types not enabled in the options will have no recipients.
  *
  * @return array An array of user IDs.
  */
 public function recipient_ids()
 {
     $post = $this->get_wp_post();
     if (!in_array($post->post_type, Prompt_Core::$options->get('site_subscription_post_types'))) {
         return array();
     }
     $recipient_ids = $this->cached_recipient_ids();
     if (!$recipient_ids) {
         $prompt_site = new Prompt_Site();
         $recipient_ids = $prompt_site->subscriber_ids();
         $prompt_author = new Prompt_User($post->post_author);
         $recipient_ids = array_unique(array_merge($recipient_ids, $prompt_author->subscriber_ids()));
         /**
          * Filter the recipient ids of notifications for a post.
          *
          * @param array   $recipient_ids
          * @param WP_Post $post
          */
         $recipient_ids = apply_filters('prompt/recipient_ids/post', $recipient_ids, $post);
         if ('publish' == $post->post_status) {
             update_post_meta($post->ID, self::$recipient_ids_meta_key, $recipient_ids);
         }
     }
     return $recipient_ids;
 }