Last active
March 18, 2018 23:27
-
-
Save bordoni/e25f3829a05c30747a2a to your computer and use it in GitHub Desktop.
Insert a new user to MailPoet and handle custom fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 exemple | |
), | |
$user_id | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment