PHP Class MC4WP_API

Mostrar archivo Open project: dannyvankooten/mailchimp-for-wordpress

Protected Properties

Property Type Description
$api_key The API key to use
$api_url The URL to the MailChimp API
$connected Boolean indicating whether the user is connected with MailChimp
$error_code The error code of the last API request (if any)
$error_message The error message of the latest API request (if any)
$last_response The full response object of the latest API call

Public Methods

Method Description
__construct ( string $api_key ) Constructor
add_ecommerce_order ( array $order_data ) : boolean
call ( string $method, array $data = [] ) : object Calls the MailChimp API
delete_ecommerce_order ( string $store_id, string $order_id ) : boolean
get_error_code ( ) : integer Gets the most recent error code
get_error_message ( ) : string Gets the most recent error message
get_last_response ( ) : object Get the most recent response object
get_list_groupings ( integer $list_id ) : array | boolean Gets the Groupings for a given List
get_lists ( array $list_ids = [] ) : boolean
get_lists_for_email ( array | string $email ) : array Get the lists an email address is subscribed to
get_lists_with_merge_vars ( array $list_ids ) : array | boolean Get lists with their merge_vars for a given array of list id's
get_subscriber_info ( string $list_id, array $emails ) : array Gets the member info for one or multiple emails on a list
has_error ( ) : boolean Checks if an error occured in the most recent request
is_connected ( ) : boolean Pings the MailChimp API to see if we're connected
list_has_subscriber ( string $list_id, string $email ) : boolean Checks if an email address is on a given list
subscribe ( string $list_id, string $email, array $merge_vars = [], string $email_type = 'html', boolean $double_optin = true, boolean $update_existing = false, boolean $replace_interests = true, boolean $send_welcome = false ) : boolean | string Sends a subscription request to the MailChimp API
unsubscribe ( string $list_id, array | string $struct, boolean $send_goodbye = true, boolean $send_notification = false, boolean $delete_member = false ) : boolean Unsubscribes the given email or luid from the given MailChimp list
update_subscriber ( string $list_id, array | string $email, array $merge_vars = [], string $email_type = 'html', boolean $replace_interests = false ) : boolean

Private Methods

Method Description
empty_last_response ( ) Empties all data from previous response
get_headers ( ) : array Get the request headers to send to the MailChimp API
parse_response ( array | WP_Error $response ) : object
show_connection_error ( $message ) : boolean
show_error ( string $message ) : boolean Show an error message to administrators

Method Details

__construct() public method

Constructor
public __construct ( string $api_key )
$api_key string

add_ecommerce_order() public method

See also: https://apidocs.mailchimp.com/api/2.0/ecomm/order-add.php
public add_ecommerce_order ( array $order_data ) : boolean
$order_data array
return boolean

call() public method

Calls the MailChimp API
public call ( string $method, array $data = [] ) : object
$method string
$data array
return object

delete_ecommerce_order() public method

See also: https://apidocs.mailchimp.com/api/2.0/ecomm/order-del.php
public delete_ecommerce_order ( string $store_id, string $order_id ) : boolean
$store_id string
$order_id string
return boolean

get_error_code() public method

Gets the most recent error code
public get_error_code ( ) : integer
return integer

get_error_message() public method

Gets the most recent error message
public get_error_message ( ) : string
return string

get_last_response() public method

Get the most recent response object
public get_last_response ( ) : object
return object

get_list_groupings() public method

Gets the Groupings for a given List
public get_list_groupings ( integer $list_id ) : array | boolean
$list_id integer
return array | boolean

get_lists() public method

public get_lists ( array $list_ids = [] ) : boolean
$list_ids array Array of ID's of the lists to fetch. (optional)
return boolean

get_lists_for_email() public method

Get the lists an email address is subscribed to
public get_lists_for_email ( array | string $email ) : array
$email array | string
return array

get_lists_with_merge_vars() public method

Get lists with their merge_vars for a given array of list id's
public get_lists_with_merge_vars ( array $list_ids ) : array | boolean
$list_ids array
return array | boolean

get_subscriber_info() public method

Gets the member info for one or multiple emails on a list
public get_subscriber_info ( string $list_id, array $emails ) : array
$list_id string
$emails array
return array

has_error() public method

Checks if an error occured in the most recent request
public has_error ( ) : boolean
return boolean

is_connected() public method

The result is cached to ensure a maximum of 1 API call per page load
public is_connected ( ) : boolean
return boolean

list_has_subscriber() public method

Checks if an email address is on a given list
public list_has_subscriber ( string $list_id, string $email ) : boolean
$list_id string
$email string
return boolean

subscribe() public method

Sends a subscription request to the MailChimp API
public subscribe ( string $list_id, string $email, array $merge_vars = [], string $email_type = 'html', boolean $double_optin = true, boolean $update_existing = false, boolean $replace_interests = true, boolean $send_welcome = false ) : boolean | string
$list_id string The list id to subscribe to
$email string The email address to subscribe
$merge_vars array Array of extra merge variables
$email_type string The email type to send to this email address. Possible values are `html` and `text`.
$double_optin boolean Should this email be confirmed via double opt-in?
$update_existing boolean Update information if this email is already on list?
$replace_interests boolean Replace interest groupings, only if update_existing is true.
$send_welcome boolean Send a welcome e-mail, only if double_optin is false.
return boolean | string True if success, 'error' if error

unsubscribe() public method

Unsubscribes the given email or luid from the given MailChimp list
public unsubscribe ( string $list_id, array | string $struct, boolean $send_goodbye = true, boolean $send_notification = false, boolean $delete_member = false ) : boolean
$list_id string
$struct array | string
$send_goodbye boolean
$send_notification boolean
$delete_member boolean
return boolean

update_subscriber() public method

public update_subscriber ( string $list_id, array | string $email, array $merge_vars = [], string $email_type = 'html', boolean $replace_interests = false ) : boolean
$list_id string
$email array | string
$merge_vars array
$email_type string
$replace_interests boolean
return boolean

Property Details

$api_key protected_oe property

The API key to use
protected $api_key

$api_url protected_oe property

The URL to the MailChimp API
protected $api_url

$connected protected_oe property

Boolean indicating whether the user is connected with MailChimp
protected $connected

$error_code protected_oe property

The error code of the last API request (if any)
protected $error_code

$error_message protected_oe property

The error message of the latest API request (if any)
protected $error_message

$last_response protected_oe property

The full response object of the latest API call
protected $last_response