Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../themes/Divi/core/componen.../api/email
File: ConvertKit.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Wrapper for ConvertKit's API.
[3] Fix | Delete
*
[4] Fix | Delete
* @since 1.1.0
[5] Fix | Delete
*
[6] Fix | Delete
* @package ET\Core\API\Email
[7] Fix | Delete
*/
[8] Fix | Delete
class ET_Core_API_Email_ConvertKit extends ET_Core_API_Email_Provider {
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* @inheritDoc
[12] Fix | Delete
*/
[13] Fix | Delete
public $BASE_URL = 'https://api.convertkit.com/v3';
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* @inheritDoc
[17] Fix | Delete
*/
[18] Fix | Delete
public $custom_fields_scope = 'account';
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* @inheritDoc
[22] Fix | Delete
*/
[23] Fix | Delete
public $name = 'ConvertKit';
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* @inheritDoc
[27] Fix | Delete
*/
[28] Fix | Delete
public $name_field_only = true;
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* @inheritDoc
[32] Fix | Delete
*/
[33] Fix | Delete
public $slug = 'convertkit';
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* @inheritDoc
[37] Fix | Delete
*/
[38] Fix | Delete
public $uses_oauth = false;
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* ET_Core_API_Email_ConvertKit constructor.
[42] Fix | Delete
*
[43] Fix | Delete
* @inheritDoc
[44] Fix | Delete
*/
[45] Fix | Delete
public function __construct( $owner, $account_name = '', $api_key = '' ) {
[46] Fix | Delete
parent::__construct( $owner, $account_name, $api_key );
[47] Fix | Delete
[48] Fix | Delete
// ConvertKit doesn't have "lists". They have "forms" so we use "forms" as if they were "lists".
[49] Fix | Delete
$this->LISTS_URL = "{$this->BASE_URL}/forms";
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
protected function _fetch_custom_fields( $list_id = '', $list = array() ) {
[53] Fix | Delete
$this->response_data_key = 'custom_fields';
[54] Fix | Delete
[55] Fix | Delete
$this->prepare_request( $this->_generate_url_for_request( "{$this->BASE_URL}/custom_fields" ) );
[56] Fix | Delete
[57] Fix | Delete
return parent::_fetch_custom_fields( $list_id, $list );
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* Generates the URL for adding subscribers.
[62] Fix | Delete
*
[63] Fix | Delete
* @param $list_id
[64] Fix | Delete
*
[65] Fix | Delete
* @since 1.1.0
[66] Fix | Delete
*
[67] Fix | Delete
* @return string
[68] Fix | Delete
*/
[69] Fix | Delete
protected function _get_subscribe_url( $list_id ) {
[70] Fix | Delete
return "{$this->LISTS_URL}/{$list_id}/subscribe";
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
protected function _get_subscriber_counts( $forms ) {
[74] Fix | Delete
$result = array();
[75] Fix | Delete
[76] Fix | Delete
foreach ( (array) $forms as $form_info ) {
[77] Fix | Delete
$url = $this->_generate_url_for_request( "{$this->LISTS_URL}/{$form_info['id']}/subscriptions", true );
[78] Fix | Delete
[79] Fix | Delete
$this->prepare_request( $url );
[80] Fix | Delete
$this->make_remote_request();
[81] Fix | Delete
[82] Fix | Delete
if ( $this->response->ERROR || ! isset( $this->response->DATA['total_subscriptions'] ) ) {
[83] Fix | Delete
continue;
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
$form_info['total_subscriptions'] = $this->response->DATA['total_subscriptions'];
[87] Fix | Delete
[88] Fix | Delete
$result[] = $form_info;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
return $result;
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* Adds default args for all API requests to given url.
[96] Fix | Delete
*
[97] Fix | Delete
* @since 1.1.0
[98] Fix | Delete
*
[99] Fix | Delete
* @param string $url
[100] Fix | Delete
* @param bool $with_secret
[101] Fix | Delete
*
[102] Fix | Delete
* @return string
[103] Fix | Delete
*/
[104] Fix | Delete
protected function _generate_url_for_request( $url, $with_secret = false ) {
[105] Fix | Delete
$key = $with_secret ? $this->data['api_secret'] : $this->data['api_key'];
[106] Fix | Delete
$key_type = $with_secret ? 'api_secret' : 'api_key';
[107] Fix | Delete
[108] Fix | Delete
return esc_url_raw( add_query_arg( $key_type, $key, $url ) );
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
protected function _process_custom_fields( $args ) {
[112] Fix | Delete
if ( ! isset( $args['custom_fields'] ) ) {
[113] Fix | Delete
return $args;
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
$fields = $args['custom_fields'];
[117] Fix | Delete
[118] Fix | Delete
unset( $args['custom_fields'] );
[119] Fix | Delete
[120] Fix | Delete
foreach ( $fields as $field_id => $value ) {
[121] Fix | Delete
if ( is_array( $value ) && $value ) {
[122] Fix | Delete
// This is a multiple choice field (eg. checkbox, radio, select)
[123] Fix | Delete
$value = array_values( $value );
[124] Fix | Delete
[125] Fix | Delete
if ( count( $value ) > 1 ) {
[126] Fix | Delete
$value = implode( ',', $value );
[127] Fix | Delete
} else {
[128] Fix | Delete
$value = array_pop( $value );
[129] Fix | Delete
}
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
self::$_->array_set( $args, "fields.{$field_id}", $value );
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
return $args;
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* @inheritDoc
[140] Fix | Delete
*/
[141] Fix | Delete
public function get_account_fields() {
[142] Fix | Delete
return array(
[143] Fix | Delete
'api_key' => array(
[144] Fix | Delete
'label' => esc_html__( 'API Key', 'et_core' ),
[145] Fix | Delete
),
[146] Fix | Delete
'api_secret' => array(
[147] Fix | Delete
'label' => esc_html__( 'API Secret', 'et_core' ),
[148] Fix | Delete
),
[149] Fix | Delete
);
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
/**
[153] Fix | Delete
* @inheritDoc
[154] Fix | Delete
*/
[155] Fix | Delete
public function get_data_keymap( $keymap = array() ) {
[156] Fix | Delete
$keymap = array(
[157] Fix | Delete
'list' => array(
[158] Fix | Delete
'list_id' => 'id',
[159] Fix | Delete
'name' => 'name',
[160] Fix | Delete
'subscribers_count' => 'total_subscriptions',
[161] Fix | Delete
),
[162] Fix | Delete
'subscriber' => array(
[163] Fix | Delete
'email' => 'email',
[164] Fix | Delete
'name' => 'first_name',
[165] Fix | Delete
'custom_fields' => 'custom_fields',
[166] Fix | Delete
),
[167] Fix | Delete
'error' => array(
[168] Fix | Delete
'error_message' => 'message',
[169] Fix | Delete
),
[170] Fix | Delete
'custom_field' => array(
[171] Fix | Delete
'field_id' => 'key',
[172] Fix | Delete
'name' => 'label',
[173] Fix | Delete
),
[174] Fix | Delete
);
[175] Fix | Delete
[176] Fix | Delete
return parent::get_data_keymap( $keymap );
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* @inheritDoc
[181] Fix | Delete
*/
[182] Fix | Delete
public function fetch_subscriber_lists() {
[183] Fix | Delete
if ( empty( $this->data['api_key'] ) ) {
[184] Fix | Delete
return $this->API_KEY_REQUIRED;
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
$url = $this->_generate_url_for_request( $this->LISTS_URL );
[188] Fix | Delete
$result = 'success';
[189] Fix | Delete
[190] Fix | Delete
$this->response_data_key = '';
[191] Fix | Delete
[192] Fix | Delete
$this->prepare_request( $url );
[193] Fix | Delete
parent::fetch_subscriber_lists();
[194] Fix | Delete
[195] Fix | Delete
if ( ! $this->response->ERROR && ! empty( $this->response->DATA['forms'] ) ) {
[196] Fix | Delete
$with_subscriber_counts = $this->_get_subscriber_counts( $this->response->DATA['forms'] );
[197] Fix | Delete
$this->data['lists'] = $this->_process_subscriber_lists( $with_subscriber_counts );
[198] Fix | Delete
$this->data['is_authorized'] = 'true';
[199] Fix | Delete
$this->data['custom_fields'] = $this->_fetch_custom_fields( '', array_shift( $this->response->DATA['forms'] ) );
[200] Fix | Delete
[201] Fix | Delete
$this->save_data();
[202] Fix | Delete
} else if ( $this->response->ERROR ) {
[203] Fix | Delete
$result = $this->get_error_message();
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
return $result;
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* @inheritDoc
[211] Fix | Delete
*/
[212] Fix | Delete
public function subscribe( $args, $url = '' ) {
[213] Fix | Delete
$url = $this->_generate_url_for_request( $this->_get_subscribe_url( $args['list_id'] ) );
[214] Fix | Delete
$params = $this->transform_data_to_provider_format( $args, 'subscriber' );
[215] Fix | Delete
$params = $this->_process_custom_fields( $params );
[216] Fix | Delete
$params['fields']['notes'] = $this->SUBSCRIBED_VIA;
[217] Fix | Delete
[218] Fix | Delete
$this->prepare_request( $url, 'POST', false, $params );
[219] Fix | Delete
[220] Fix | Delete
return parent::subscribe( $params, $url );
[221] Fix | Delete
}
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function