• Is it possible to pre-populate a users information and interest groups when they’re modifying their preferences? We have the form not display unless they’re logged in, so we know that the user has been validated so it’s not a security risk to prepopulate this data. Is it possible to do so?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hello @glimmernet,

    Unfortunately this is not possible to do out-of-the-box. We have some filters in place where you can change the default value of a field. However, any field except email would have to be retrieved from the MailChimp API. It’s a big task to accomplish, even with filters.

    I’m sorry about that.

    All the best,
    Kevin.

    Thread Starter Glimmernet Technologies

    (@glimmernet)

    Kevin,

    Thanks for the quick reply. That would certainly be a useful option for a future update to the plugin.

    Is it possible to pull the Mail Chimp URL that is sent to them via email and display that to the logged in user so that they can go to MC without having to get the email first?

    Dave

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi Dave,

    I think I can try to do that for you 🙂

    My approach would be to add the URL and a sentence or two of text at the top of the form very similar to how it works when an already subscribed user tries to resubscribe. I’ll let you know if I hit any stumbling blocks.

    Kevin.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi Dave,

    I just wrote up this snippet. I am not sure how familiar you are with PHP so I will walk through each step.

    The first thing we do is grab our MailChimp list. We’ll need this for subscriptions. The second thing we do is grab the email of the currently logged in user. The third thing we do is check if the user is already subscribed (we ping the MailChimp API). The fourth thing we do is a check to see if the user is already subscribed, the user has an email, and our list id was not empty. If all of these things look good, we create a link with some text in it “Click here to update your profile.”

    At the moment there is no feedback after clicking the link which makes it a bit awkward but I figured you could test this snippet now and come back to me with any feedback you have.

    add_action( 'yikes-mailchimp-before-form', 'add_update_user_profile_link_above_form', 10, 1 );
    
    function add_update_user_profile_link_above_form( $form_id ) {
    
    	$html = '';
    
    	// Get the list ID
    	$interface = yikes_easy_mailchimp_extender_get_form_interface();
    	$form_data = $interface->get_form( $form_id );
    	$list_id   = isset( $form_data['list_id'] ) ? $form_data['list_id'] : '';
    
    	// Get the current user's email
    	$user = wp_get_current_user();
    	$email = is_object( $user ) && isset( $user->data ) && is_object( $user->data ) && isset( $user->data->user_email ) ? $user->data->user_email : '';
    
    	// Check if the current user is subcribed
    	$list_handler = yikes_get_mc_api_manager()->get_list_handler();
    	$member_exists = $list_handler->get_member( $list_id, md5( strtolower( $email ) ), $use_transient = true );
    
    	// Make sure we have the list ID, the email, and the form id
    	if ( ! is_wp_error( $member_exists ) && ! empty ( $email ) && ! empty( $list_id ) && ! empty( $form_id ) ) {
    		$html .= '<a class="send-update-email" data-form-id="' . $form_id . '" data-list-id="' . $list_id . '" data-user-email="' . $email . '" href="#">';
    		$html .= 'Click here to update your profile.';
    		$html .= '</a>';
    	}
    
    	echo $html;
    }

    This snippet should be placed into your functions.php file.

    Let me know how that goes.

    All the best,
    Kevin.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Populate User Data When Updating Preferences’ is closed to new replies.