• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Jetpack a2z

Jetpack a2z

Jetpack a2z

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Jetpack_Subscriptions::subscribe() – Jetpack_Subscriptions::subscribe()

You appear to be a bot. Output may be restricted

Description

Jetpack_Subscriptions::subscribe()

Send a synchronous XML-RPC subscribe to blog posts or subscribe to post comments request.

Usage

$true|WP_Error = Jetpack_Subscriptions::subscribe( $email, $post_ids, $async, $extra_data );

Parameters

$email
( string ) required –
$post_ids
( array ) optional – (optional) defaults to 0 for blog posts only: array of post IDs to subscribe to blog's posts
$async
( bool ) optional default: 1 – (optional) Should the subscription be performed asynchronously? Defaults to true.
$extra_data
( mixed ) optional –

Returns

true|WP_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. pending : Tried to subscribe before but the confirmation link is never clicked. No confirmation email is sent. 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.

Source

File name: jetpack/modules/subscriptions.php


Lines:

1 to 74 of 74
  function subscribe( $email, $post_ids = 0, $async = true, $extra_data = array() ) {
    if ( !is_email( $email ) ) {
      return new WP_Error( 'invalid_email' );
    }

    if ( !$async ) {
      $xml = new Jetpack_IXR_ClientMulticall();
    }

    foreach ( (array) $post_ids as $post_id ) {
      $post_id = (int) $post_id;
      if ( $post_id < 0 ) {
        return new WP_Error( 'invalid_post_id' );
      } else if ( $post_id && !$post = get_post( $post_id ) ) {
        return new WP_Error( 'unknown_post_id' );
      }

      if ( $async ) {
        XMLRPC_Async_Call::add_call( 'jetpack.subscribeToSite', 0, $email, $post_id, serialize( $extra_data ) ); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
      } else {
        $xml->addCall( 'jetpack.subscribeToSite', $email, $post_id, serialize( $extra_data ) );
      }
    }

    if ( $async ) {
      return;
    }

    // Call
    $xml->query();

    if ( $xml->isError() ) {
      return $xml->get_jetpack_error();
    }

    $responses = $xml->getResponse();

    $r = array();
    foreach ( (array) $responses as $response ) {
      if ( isset( $response['faultCode'] ) || isset( $response['faultString'] ) ) {
        $r[] = $xml->get_jetpack_error( $response['faultCode'], $response['faultString'] );
        continue;
      }

      if ( !is_array( $response[0] ) || empty( $response[0]['status'] ) ) {
        $r[] = new WP_Error( 'unknown' );
        continue;
      }

      switch ( $response[0]['status'] ) {
        case 'error':
          $r[] = new WP_Error( 'not_subscribed' );
          continue 2;
        case 'disabled':
          $r[] = new WP_Error( 'disabled' );
          continue 2;
        case 'active':
          $r[] = new WP_Error( 'active' );
          continue 2;
        case 'confirming':
          $r[] = true;
          continue 2;
        case 'pending':
          $r[] = new WP_Error( 'pending' );
          continue 2;
        default:
          $r[] = new WP_Error( 'unknown_status', (string) $response[0]['status'] );
          continue 2;
      }
    }

    return $r;
  }
 

 View on GitHub View on Trac

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Related

Published: 27 November 2019 | Last updated: 10 December 2020

Primary Sidebar

Information

Function name: Jetpack_Subscriptions::subscribe
Class ref: Jetpack_Subscriptions
Plugin ref: Jetpack
Version: 9.2
Sourcefile: modules/subscriptions.php
File ref: modules/subscriptions.php
Deprecated?: No
API Letters: J,S

Footer

Jetpack a2z
Jetpack a2z
Jetpack a2z
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  jetpack.wp-a2z.org
© Copyright Jetpack a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites