
It’s easy to assign subscribers to list with the UI of Mailster. Just select the subscribers you like to assign and select the option from the drop down. To get more specific you need to add some custom code to your website.
There are many situations where you like to move a user to a certain lists. In any case you need two methods:
mailster( 'subscribers' )->assign_lists( $subscriber_ids, $lists );
to add lists to your subscribers and
mailster( 'subscribers' )->unassign_lists( $subscriber_ids, $lists );
$subscriber_ids
can either be a single ID of one of your subscribers or an array of IDs.
$lists
can either be a single ID of one of your lists or an array of IDs.
Assign a list after clicking a link
Lets assign the subscriber who clicks on the link to “http://example.com” to the List with ID 1.
add_action( 'mailster_click', function( $subscriber_id, $campaign_id, $target, $index ) { $list_id = 1; if ( $target == 'http://example.com' ) { mailster( 'subscribers' )->assign_lists( $subscriber_id, $list_id ); } }, 10, 4);
Assign two lists after opening a specific campaign
Lets assign the subscriber from a specific campaign (ID 12) to the List with ID 1 and 2 one the campaign was sent.
add_action( 'mailster_open', function( $subscriber_id, $campaign_id ) { $list_id = array(1, 2); if ( $campaign_id == 12 ) { mailster( 'subscribers' )->assign_lists( $subscriber_id, $list_id ); } }, 10, 2);
Assign two lists after a specific campaign was sent
Lets assign the subscriber who opens a specific campaign (ID 12) to the List with ID 1 and 2.
add_action( 'mailster_send', function( $subscriber_id, $campaign_id, $result ) { $list_id = array(1, 2); if ( $campaign_id == 12 ) { mailster( 'subscribers' )->assign_lists( $subscriber_id, $list_id ); } }, 10, 3);
Moving a subscriber from one list to another after a certain action
Since we don’t know the current subscriber we have to get it from the current WordPress User. This requires an existing WordPress user with matching Mailster Subscriber.
add_action( 'my_custom_action', function( ) { if( $subscriber = mailster( 'subscribers' )->get_by_wpid() ){ $list_id_from = 1; $list_id_to = 2; mailster( 'subscribers' )->unassign_lists( $subscriber->ID, $list_id_from ); mailster( 'subscribers' )->assign_lists( $subscriber->ID, $list_id_to ); } });