Skip to content

Instantly share code, notes, and snippets.

@bordoni
Last active March 18, 2018 23:27
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bordoni/e25f3829a05c30747a2a to your computer and use it in GitHub Desktop.
Save bordoni/e25f3829a05c30747a2a to your computer and use it in GitHub Desktop.
Insert a new user to MailPoet and handle custom fields
<?php
// The ID of the lists you want to add a user to
$list_ids = array( 1 );
// User Data without the custom fields
$data_subscriber = array(
'user' => array(
'email' => 'johndoe@email.com',
'firstname' => 'John',
'lastname' => 'Doe',
),
'user_list' => array(
'list_ids' => $list_ids
),
);
// Insert the user to the database and return it's ID
$user_id = WYSIJA::get( 'user', 'helper' )->addSubscriber( $data_subscriber );
/**
* Possible results for $user_id
* (bool) true = User Already Exists
* (bool) false = There was an error
* (int) = The ID of the user on MailPoet's Table
*/
/**
* Here you will handle all the Custom Fields
*/
if ( is_numeric( $user_id ) ){
WJ_FieldHandler::handle_all(
array(
'cf_3' => 'Google' // Company Field on this exemple
),
$user_id
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment