Action uncanny-automator

automator_facebook_lead_ads_rest_api_handle_request_after

Fires after the Facebook Lead Ads REST API request is processed. Fires after the Facebook Lead Ads REST API request is processed, providing access to request data and the request object.

add_action( 'automator_facebook_lead_ads_rest_api_handle_request_after', $callback, 10, 1 );

Description

Fires immediately after the Facebook Lead Ads REST API request has been successfully processed. Developers can use this action to perform custom actions or modifications on the lead data and the request object before the response is sent back. This hook is crucial for extending functionality or integrating with other systems after a lead is submitted via Facebook.


Usage

add_action( 'automator_facebook_lead_ads_rest_api_handle_request_after', 'your_function_name', 10, 1 );

Parameters

$args (array)
{ Arguments for the action.

Examples

<?php
/**
 * Example callback for the automator_facebook_lead_ads_rest_api_handle_request_after hook.
 *
 * This function demonstrates how to access the data and request objects
 * after the initial processing of a Facebook Lead Ads REST API request.
 * It logs the received lead data for debugging purposes.
 *
 * @param array $args An array containing 'data' (the lead data) and 'request' (the WP_REST_Request object).
 */
function my_facebook_lead_ads_post_processing( $args ) {
	// Ensure we have the expected arguments.
	if ( ! isset( $args['data'] ) || ! isset( $args['request'] ) ) {
		return;
	}

	$lead_data = $args['data'];
	$request   = $args['request'];

	// Log the received lead data for debugging.
	// In a real-world scenario, you might process this data further,
	// such as creating a user, sending an email, or updating a custom field.
	error_log( 'Facebook Lead Ads Data Received: ' . print_r( $lead_data, true ) );
	error_log( 'Facebook Lead Ads Request Path: ' . $request->get_route() );

	// Example: Check if a specific field exists and process it.
	if ( isset( $lead_data['form_id'] ) ) {
		$form_id = sanitize_text_field( $lead_data['form_id'] );
		error_log( 'Processing lead from form ID: ' . $form_id );
		// Further processing based on form_id can be added here.
	}
}

// Add the callback function to the hook.
// The second parameter (10) is the priority, and the third parameter (1)
// indicates that the callback function accepts one argument (the $args array).
add_action( 'automator_facebook_lead_ads_rest_api_handle_request_after', 'my_facebook_lead_ads_post_processing', 10, 1 );

// If this were a filter hook, you would need to return the modified or original value.
// For example, if the hook was 'automator_facebook_lead_ads_modify_data_before_save':
/*
function my_facebook_lead_ads_modify_data( $data ) {
    // Modify $data here
    return $data;
}
add_filter( 'automator_facebook_lead_ads_modify_data_before_save', 'my_facebook_lead_ads_modify_data', 10, 1 );
*/

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/integrations/facebook-lead-ads/utilities/rest-api.php:132

* @param array $args {
		 *     Arguments for the action.
		 *
		 *     @type array          $data    Data received in the request.
		 *     @type WP_REST_Request $request The REST API request object.
		 * }
		 */
		do_action( 'automator_facebook_lead_ads_rest_api_handle_request_after', $args );

		// Your processing logic here.
		return rest_ensure_response(
			array(
				'code'    => 'rest_success',
				'message' => esc_html_x( 'Data processed successfully.', 'Facebook Lead Ads', 'uncanny-automator' ),
				'data'    => $data,

Internal Usage

Found in src/integrations/facebook-lead-ads/triggers/lead-created.php:48:

$this->add_action( 'automator_facebook_lead_ads_rest_api_handle_request_after', 10, 1 );
Scroll to Top