Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.