[e-Newsletter] eNewsletter add member to group via php

Hello
I want to be able to add users to a member group in e-newsletter via code
Is there an easy way to do that?
Best
/Cristina

  • Konstantinos Xenos
    • Rubber Duck Debugger

    Hi Cristina Krügnell ,

    You can add as many user's to groups as you like as long as you know their e-mails at least. As an example snippet this would be something that you could integrate to your code:

    if ( class_exists( 'Email_Newsletter' ) ) {
    
    	$nsltr = new Email_Newsletter();
    
    	$member = $nsltr->get_member_by_email( 'some@e-mail.test' );
    
    	$members = array(
    		$member['member_id'],
    	);
    
    	$groups = array(
    		1,
    	);
    
    	$nsltr->add_members_to_groups( $members, $groups );
    }

    It is using the get_member_by_email() to find the members ID ( note that they have to be already Subscribers ) and then the add_members_to_groups() to add the member's that you like into the groups you want. The add_members_to_groups() supports both members & groups as arrays so you can add multiple members into multiple groups in 1 run as well.

    This should most likely be added on a custom plugin or mu-plugin of yours to fist gather the array of member IDs that you like and then run the above snippet that will complete this utility :slight_smile: .

    Tell me if you need further help with this!

    Regards,
    Konstantinos

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.