Updates an existing contact from an associative array of field values and a field map. This is a convenience wrapper around generate_contact_with_map() that makes the update intent explicit. Accepts a Contact object, a contact ID, or an email address as the first argument.
Parameters
| Parameter | Type | Description |
|---|---|---|
$contact | Contact|int|string | The contact to update — accepts a Contact object, ID, or email. |
$fields | array | Associative array of raw field data. |
$map | array | Field map (source key → Groundhogg field key). If empty, field keys are used directly. |
$submission | array | Optional submission-level settings. |
Return value
Contact|false — The updated Contact object, or false on failure.
Usage
\Groundhogg\update_contact_with_map( $contact, [
'job_title' => 'Senior Developer',
'city' => 'Toronto',
] );
Example
Here’s a pseudo code example for a hypothetical CRM sync integration.
add_action( 'my_crm_record_updated', 'my_plugin_sync_update_to_groundhogg', 10, 2 );
/**
* Push updated fields from an external CRM to the matching Groundhogg contact.
*
* @param string $email
* @param array $updated Key/value pairs of updated fields from the external CRM.
*
* @return void
*/
function my_plugin_sync_update_to_groundhogg( $email, $updated ) {
$contact = \Groundhogg\get_contactdata( $email );
if ( ! $contact ) {
return;
}
$map = [
'FirstName' => 'first_name',
'LastName' => 'last_name',
'PhoneNumber' => 'phone_number',
'Company' => 'company_name',
'JobTitle' => 'job_title',
];
\Groundhogg\update_contact_with_map( $contact, $updated, $map );
}
Was this helpful?
Let us know if this document answered your question. That’s the only way we can improve.
