My goal is to check if my custom user meta field 'subscribe_to_newsletter' has been changed. If so i will be sending an API call to mailchimp to change the users status.

I currently have a front end profile page that gives users an edit profile option that includes the 'subscribe_to_newsletter' meta. The fields are commited via REST API. I currently am using the following filter to catch the action:

add_filter('insert_user_meta', 'post_subscriber_mailchimp_status', 10, 3);

function post_subscriber_mailchimp_status($meta, $user, $update) 
    if(!$update) return $meta; // User first Creation

    $old_meta = get_user_meta($user->ID, 'subscribe_to_newsletter'); //old meta

    // What I would like to do...
    // Check new meta (Doesn't Exist..) vs old_meta (Exists)
    if ($meta['subscribe_to_newsletter'] == $old_meta[0])
        //...call mailchimp API

Everything works as expected when it comes to sequence of events. But the $meta variable of the new data doesn't include my custom meta field 'subscribe_to_newsletter'.

Is there a way to add my meta field to be included in the $meta variable passed to this filter? Or another possible solution all together.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.