subscribe() public method

Send a synchronous XML-RPC subscribe to blog posts or subscribe to post comments request.
public subscribe ( string $email, array $post_ids, boolean $async = true, $extra_data = [] ) : true | Jetpack_Error
$email string
$post_ids array (optional) defaults to 0 for blog posts only: array of post IDs to subscribe to blog's posts
$async boolean (optional) Should the subscription be performed asynchronously? Defaults to true.
return true | Jetpack_Error true on success invalid_email : not a valid email address invalid_post_id : not a valid post ID unknown_post_id : unknown post not_subscribed : strange error. Jetpack servers at WordPress.com could subscribe the email. disabled : Site owner has disabled subscriptions. active : Already subscribed. unknown : strange error. Jetpack servers at WordPress.com returned something malformed. unknown_status : strange error. Jetpack servers at WordPress.com returned something I didn't understand.
Esempio n. 1
0
 /**
  * Check Jetpack Subscription
  * @since 1.0.5
  * @version 1.0
  */
 protected function check_jetpack_subscription($email = NULL, $post_ids = NULL)
 {
     if ($email === NULL) {
         return 'missing';
     }
     if (!class_exists('Jetpack') && defined('JETPACK__PLUGIN_DIR')) {
         require_once JETPACK__PLUGIN_DIR . 'jetpack.php';
     }
     if (!class_exists('Jetpack_Subscriptions') && defined('JETPACK__PLUGIN_DIR')) {
         require_once JETPACK__PLUGIN_DIR . 'modules/subscriptions.php';
     }
     if ($post_ids === NULL) {
         $subscribe = Jetpack_Subscriptions::subscribe($email, 0, false);
     } else {
         $subscribe = Jetpack_Subscriptions::subscribe($email, $post_ids, false);
     }
     if (is_wp_error($subscribe)) {
         $error = $subscribe->get_error_code();
     } else {
         $error = false;
         foreach ($subscribe as $response) {
             if (is_wp_error($response)) {
                 $error = $response->get_error_code();
                 break;
             }
         }
     }
     if ($error) {
         switch ($error) {
             case 'invalid_email':
                 $return = 'invalid';
                 break;
             case 'active':
                 $return = 'active';
                 break;
             case 'pending':
                 $return = 'pending';
                 break;
             default:
                 $return = '';
                 break;
         }
     } else {
         if (is_array($subscribe) && $subscribe[0] === true) {
             $error = true;
         }
         $return = 'pending';
     }
     if ($error) {
         return $return;
     }
     return 'new';
 }
Esempio n. 2
0
 /**
  * Jetpack_Subscriptions::comment_subscribe_init()
  *
  * When a user checks the comment subscribe box and submits a comment, subscribe them to the comment thread.
  */
 function comment_subscribe_submit($comment_id, $approved)
 {
     if ('spam' === $approved) {
         return;
     }
     // Set cookies for this post/comment
     $this->set_cookies(isset($_REQUEST['subscribe_comments']), isset($_REQUEST['subscribe_blog']));
     if (!isset($_REQUEST['subscribe_comments']) && !isset($_REQUEST['subscribe_blog'])) {
         return;
     }
     $comment = get_comment($comment_id);
     $post_ids = array();
     if (isset($_REQUEST['subscribe_comments'])) {
         $post_ids[] = $comment->comment_post_ID;
     }
     if (isset($_REQUEST['subscribe_blog'])) {
         $post_ids[] = 0;
     }
     Jetpack_Subscriptions::subscribe($comment->comment_author_email, $post_ids, true, array('source' => 'comment-form', 'widget-in-use' => is_active_widget(false, false, 'blog_subscription', true) ? 'yes' : 'no', 'comment_status' => $approved, 'server_data' => $_SERVER));
 }
Esempio n. 3
0
 /**
  * Jetpack_Subscriptions::comment_subscribe_init()
  *
  * When a user checks the comment subscribe box and submits a comment, subscribe them to the comment thread.
  */
 function comment_subscribe_submit($comment_id, $approved)
 {
     if ('spam' === $approved) {
         return;
     }
     // Set cookies for this post/comment
     $this->set_cookies(isset($_REQUEST['subscribe_comments']), isset($_REQUEST['subscribe_blog']));
     if (!isset($_REQUEST['subscribe_comments']) && !isset($_REQUEST['subscribe_blog'])) {
         return;
     }
     $comment = get_comment($comment_id);
     $post_ids = array();
     if (isset($_REQUEST['subscribe_comments'])) {
         $post_ids[] = $comment->comment_post_ID;
     }
     if (isset($_REQUEST['subscribe_blog'])) {
         $post_ids[] = 0;
     }
     Jetpack_Subscriptions::subscribe($comment->comment_author_email, $post_ids);
 }