groundhogg/create_contact_from_user

πŸ“… Published on

πŸ“ Last updated

Documentation

Β»

Action Hooks

Β»

groundhogg/create_contact_from_user

Fires after a contact is created from an existing WordPress user. Use this to copy custom user meta to the new contact record.

do_action( 'groundhogg/create_contact_from_user', $contact, $user );

You will receive the newly created Contact object as the first argument and the source WP_User as the second.

Example

add_action( 'groundhogg/create_contact_from_user', 'my_extension_copy_user_meta', 10, 2 );

/**
 * Copy a custom user meta field to the new contact record.
 *
 * @param \Groundhogg\Contact $contact
 * @param \WP_User             $user
 *
 * @return void
 */
function my_extension_copy_user_meta( $contact, $user ) {
    $account_tier = get_user_meta( $user->ID, 'account_tier', true );

    if ( $account_tier ) {
        $contact->update_meta( 'account_tier', $account_tier );
    }
}

Was this helpful?

Let us know if this document answered your question. That’s the only way we can improve.