Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RafaelFunchal/40ae6832eb469a1ce216 to your computer and use it in GitHub Desktop.
Save RafaelFunchal/40ae6832eb469a1ce216 to your computer and use it in GitHub Desktop.
<?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' => '[email protected]',
'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 example
),
$user_id
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment