WordPress.org

Ready to get started?Download WordPress

Forums

ALO EasyMail Newsletter
[resolved] ALO Subscribers and WP Users (3 posts)

  1. mindctrl
    Member
    Posted 1 year ago #

    I have a case where I need to collect user info and have users categorized by interests. These "interests" are simply newsletters, but along with that I collect additional user information in the WP user profile.

    When users go through the WordPress user registration process, I'm collecting more data than the default WP setup, and along with that extra data they have the option to subscribe to newsletters using ALO Easymail on the registration screen.

    Example:

    • User registers as a WP user at /wp-login.php?action=register.
    • I collect username, password, first and last name, address, phone, etc.
    • I present Newsletter options to the user: Newsletter A, Newsletter B, Newsletter C, etc.

    No problems with any of this. But here's what I need to do and here are some questions.

    I'll need to contact users offline through postal mail and telephone. Sometimes I'll want to contact people using these offline methods who subscribe to Newsletter A, and sometimes Newsletter B, or sometimes any combination of the groups.

    I'm using ALO newsletters as a way to categorize users based on their interests. But this data isn't stored in the WP user table. If I export the list of users, I can't see the newsletters they've subscribed to. If I use the export feature in ALO, I don't get all the extra info stored in the WP user table.

    Originally I thought I could capture the newsletters selected during the user registration process using $_POST, and assign values to custom fields on the user profile.

    But I haven't been successful in doing so - perhaps because of the user doesn't really exists because it's not fully activated at that time?

    Since the ALO Subscribers screen shows the WP username if one exists, I'm now thinking it might be easier to do some sort of custom query/export that pulls the data from both tables and assembles it accordingly.

    Any ideas about what would be the best way to do what I'm needing?

    http://wordpress.org/extend/plugins/alo-easymail/

  2. eventualo
    Member
    Plugin Author

    Posted 1 year ago #

    I understand your issue.
    I wrote the following code that I hope can help you.
    The 1st function stores the mailing list IDs selected by a new user on registration into a easymail_lists user meta.
    The 2nd function is a sample to get the user meta and show values in profile.
    Then, you should write by yourself new functions for profile update etc. but I hope this can be a good starting point.

    /**
     * For each selected list in registration form, add a value in 'easymail_lists' user meta
     */
    function custom_easymail_on_registration ( $user_id ) {
    
    	// Get all available lists
    	$mailinglists = alo_em_get_mailinglists( 'public' );
    
    	if ($mailinglists && isset ($_POST['alo_em_register_lists']) && is_array ($_POST['alo_em_register_lists']) )
    	{
    		foreach ( $mailinglists as $mailinglist => $val)
    		{
    			// For each selected list add a user meta value
    			if ( in_array ( $mailinglist, $_POST['alo_em_register_lists'] ) )
    			{
    				add_user_meta( $user_id, 'easymail_lists', $mailinglist );
    			}
    		}
    	}
    }
    add_action( 'user_register', 'custom_easymail_on_registration' );
    
    /**
     * Sample function to show in profile the lists from 'easymail_lists' user meta
     */
    function custom_easymail_lists_in_profile($user) {
    
        $user_lists = get_user_meta( $user->ID, 'easymail_lists' );
    
    	if ( is_array($user_lists) )
    	{
    		echo 'Mailing lists IDs from "easymail_lists" user meta: ';
    		foreach ( $user_lists as $list ) echo $list .', ';
    		echo '<br />';
    	}
    }
    add_action( 'show_user_profile', 'custom_easymail_lists_in_profile', 100 );
    add_action( 'edit_user_profile', 'custom_easymail_lists_in_profile', 100 );
  3. mindctrl
    Member
    Posted 1 year ago #

    Alo, thanks a lot for the code. I'll work with this and see if I can make it do what I need.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic