: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Wrapper for SendinBlue's API.
* @package ET\Core\API\Email
class ET_Core_API_Email_SendinBlue extends ET_Core_API_Email_Provider {
public $BASE_URL = 'https://api.sendinblue.com/v2.0';
public $FIELDS_URL = 'https://api.sendinblue.com/v2.0/attribute/normal';
public $LISTS_URL = 'https://api.sendinblue.com/v2.0/list';
public $SUBSCRIBE_URL = 'https://api.sendinblue.com/v2.0/user/createdituser';
public $USERS_URL = 'https://api.sendinblue.com/v2.0/user';
public $custom_fields_scope = 'account';
public $name = 'SendinBlue';
public $slug = 'sendinblue';
public $uses_oauth = false;
public function __construct( $owner, $account_name, $api_key = '' ) {
parent::__construct( $owner, $account_name, $api_key );
$this->_maybe_set_custom_headers();
protected function _maybe_set_custom_headers() {
if ( empty( $this->custom_headers ) && isset( $this->data['api_key'] ) ) {
$this->custom_headers = array( 'api-key' => $this->data['api_key'] );
protected function _process_custom_fields( $args ) {
if ( ! isset( $args['custom_fields'] ) ) {
$fields = $args['custom_fields'];
unset( $args['custom_fields'] );
foreach ( $fields as $field_id => $value ) {
if ( is_array( $value ) && $value ) {
// This is a multiple choice field (eg. checkbox, radio, select)
$value = array_values( $value );
if ( count( $value ) > 1 ) {
$value = implode( ',', $value );
$value = array_pop( $value );
self::$_->array_set( $args, "attributes.{$field_id}", $value );
public function get_account_fields() {
'label' => esc_html__( 'API Key', 'et_core' ),
public function get_data_keymap( $keymap = array() ) {
'subscribers_count' => 'total_subscribers',
'name' => 'attributes.NAME',
'last_name' => 'attributes.SURNAME',
'custom_fields' => 'custom_fields',
return parent::get_data_keymap( $keymap );
public function get_subscriber( $email ) {
$this->prepare_request( "{$this->USERS_URL}/{$email}", 'GET' );
$this->make_remote_request();
if ( $this->response->ERROR || ! isset( $this->response->DATA['listid'] ) ) {
if ( isset( $this->response->DATA['code'] ) && 'success' !== $this->response->DATA['code'] ) {
return $this->response->DATA;
public function fetch_subscriber_lists() {
if ( empty( $this->data['api_key'] ) ) {
return $this->API_KEY_REQUIRED;
if ( empty( $this->custom_headers ) ) {
$this->_maybe_set_custom_headers();
$this->prepare_request( $this->LISTS_URL, 'GET', false, $params );
$this->request->data_format = 'body';
$this->response_data_key = 'data';
parent::fetch_subscriber_lists();
if ( $this->response->ERROR ) {
return $this->response->ERROR_MESSAGE;
if ( isset( $this->response->DATA['code'] ) && 'success' !== $this->response->DATA['code'] ) {
return $this->response->DATA['message'];
$this->data['is_authorized'] = 'true';
if ( ! empty( $this->response->DATA['data']['lists'] ) ) {
$this->data['lists'] = $this->_process_subscriber_lists( $this->response->DATA['data']['lists'] );
public function subscribe( $args, $url = '' ) {
$args['list_id'] = array( $args['list_id'] );
$existing_user = $this->get_subscriber( $args['email'] );
if ( false !== $existing_user ) {
$args['list_id'] = array_unique( array_merge( $args['list_id'], $existing_user['listid'] ) );
return parent::subscribe( $args, $this->SUBSCRIBE_URL );