special offer desktop
menu-icon
Bit Assist Menu Icon
Estimated reading: 3 minutes 425 views

Bit Integrations with Custom Action

This feature helps WordPress developers, who want to run a custom PHP function. Developers can easily run their own php function. Follow the steps using the custom action.

To integrate with Custom Action follow, the below steps.

  1. Search & Select Custom Action from the actions pages
search-select
  1. write an initial PHP procedure that is not static and has no access modifier.
write-function
  1. You can access form field values by using the syntax $trigger[], which will then display a drop-down menu with the list of form fields that can be selected.
  2. After writing the function, you must invoke the function.
  3. Then click the Validate button to validate the function. This validation process will check only syntax errorsnot logical errors.
validate-function
  1. After the validation is complete of function, Click on Next to set up the other integration settings ahead.
validate-and-next
  1. Now save the integration by clicking the Finish & Save Button
finish-and-save
  1. At Bit Integrations, the Timeline of each integration contains a feature allowing you to quickly view the status of your integration, whether it has been successful or encountered an error.
timeline-log
  1. You can also easily editClone, or delete the integration.
integration-option

Congratulations, your integration process has been completed successfully. Once the trigger is executed, the function will run successfully.

Custom Action examples

Custom Action has multiple use cases. Here are two examples showing how to work “Custom Action” Does.

Data Field Mapping

Data Field Mapping
  1. Mapped data according to field keywords
  2. Keywords came from the trigger that you received at the top

Nested Data Field Mapping

  1. Defined an empty array
  2. Fill the array with your data fields
Nested Data Field Mapping

Find the keywords

If you don’t know what kind of data you received from the trigger & and don’t know the keywords then you send your whole trigger into API or HOOK and find the keywords from the output result.

HOOK

Custom Action HOOK

API

Custom action API

Use Cases Example

  1. Data sent into the hook
  2. Data sent into API

Use Cases #1: Data sent into the hook

  1. Map data
  2. Define the hook
  3. Put mapped data into the hook
Use Cases 1 Data sent into the hook

Use Cases #2: Data sent into the API

  1. Define API URL/Endpoint
  2. Initialize cURL session including URL
  3. Set cURL options according to your requirements
  4. Attach mapped data in the cURL options
  5. Execute cURL & and close it
Use Cases 2 Data sent into the API
Use Cases 2 Data sent into the API 1

Demo Code

<?php if (!defined('ABSPATH')) {
    exit;
}

function yourFunctionName($trigger)
{
    // defiend an empty array
    $data = [];

    // map Data
    $data['your-key'] = $trigger['your-key'];

    // API URL
    $url = "Your API URL"; // add your API URL

    // Initialize cURL session
    $ch = curl_init($url); 

    // Set CURL options
    curl_setopt($ch, CURLOPT_POST, true); // initial method is POST, you should replace as your requirement
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // Attach encoded data
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the output as a string
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json', // Set content type to JSON
        // Add other headers if required
    ));

    // response stored in a variable
    $response = curl_exec($ch);
    curl_close($ch);
}

yourFunctionName($trigger);
Share this Doc

Custom Action Integrations

Or copy link

CONTENTS