automator_outgoing_webhook_request_type
Filters the HTTP request type for outgoing webhooks, allowing modification of the default GET method.
add_filter( 'automator_outgoing_webhook_request_type', $callback, 10, 1 );
Description
Modify the HTTP request method for outgoing webhooks. This filter fires before the webhook request is sent, allowing you to change the default 'GET' method to POST, PUT, DELETE, or any other valid HTTP verb. Use this to control how your automations interact with external services.
Usage
add_filter( 'automator_outgoing_webhook_request_type', 'your_function_name', 10, 1 );
Parameters
-
$data(mixed) - This parameter is the HTTP request method to be used for the webhook.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the automator_outgoing_webhook_request_type filter.
* This filter allows you to dynamically change the HTTP request method based on specific data.
* For instance, you might want to use 'POST' for creating new resources and 'PUT' for updating existing ones.
*
* @param string $request_type The current HTTP request type ('GET', 'POST', 'PUT', 'PATCH', etc.).
* @param array $data The data being sent in the webhook request.
*
* @return string The modified HTTP request type.
*/
function my_custom_automator_webhook_request_type( $request_type, $data ) {
// Check if the data array has a key that indicates an update operation.
// For example, if 'id' is present, it might imply an update.
// You would replace 'id' with the actual key used in your automator setup
// to signify an update operation.
if ( isset( $data['record_id'] ) && ! empty( $data['record_id'] ) ) {
// If a record ID is present, change the request type to 'PUT' for updates.
return 'PUT';
} elseif ( isset( $data['ACTION_EVENT'] ) && 'CREATE_USER' === $data['ACTION_EVENT'] ) {
// Example: If the action event is specifically for creating a user, ensure it's POST.
return 'POST';
}
// Otherwise, return the original request type.
return $request_type;
}
add_filter( 'automator_outgoing_webhook_request_type', 'my_custom_automator_webhook_request_type', 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:321
src/core/lib/webhooks/class-automator-send-webhook.php:324
src/core/lib/webhooks/class-automator-send-webhook.php:327
src/core/lib/webhooks/class-automator-send-webhook.php:330
src/core/lib/webhooks/class-automator-send-webhook.php:333
src/core/lib/webhooks/class-automator-send-webhook.php:336
src/core/lib/webhooks/class-automator-send-webhook.php:340
src/core/lib/webhooks/class-automator-send-webhook.php:343
src/core/lib/webhooks/class-automator-send-webhook.php:349
src/core/lib/webhooks/class-automator-send-webhook.php:352
public function request_type( $data ) {
switch ( $data['ACTION_EVENT'] ) {
case 'GET':
$request_type = apply_filters( 'automator_outgoing_webhook_request_type', 'GET', $data );
break;
case 'PUT':
$request_type = apply_filters( 'automator_outgoing_webhook_request_type', 'PUT', $data );
break;
case 'PATCH':
$request_type = apply_filters( 'automator_outgoing_webhook_request_type', 'PATCH', $data );
break;
case 'DELETE':
$request_type = apply_filters( 'automator_outgoing_webhook_request_type', 'DELETE', $data );
break;
case 'HEAD':
$request_type = apply_filters( 'automator_outgoing_webhook_request_type', 'HEAD', $data );
break;
case 'OPTIONS':
$request_type = apply_filters( 'automator_outgoing_webhook_request_type', 'OPTIONS', $data );
break;
case 'automator_custom_value':
if ( isset( $data['ACTION_EVENT_custom'] ) ) {
$request_type = apply_filters( 'automator_outgoing_webhook_request_type', $data['ACTION_EVENT_custom'], $data );
break;
}
$request_type = apply_filters( 'automator_outgoing_webhook_request_type', 'POST', $data );
break;
case 'POST':
case 'CUSTOM':
default:
if ( 'POST' !== $data['ACTION_EVENT'] && isset( $data['ACTION_EVENT_custom'] ) ) {
$request_type = apply_filters( 'automator_outgoing_webhook_request_type', $data['ACTION_EVENT_custom'], $data );
break;
}
$request_type = apply_filters( 'automator_outgoing_webhook_request_type', 'POST', $data );
break;
}
return $request_type;
}