Filter
uncanny-automator
automator_send_webhook_data_tree_required
Filters the allowed data types for sending webhook data, allowing customization of accepted formats like JSON, graph, or XML.
add_filter( 'automator_send_webhook_data_tree_required', $callback, 10, 1 );
Description
Filters whether Automator should prepare nested array data for webhooks. Allows developers to override default behavior, specifying which data types ('json', 'graph', 'xml') necessitate tree preparation. Use this to customize how complex data structures are sent via webhooks.
Usage
add_filter( 'automator_send_webhook_data_tree_required', 'your_function_name', 10, 1 );
Parameters
-
$data_type(mixed) - This parameter is a list of data types for which a tree structure is considered essential for webhook data.
Return Value
The filtered value.
Examples
/**
* Example callback for the 'automator_send_webhook_data_tree_required' filter.
*
* This callback demonstrates how to conditionally modify the array of data types
* for which Automator should prepare nested arrays when sending webhooks.
* In this example, we'll add 'csv' to the list if the webhook is for a specific
* external service, perhaps indicating it requires a more structured format.
*
* @param array $required_for The default array of data types that require nested array preparation.
* @param string $data_type The current data type being processed by the webhook.
*
* @return array The modified array of data types requiring nested array preparation.
*/
function my_automator_webhook_tree_required_callback( $required_for, $data_type ) {
// Check if the current data type is 'csv' or if it's another specific type
// that we want to ensure is prepared with nested arrays for webhooks.
// For instance, maybe we are sending data to a third-party CRM that specifically
// benefits from structured nested data for its import process.
if ( 'csv' === $data_type || 'crm_integration' === $data_type ) {
// Add 'csv' and 'crm_integration' to the list if they are not already present.
// This ensures that even if the default doesn't include them, our custom logic will.
if ( ! in_array( 'csv', $required_for, true ) ) {
$required_for[] = 'csv';
}
if ( ! in_array( 'crm_integration', $required_for, true ) ) {
$required_for[] = 'crm_integration';
}
}
// It's also possible to remove types if needed, for example:
// if ( 'legacy_api' === $data_type && in_array( 'xml', $required_for, true ) ) {
// $required_for = array_diff( $required_for, array( 'xml' ) );
// }
// Always return the potentially modified array.
return $required_for;
}
// Add the filter callback with the correct number of accepted arguments (2).
// The priority is set to 10, which is the default.
add_filter( 'automator_send_webhook_data_tree_required', 'my_automator_webhook_tree_required_callback', 10, 2 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/core/lib/webhooks/class-automator-send-webhook.php:663
private function is_tree_required( $data_type ) {
$required_for = apply_filters(
'automator_send_webhook_data_tree_required',
array(
'json',
'graph',
'xml',
),
$data_type
);
if ( in_array( $data_type, $required_for, true ) ) {
return true;
}
return false;
}