Prompt_Api::subscribe()

If you've collected data from a subscriber and want to sign them up to receive new posts via Postmatic, this is your method.

Example

Call the subscribe method with some hard coded data, and check the result:

$subscriber_data = array(
  'email_address' => 'test@example.tld',  // Required
  'first_name' => 'Example',              // Optional
  'last_name' => 'Subscriber',            // Optional
);
$status = Prompt_Api::subscribe( $subscriber_data );
switch ( $status ) {
  case Prompt_Api::INVALID_EMAIL:
    _e( 
      "Whoa, that's something, but it ain't an email address!", 
      'example-text-domain' 
    );
    break;
  case Prompt_Api::ALREADY_SUBSCRIBED:
    _e( 
      "You were already subscribed, but we're glad you wanted to make sure.", 
      'example-text-domain' 
    );
    break;
  case Prompt_Api::CONFIRMATION_SENT:
    _e( "You're subscribed - watch for a confirmation email.", 'example-text-domain' );
    break;
  case Prompt_Api::OPT_IN_SENT:
    _e( "Great! Now check your email for the final step.", 'example-text-domain' );
    break;
}

Parameters

$subscriber_data
(array) (Required) Data fields for the subscriber can include additional WordPress user fields, but most likely of interest are:

  • 'email_address' 
    (string) (Required)
  • 'first_name'
    (string)
  • 'last_name'
    (string)
  • 'display_name'
    (string) If not supplied first and last name are used. If no names are supplied, a name is created from the user part of the email address.

Return Value

(string) The resulting status of the subscriber, matching one of the following class constants:

  • Prompt_Api::OPT_IN_SENT
    An email was sent to verify the subscription for an address that has not yet opted in to receive content from the site.
  • Prompt_Api::CONFIRMATION_SENT
    An email was sent confirming the subscription for an address that has already opted in to receive content from the site.
  • Prompt_Api::ALREADY_SUBSCRIBED
    The email address was already subscribed, so no action was needed.
  • Prompt_Api::INVALID_EMAIL
    The email address was invalid and could not be subscribed.

Still need help? Contact Us Contact Us