The Agile Sync Addon supports several powerful WordPress filters that allow developers to:
- Transform API responses
- Modify endpoints and headers
- Handle pagination
- Map external data into the Agile Store Locator format
Use these filters to customize your synchronization logic when working with platforms like Salesforce, Google Sheets, and REST APIs.
Filters #
1. asl_sync_data_row_mapping #
Transform each data record before it’s saved into the store database.
add_filter('asl_sync_data_row_mapping', function ($store_inst, $data_row) {
// Convert "yes" to true boolean
if (isset($store_inst['is_disabled'])) {
$store_inst['is_disabled'] = (strtolower($store_inst['is_disabled']) === 'yes') ? 1 : 0;
}
// Example: build Facebook URL
if (isset($data_row['facebookVanityUrl'])) {
$store_inst['custom-facebook_url'] = "https://www.facebook.com/" . esc_attr($data_row['facebookVanityUrl']) . "/";
}
return $store_inst;
}, 10, 2);
Params:
$store_inst
: The processed store data array.$data_row
: The original raw API data row.
2. asl_sync_prepare_endpoint #
Customize or append query parameters to the API endpoint before the request is sent.
add_filter('asl_sync_prepare_endpoint', function ($endpoint_url) {
$endpoint_url .= '&filter={"meta.folderId":{"$eq":"112810"}}';
return $endpoint_url;
});
3. asl_sync_logo_url #
Update or override the logo URL used during the sync process.
add_filter('asl_sync_logo_url', function ($logo_url, $handler) {
return str_replace('http://', 'https://', $logo_url);
}, 10, 2);
4. asl_sync_endpoint #
Modify the final API endpoint using full sync config context.
add_filter('asl_sync_endpoint', function ($endpoint, $config) {
return $endpoint . '?apikey=' . $config['sync_key'];
}, 10, 2);
5. asl_sync_request_data #
Alter the request payload (body) before it is sent to the API.
add_filter('asl_sync_request_data', function ($data, $config) {
$data['region'] = 'Middle East';
return $data;
}, 10, 2);
6. asl_sync_request_headers #
Customize or add headers to the outgoing API request.
add_filter('asl_sync_request_headers', function ($headers, $config) {
$headers['Authorization'] = 'Bearer ' . $config['bearer_token'];
return $headers;
}, 10, 2);
7. asl_sync_api_request_params #
Modify the full set of parameters used in the request.
add_filter('asl_sync_api_request_params', function ($params) {
$params['timeout'] = 30;
return $params;
});
8. asl_sync_raw_response #
Filter or log the raw response before it’s parsed or mapped.
add_filter('asl_sync_raw_response', function ($response, $params) {
error_log(print_r($response, true));
return $response;
}, 10, 2);
9. asl_sync_request_pagination #
Add logic to recursively fetch all pages from a paginated API.
add_filter('asl_sync_request_pagination', function ($responseData, $apiClient, $params) {
$all = $responseData['response']['entities'];
$max = 10;
while (isset($responseData['response']['pageToken']) && $max-- > 0) {
$params['endpoint'] .= '&pageToken=' . $responseData['response']['pageToken'];
$responseData = $apiClient->makeApiRequest($params);
if (isset($responseData['response']['entities'])) {
$all = array_merge($all, $responseData['response']['entities']);
}
}
$responseData['response']['entities'] = $all;
return $responseData;
}, 10, 3);
10. asl_sync_completed_event (Action) #
Run custom logic after a sync completes.
add_action('asl_sync_completed_event', function ($sync_key, $settings) {
// Send admin notification or log sync summary
});
11. asl_sync_skip_data_row #
To create a criteria to skip certain rows from import based on condition.
add_filter('asl_sync_skip_data_row', function ($should_skip, $row, $sync_id) {
// Skip if the Sync_To_Store_Listing__c flag is missing or not true
if (!isset($row['Sync_To_Store_Listing__c']) || strtolower($row['Sync_To_Store_Listing__c']) !== 'true') {
return true; // Skip this record
}
return false; // Sync this record
}, 10, 3);
Developer Notes #
- Use filters inside a custom plugin or your theme’s
functions.php
. - Always validate and sanitize external data before saving.
- Test filters with a manual sync run using the “Run Sync Now” button.
Need Help? #
For custom integration support or additional hooks, reach out at support@agilelogix.com