Developer Hooks & Filters
The Object Data Sync for Salesforce plugin provides several WordPress hooks that allow developers to customize and extend the plugin's functionality during the record synchronization process between Salesforce and WordPress.
This page covers the available action hooks and filters you can use to modify sync behavior, transform data, and add custom functionality.
Available Hooks
1. mo_sf_sync_after_object_upsert
Hook Type: Action Hook
Description: Fires after a Salesforce record has been successfully synced (inserted or updated) in WordPress. Use this hook to perform post-sync operations such as logging, triggering workflows, or updating related data.
When It Triggers: Immediately after the WordPress record has been created or updated based on the Salesforce data.
Parameters:
$wp_object(string) - WordPress Object Type (e.g., 'post', 'user')$wp_upsert_object_id(string|int) - WordPress Record ID that was synced$sf_object(string) - Salesforce Object Type (e.g., 'Contact')$field_map(array) - Field mapping configuration used in this sync$record(array|object) - Complete Salesforce record data
Hook Definition:
/**
* Fires after the Salesforce record has been synced to WordPress.
*
* @param string $wp_object WordPress Object Type (e.g., 'post', 'user').
* @param string|int $wp_upsert_object_id WordPress Record ID synced.
* @param string $sf_object Salesforce Object Type (e.g., 'Contact').
* @param array $field_map Field mapping used in this sync.
* @param array|object $record Salesforce record received from Salesforce.
*/do_action( 'mo_sf_sync_after_object_upsert', $wp_object, $wp_upsert_object_id, $sf_object, $field_map, $record );
Example Usage:
add_action( 'mo_sf_sync_after_object_upsert', 'custom_post_sync_operations', 10, 5 );
function custom_post_sync_operations( $wp_object, $wp_id, $sf_object, $field_map, $record ) {
error_log("Salesforce {$sf_object} record (ID: {$record['Id']}) synced to WordPress {$wp_object} with ID {$wp_id}.");
}
2. mo_sf_sync_pre_data_send
Hook Type: Filter
Description: Allows you to modify the data received from Salesforce before it is saved to WordPress. Use this filter to sanitize, transform, or augment WordPress field values before insertion or update.
When It Triggers: After Salesforce data has been mapped to WordPress fields, but before creating or updating the WordPress record.
Parameters:
$data_to_store(array) - Associative array of WordPress fields and their values
Returns: (array) Modified data array to be saved to WordPress
Hook Definition:
/**
* Filter the record data before saving to WordPress.
*
* @param array $data_to_store Associative array of WordPress fields and their values.
* @return array Modified data array to be saved.
*/$data_to_store = apply_filters( 'mo_sf_sync_pre_data_send', $data_to_store );
Example Usage:
add_filter( 'mo_sf_sync_pre_data_send', 'normalize_phone_number' );
function normalize_phone_number( $data ) {
if ( isset( $data['phone'] ) ) {
$data['phone'] = preg_replace('/\D+/', '', $data['phone']);
}
return $data;
}
3. mo_sf_sync_after_date_conversions
Hook Type: Filter
Description: Allows you to modify or transform a date value (in Y-m-d format) received from Salesforce before it is saved as WordPress metadata. Use this hook to adjust date formats, apply timezone changes, or convert DateTime objects.
When It Triggers: After a valid Y-m-d date string from Salesforce has been parsed into a DateTime object, but before the value is saved as post/user/custom post meta in WordPress.
Parameters:
$dt(DateTime) - Parsed DateTime object from a Salesforce date field
Returns: Modified (mixed) date value to be saved. You can return any format suitable for saving as a meta value
Hook Definition:
/**
* Filter a parsed DateTime object from a 'Y-m-d' formatted string before saving it to WordPress.
*
* @param \DateTime $dt Parsed DateTime object from a Salesforce date field.
* @return mixed Modified date value to be saved. You may return:
* - A formatted string (e.g., with timezone or localized)
* - A DateTime object
* - Any format suitable for saving as a meta value
*/$new_value = apply_filters( 'mo_sf_sync_after_date_conversions', $dt );
Example Usage:
add_filter( 'mo_sf_sync_after_date_conversions', 'convert_date_to_display_format' );
function convert_date_to_display_format( $dt ) {
return $dt->format( 'F j, Y' ); // e.g., "July 17, 2025"
}
4. mo_sf_sync_wp_to_sf_sync_body
Hook Type: Filter
Description: This filter allows developers to modify the request body ($new_map) before it is sent from WordPress to Salesforce during a sync operation. You can use it to apply conditional logic, transform fields, or map custom fields dynamically.
When It Triggers: It triggers just before the WordPress object data is sent to Salesforce during a WordPress to Salesforce sync operation.
Parameters:
$new_map(array) - The request body (data map) that will be sent to Salesforce.$wp_object(string) - The WordPress object type being synced (e.g., 'post', 'user').$object(string) - The Salesforce object name being synced (e.g., 'Lead', 'Contact').
Returns: (array) The modified request body that will be sent to Salesforce
Hook Definition:
/**
* Filters the data before it is synced from WordPress to Salesforce.
*
* This filter allows developers to modify or extend the request body ($new_map)
* before it is sent to Salesforce during a WordPress → Salesforce sync operation.
* It provides the request body, the WordPress object name, and the Salesforce
* object name, allowing conditional logic, field transformations, or custom
* field mappings.
*
* @param array $new_map The request body (data map) that will be sent to Salesforce.
* @param string $wp_object The WordPress object name being synced (e.g., 'post', 'user').
* @param string $object The Salesforce object name being synced (e.g., 'Lead', 'Contact').
*
* @return array The modified request body to be synced to Salesforce.
*/$new_map = apply_filters('mo_sf_sync_wp_to_sf_sync_body', $new_map, $wp_object, $object);
Example Usage:
add_filter('mo_sf_sync_wp_to_sf_sync_body', 'custom_wp_to_sf_data', 10, 3);
function custom_wp_to_sf_data($new_map, $wp_object, $object) {
// Example: Add a custom field for Salesforce Lead
if ($object === 'Lead' && $wp_object === 'user') {
$new_map['Custom_Field__c'] = 'Custom Value';
}
// Example: Modify post title before syncing
if ($object === 'Contact' && $wp_object === 'post') {
$new_map['Title'] = strtoupper($new_map['Title']);
}
return $new_map;
}Note: These hooks provide powerful customization options for developers who need to extend the plugin's synchronization behavior. Always test your custom implementations in a development environment before deploying to production.
For more information visit our Object Data Sync for Salesforce page or mail us at salesforcesupport@xecurify.com.