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/wp-conte.../plugins/themify-.../includes/optin-se...
File: mailerlite.php
<?php
[0] Fix | Delete
[1] Fix | Delete
defined('ABSPATH') || exit;
[2] Fix | Delete
[3] Fix | Delete
class Builder_Optin_Service_MailerLite extends Builder_Optin_Service {
[4] Fix | Delete
[5] Fix | Delete
public static function get_id():string {
[6] Fix | Delete
return 'mailerlite';
[7] Fix | Delete
}
[8] Fix | Delete
[9] Fix | Delete
public static function get_label():string {
[10] Fix | Delete
return __('MailerLite', 'themify');
[11] Fix | Delete
}
[12] Fix | Delete
[13] Fix | Delete
public static function get_settings():array {
[14] Fix | Delete
$lists = self::get_lists();
[15] Fix | Delete
if (is_array($lists)) {
[16] Fix | Delete
return array(
[17] Fix | Delete
array(
[18] Fix | Delete
'id' => 'ml_form',
[19] Fix | Delete
'type' => 'select',
[20] Fix | Delete
'label' => __('Groups', 'themify'),
[21] Fix | Delete
'options' => $lists,
[22] Fix | Delete
),
[23] Fix | Delete
);
[24] Fix | Delete
} else {
[25] Fix | Delete
return array(
[26] Fix | Delete
array(
[27] Fix | Delete
'type' => 'message',
[28] Fix | Delete
'class' => 'tb_field_error_msg',
[29] Fix | Delete
'comment' => $lists
[30] Fix | Delete
)
[31] Fix | Delete
);
[32] Fix | Delete
}
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
public function get_options():array {//backward for fw 7.5
[36] Fix | Delete
return self::get_settings();
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
public static function get_global_options():array {
[40] Fix | Delete
return array(
[41] Fix | Delete
array(
[42] Fix | Delete
'id' => 'mailerlite_version',
[43] Fix | Delete
'type' => 'select',
[44] Fix | Delete
'label' => __('Version', 'themify'),
[45] Fix | Delete
'options' => [
[46] Fix | Delete
'' => __( 'Classic', 'themify' ), /* v1 or v2 */
[47] Fix | Delete
'new' => __( 'New', 'themify' ),
[48] Fix | Delete
],
[49] Fix | Delete
'description' => sprintf(__('Accounts created before March 22nd, 2022 use MailerLite Classic. Accounts created after March 22nd, 2022 use the new MailerLite. <a href="%s" target="_blank">Which version of MailerLite am I using?</a>', 'themify'), 'https://www.mailerlite.com/help/which-version-of-mailerlite-am-i-using'),
[50] Fix | Delete
'bind' => [
[51] Fix | Delete
'' => [ 'show' => 'mailerlite_key', 'hide' => 'mailerlite_key_new' ],
[52] Fix | Delete
'new' => [ 'show' => 'mailerlite_key_new', 'hide' => 'mailerlite_key' ],
[53] Fix | Delete
]
[54] Fix | Delete
),
[55] Fix | Delete
array(
[56] Fix | Delete
'id' => 'mailerlite_key',
[57] Fix | Delete
'type' => 'text',
[58] Fix | Delete
'label' => __('MailerLite Classic API Key', 'themify'),
[59] Fix | Delete
'description' => sprintf(__('<a href="%s" target="_blank">Get an API key</a>', 'themify'), 'https://app.mailerlite.com/integrations/api/'),
[60] Fix | Delete
'wrap_attr' => [
[61] Fix | Delete
'data-show-if-element' => '[name=setting-mailerlite_version]',
[62] Fix | Delete
'data-show-if-value' => ''
[63] Fix | Delete
],
[64] Fix | Delete
'wrap_class' => 'mailerlite_key'
[65] Fix | Delete
),
[66] Fix | Delete
array(
[67] Fix | Delete
'id' => 'mailerlite_key_new',
[68] Fix | Delete
'type' => 'textarea',
[69] Fix | Delete
'label' => __('MailerLite New API Key', 'themify'),
[70] Fix | Delete
'description' => sprintf(__('<a href="%s" target="_blank">Get an API key</a>', 'themify'), 'https://www.mailerlite.com/help/where-to-find-the-mailerlite-api-key-groupid-and-documentation#new'),
[71] Fix | Delete
'wrap_attr' => [
[72] Fix | Delete
'data-show-if-element' => '[name=setting-mailerlite_version]',
[73] Fix | Delete
'data-show-if-value' => 'new'
[74] Fix | Delete
],
[75] Fix | Delete
'wrap_class' => 'mailerlite_key_new'
[76] Fix | Delete
),
[77] Fix | Delete
);
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
private static function request($request = 'groups', $method = 'GET', $args = array()) {
[81] Fix | Delete
$args += array(
[82] Fix | Delete
'method' => $method,
[83] Fix | Delete
'headers' => array(
[84] Fix | Delete
'Content-Type' => 'application/json',
[85] Fix | Delete
),
[86] Fix | Delete
);
[87] Fix | Delete
if ( self::is_classic() ) {
[88] Fix | Delete
$args['headers']['X-MailerLite-ApiKey'] = self::get_api_key();
[89] Fix | Delete
$url = 'https://api.mailerlite.com/api/v2/' . $request;
[90] Fix | Delete
} else {
[91] Fix | Delete
$args['user-agent'] = null;
[92] Fix | Delete
$args['headers']['Authorization'] = 'Bearer ' . self::get_api_key();
[93] Fix | Delete
$url = 'https://connect.mailerlite.com/api/' . $request;
[94] Fix | Delete
}
[95] Fix | Delete
$results = wp_remote_request($url, $args);
[96] Fix | Delete
[97] Fix | Delete
if (!is_wp_error($results)) {
[98] Fix | Delete
$response = json_decode(wp_remote_retrieve_body($results), true);
[99] Fix | Delete
if (empty($response)) {
[100] Fix | Delete
return new WP_Error('empty_response', __('Empty response.', 'themify'));
[101] Fix | Delete
}
[102] Fix | Delete
if (isset($response['error'])) {
[103] Fix | Delete
return new WP_Error('error-' . $response['error']['code'], $response['error']['message']);
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
// all good!
[107] Fix | Delete
return $response;
[108] Fix | Delete
} else {
[109] Fix | Delete
return $results;
[110] Fix | Delete
}
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
protected static function request_list() {
[114] Fix | Delete
if (is_wp_error(( $data = self::request('groups')))) {
[115] Fix | Delete
return $data;
[116] Fix | Delete
}
[117] Fix | Delete
if (!empty($data) && is_array($data)) {
[118] Fix | Delete
if ( ! self::is_classic() && isset( $data['data'] ) ) {
[119] Fix | Delete
/* handle /groups request in new mailerlite */
[120] Fix | Delete
$data = $data['data'];
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
$lists = array();
[124] Fix | Delete
foreach ($data as $v) {
[125] Fix | Delete
$lists[$v['id']] = $v['name'];
[126] Fix | Delete
}
[127] Fix | Delete
return $lists;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
return new WP_Error('list_error', __('Error retrieving forms.', 'themify'));
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
/**
[134] Fix | Delete
* Gets data from module and validates API key
[135] Fix | Delete
*/
[136] Fix | Delete
public static function validate_data(array $fields_args):string {
[137] Fix | Delete
return isset($fields_args['ml_form']) ? '' : __('No campaign is selected.', 'themify');
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
*
[142] Fix | Delete
* @doc https://developers.mailerlite.com/reference#add-single-subscriber
[143] Fix | Delete
*/
[144] Fix | Delete
public static function subscribe(array $args) {
[145] Fix | Delete
$fields = array(
[146] Fix | Delete
'email' => $args['email'],
[147] Fix | Delete
'fields' => [
[148] Fix | Delete
'name' => $args['fname'],
[149] Fix | Delete
'last_name' => $args['lname'],
[150] Fix | Delete
]
[151] Fix | Delete
);
[152] Fix | Delete
if ( self::is_classic() ) {
[153] Fix | Delete
return self::request(sprintf('groups/%s/subscribers', $args['ml_form']), 'POST', array(
[154] Fix | Delete
'body' => json_encode( $fields ),
[155] Fix | Delete
));
[156] Fix | Delete
} else {
[157] Fix | Delete
$fields['groups'] = [ $args['ml_form'] ];
[158] Fix | Delete
return self::request( 'subscribers', 'POST', array(
[159] Fix | Delete
'body' => json_encode( $fields ),
[160] Fix | Delete
));
[161] Fix | Delete
}
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
/**
[165] Fix | Delete
* True: using MailerLite V1 or V2. False: using the New MailerLite
[166] Fix | Delete
*/
[167] Fix | Delete
private static function is_classic() : bool {
[168] Fix | Delete
return empty( self::get( 'mailerlite_version' ) );
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
protected static function get_api_key() :? string {
[172] Fix | Delete
$option_key = static::get_id() . '_key';
[173] Fix | Delete
if ( ! self::is_classic() ) {
[174] Fix | Delete
$option_key .= '_new';
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
return static::get( $option_key );
[178] Fix | Delete
}
[179] Fix | Delete
}
[180] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function