What are Actions?
Actions are “things” that happen on your WordPress website such as publishing a new post, a WooCommerce order is updated, a new user is registered, a new product is added, a form is submitted and so on.
Actions are a no-code automation tool, allowing you to automate sending data to your APIs.
If you can’t find the action you need, just let us know and we will add it to the plugin.
Actions Integrations
Actions can be run on many core WordPress actions as well as popular WordPress plugins such as:
- WooCommerce
- Easy Digital Downloads
- Paid Memberships Pro
- Fluent Forms
- Elementor Forms
- Gravity Forms
- Contact Form 7
- Formidable Forms
- JetFormBuilder
- WPForms
How do Actions work?
After installing the PRO plugin, you will see a new field within each endpoint called Actions. Select your Action and hit save, and then every time that particular Action happens on your site, your endpoint will be called.
Some Actions contain extra fields which will appear once you select that Action. These extra fields give you further configuration options.
All Actions run in the background, so an action is best used when you need to send data to an API via POST, PUT, DELETE or PATCH methods. An Action will not display API data to the user.
Sending values related to the Action
When an Action is run, there will be values related to the Action that can be sent to your API.
For example, the ‘User – New User Registered‘ Action contains all user data related to the user that just registered. To get access to these values, we use a token that starts with the word ‘action’ and looks something like this:
- (action:data:user_email) – this token gets the users email address
Below is a look at some of the values we have access to when a user registers.
[
"data" => [
"user_login" => "fdasdfffdfaaaa",
"user_pass" => "-- sensitive value hidden --",
"user_email" => "[email protected]",
"role" => "customer"
]
]
To get the ‘role’ value we simply need to use this token: (action:data:role)
These action tokens can be added within the Body POST fields, Headers, Query String or Endpoint.
The Action Log
Each time an Action runs, a log entry will be created on the Actions Log page. This log can assist with troubleshooting and for viewing the data available to send to your API.
This log gives you the following information:
- The time and date the action was run and the name of the action.
- ACTION DATA :: The values from with the Action.
- API ID :: The ID of the API that was called.
- ENDPOINT ID :: The ID of the endpoint that was called.
- SENT TO API :: The actual values that were sent to your API.
- API RESULT :: The data that was returned from the API.
Modify action values before sending to API
To modify or format a value before sending to your API, you can use the below hook.
Note that the $action value needs to be the name of your Action. You can find the name of the action within the Actions Log.
/**
* Filter that can be run before calling API.
* Allows us to stop before doing the endpoint or to modify values before sending.
*
* example: 'wpgetapi_argument_values_before_woocommerce_order_status_changed' or 'wpgetapi_argument_values_before_contact_form_7_57685'
*
* @param array $action_args the values from the action
* @param array $endpoint the endpoint setting values
*
*/
$argument_values['action_args'] = apply_filters( 'wpgetapi_argument_values_before_' . $action, $argument_values['action_args'], $endpoint );
The snippet below modifies a certain value within an Action. In this case we are using the ‘woocommerce_order_status_changed’ action and we are modifying the ‘number’ field and also rounding the ‘subtotal’ field within each line item.
function wpgetapi_modify_action_values( $args, $endpoint ) {
// set a custom value to 'number'
$args['number'] = 'add some custom number here';
// round each line item subtotal
if( isset( $args['line_items'] ) ) {
foreach ( $args['line_items'] as $i => $line_item ) {
if( isset( $line_item['subtotal'] ) )
$args['line_items'][ $i ]['subtotal'] = round( $line_item['subtotal'], 2 );
}
}
return $args;
}
add_filter( 'wpgetapi_argument_values_before_woocommerce_order_status_changed', 'wpgetapi_modify_action_values', 10, 2 );
Using the data returned from the API
Sometimes you may need to get the data that is returned from the API and save this within your database, or use this data in some other way.
The below hook can be used to achieve this. Note that the $action value needs to be the name of your Action which in this case is user_register. You can find the name of the action within the Actions Log.
/**
* Actions that can be run after calling API
* example: 'wpgetapi_after_user_register'
*
* @param array|string $result the data returned from the API
* @param array $data the values from the action
* @param array $values_sent the values sent to the API
* @param array $endpoint the endpoint settings
*
*/
do_action( 'wpgetapi_after_' . $action, $result, $data, $values_sent, $endpoint );
Let’s say you are using the ‘User – New User Registered‘ action which sends the users name and email address to your CRM and your CRM then creates a new customer in the CRM system. If the customer is successfully created, the CRM simply returns the customer ID and you then want to save that customer ID within a user_meta field.
You can add a snippet like the below to achieve this. Note that this code will need to be modified to suit your own requirements! This is just a simple example.
function wpgetapi_save_customer_id( $result, $data, $values_sent, $endpoint ) {
if( isset( $result['customer_id'] ) ) {
$user_id = $data['data']['ID'];
add_user_meta( $user_id, 'crm_customer_id', $result['customer_id'] );
}
}
add_filter( 'wpgetapi_after_user_register', 'wpgetapi_save_customer_id', 10, 4 );
List of Actions and their values
Here we will look at each of the Actions that are available and the values that we can get when running the Action.
User – New User Registered
This action runs each time a user is registered on the site. Below is an example of the values associated with this action.
array (
'data' => array(
'user_login' => 'Test Username',
'user_email' => '[email protected]',
'user_pass' => 'xxxxxxxxxx',
'meta' => array(
'custom_value1' => 'stuff',
'custom_value2' => 'some data',
'another_one' => 'something',
)
)
)
To get the ‘custom_value1’ value within this array, we would use a token like this: (action:data:meta:custom_value1) which would return the value of ‘stuff’.
User – User Logs In
This action runs each time a user logs into the site. Below is an example of the values associated with this action.
Note that the users password cannot be retrieved here due to security restrictions of WordPress – there is no workaround for this.
array (
'data' => array (
'ID' => '70',
'user_login' => 'Test User',
'user_nicename' => 'Bob Smith',
'user_email' => '[email protected]',
'user_url' => '',
'user_registered' => '2023-07-10 04:45:33',
'user_status' => '0',
'display_name' => 'Bob',
.
.
.
),
'caps' => array (
'subscriber' => true,
),
'meta' => array (
'locale' => '',
'wp_user_level' => '0',
'last_update' => '1688964334',
'wc_last_active' => '1688947200',
.
.
.
),
)
To get the ‘user_email’ value within this array, we would use a token like this: (action:data:user_email)
User – Delete User
This action runs each time a user is deleted from your site. Below is an example of the values associated with the action.
array (
'data' => array (
'ID' => '70',
'user_login' => 'Test User',
'user_nicename' => 'Bob Smith',
'user_email' => '[email protected]',
'user_url' => '',
'user_registered' => '2023-07-10 04:45:33',
'user_status' => '0',
'display_name' => 'Bob',
.
.
.
),
'caps' => array (
'subscriber' => true,
),
'meta' => array (
'locale' => '',
'wp_user_level' => '0',
'last_update' => '1688964334',
'wc_last_active' => '1688947200',
.
.
.
),
)
To get the ‘user_email’ value within this array, we would use a token like this: (action:data:user_email)
Post/Custom Post – New Post Published
This action runs each time a new post transitions to the ‘publish’ status. It won’t run when an already published post is updated.
Works with any post, page or custom post type and this is selectable.
Below is an example of the values associated with this action.
[
"ID" => 61003,
"post_author" => "1",
"post_date" => "2023-07-18 12:04:46",
"post_date_gmt" => "2023-07-18 02:04:46",
"post_title" => "asdf dsaf",
"post_status" => "publish",
"comment_status" => "open",
"ping_status" => "open",
"post_name" => "asdf-dsaf",
"post_modified" => "2023-07-18 12:04:46",
"post_modified_gmt" => "2023-07-18 02:04:46",
"post_parent" => 0,
"guid" => "http://localhost:8888/staging/?p=61003",
"menu_order" => 0,
"post_type" => "post",
"comment_count" => "0",
"filter" => "raw",
"meta" => [
"_edit_lock" => "1689645881:1",
"_edit_last" => "1"
],
"old_status" => "draft",
"category" => [
0 => [
"term_id" => 13034,
"name" => "Used",
"slug" => "used",
"term_group" => 0,
"term_taxonomy_id" => 13034,
"taxonomy" => "category",
"parent" => 0,
"count" => 1,
"filter" => "raw"
]
],
"post_tag" => [
0 => [
"term_id" => 13054,
"name" => "test tag",
"slug" => "test-tag",
"term_group" => 0,
"term_taxonomy_id" => 13054,
"taxonomy" => "post_tag",
"parent" => 0,
"count" => 6,
"filter" => "raw"
]
]
]
To get the ‘post_title’ value within this array, we would use a token like this: (action:post_title)
To get the category name within this array, we would use a token like this: (action:category:0:name)
To get the post meta field, we would use a token like this: (action:meta:subtitle)
Post/Custom Post – Status Changed
This action runs each time a new post changes its status. It won’t run when an already published post is updated. This is because we are doing a check that makes sure it never runs if the old status is equal to the new status.
Works with any post, page or custom post type and this is selectable.
The values available for this action are the same as Post/Custom Post – New Post Published above.
Post/Custom Post – Delete Post
This action runs each time a post is deleted from the database. It won’t run when an post is moved to trash.
Works with any post, page or custom post type and this is selectable.
The values available for this action are the same as Post/Custom Post – New Post Published above.
WooCommerce – New Product Created
This action runs each time a new product is published. It won’t run when an already published product is updated. This is because we are doing a check that makes sure it never runs if the old status is equal to the new status.
Below is an example of the values associated with this action.
array (
'id' => '60948',
'name' => 'Test product',
'slug' => 'test-product-3',
'date_created' => array (
'date' => '2023-07-11 12:05:54.000000',
'timezone_type' => 3,
'timezone' => 'Australia/Melbourne',
),
'status' => 'publish',
'featured' => '',
'catalog_visibility' => 'visible',
'description' => 'Test description',
'short_description' => 'Test short description',
'sku' => 'ITEM123456',
'price' => '249',
'regular_price' => '299',
'sale_price' => '249',
'date_on_sale_from' => '',
'date_on_sale_to' => '',
'total_sales' => '0',
'tax_status' => 'taxable',
'tax_class' => '',
'manage_stock' => '',
'stock_quantity' => '',
'stock_status' => 'instock',
'backorders' => 'no',
'low_stock_amount' => '',
'sold_individually' => '',
'weight' => '',
'length' => '',
'width' => '',
'height' => '',
'parent_id' => '0',
'reviews_allowed' => '1',
'purchase_note' => '',
'category_ids' => array (
0 => 13039,
1 => 13040,
),
'shipping_class_id' => '0',
'image_id' => '57682',
'gallery_image_ids' => array (
0 => 58591,
1 => 57682,
),
'average_rating' => '0',
'review_count' => '0',
'meta_data' => array (
0 => array (
'id' => 925479,
'key' => 'country',
'value' => 'Australia',
),
),
)
WooCommerce – New Order Created
See our full article on how to send WooCommerce order data to an API.
This action runs each time a new order is created. This runs on front end orders as well as orders created in the admin as well.
To grab any of these values, the tokens you need to use would like like these examples below:
- (action:id) – gets the id of the order
- (action:total) – gets the total of the order
- (action:line_items:0:name) – gets the name of the first product
We can also loop through the line items to grab data for all products, no matter how many products are in the order.
(line_items:start)
{
"Name": "(get:sku)",
"Quantity": "(get:qty)",
"LineSubTotal": "(get:subtotal)",
"image": "(get:image_url)",
}
(line_items:end)
Below is an example of the values associated with this action.
array (
'id' => '60963',
'parent_id' => '0',
'status' => 'pending',
'currency' => 'USD',
'version' => '7.8.0',
'prices_include_tax' => '',
'date_created' => array (
'date' => '2023-07-11 14:41:52.000000',
'timezone_type' => 3,
'timezone' => 'Australia/Melbourne',
),
'discount_total' => '0',
'discount_tax' => '0',
'shipping_total' => '0',
'shipping_tax' => '0',
'cart_tax' => '0',
'total' => '0.00',
'total_tax' => '0',
'customer_id' => '0',
'order_key' => 'wc_order_HL6T4nWrGq5My',
'billing' => array (
'first_name' => '',
'last_name' => '',
'company' => '',
'address_1' => '',
'address_2' => '',
'city' => '',
'state' => '',
'postcode' => '',
'country' => '',
'email' => '',
'phone' => '',
),
'shipping' => array (
... same as billing
),
'payment_method' => '',
'payment_method_title' => '',
'transaction_id' => '',
'customer_ip_address' => '',
'customer_user_agent' => '',
'created_via' => 'admin',
'customer_note' => '',
'date_completed' => '',
'date_paid' => '',
'cart_hash' => '',
'order_stock_reduced' => '',
'download_permissions_granted' => '',
'new_order_email_sent' => '',
'recorded_sales' => '',
'recorded_coupon_usage_counts' => '',
'number' => '60963',
'line_items' =>array (
0 => array (
'id' => 28,
'order_id' => 60965,
'name' => 'iPhone 14',
'product_id' => 58590,
'variation_id' => 0,
'quantity' => 3,
'tax_class' => '',
'subtotal' => '4200',
'subtotal_tax' => '0',
'total' => '4200',
'total_tax' => '0',
),
),
)
WooCommerce – Order Status Changed
See our full article on how to send WooCommerce order data to an API.
This action runs each time the status of an order is changed. This won’t run when a new order is created – use the New Order action above for new orders.
This action contains extra fields that allow you to select which statuses this action will apply to.
Below is an example of the values associated with this action.
array (
'id' => '60963',
'parent_id' => '0',
'status' => 'pending',
'currency' => 'USD',
'version' => '7.8.0',
'prices_include_tax' => '',
'date_created' => array (
'date' => '2023-07-11 14:41:52.000000',
'timezone_type' => 3,
'timezone' => 'Australia/Melbourne',
),
'discount_total' => '0',
'discount_tax' => '0',
'shipping_total' => '0',
'shipping_tax' => '0',
'cart_tax' => '0',
'total' => '0.00',
'total_tax' => '0',
'customer_id' => '0',
'order_key' => 'wc_order_HL6T4nWrGq5My',
'billing' => array (
'first_name' => '',
'last_name' => '',
'company' => '',
'address_1' => '',
'address_2' => '',
'city' => '',
'state' => '',
'postcode' => '',
'country' => '',
'email' => '',
'phone' => '',
),
'shipping' => array (
... same as billing
),
'payment_method' => '',
'payment_method_title' => '',
'transaction_id' => '',
'customer_ip_address' => '',
'customer_user_agent' => '',
'created_via' => 'admin',
'customer_note' => '',
'date_completed' => '',
'date_paid' => '',
'cart_hash' => '',
'order_stock_reduced' => '',
'download_permissions_granted' => '',
'new_order_email_sent' => '',
'recorded_sales' => '',
'recorded_coupon_usage_counts' => '',
'number' => '60963',
'line_items' =>array (
0 => array (
'id' => 28,
'order_id' => 60965,
'name' => 'iPhone 14',
'product_id' => 58590,
'variation_id' => 0,
'quantity' => 3,
'tax_class' => '',
'subtotal' => '4200',
'subtotal_tax' => '0',
'total' => '4200',
'total_tax' => '0',
),
),
)
Contact Form 7
This action runs each time your chosen Contact Form 7 form is submitted.
Below is an example of the values associated with this action.
array(
'email' => '[email protected]',
'first_name' => 'Bob',
'last_name' => 'Smith',
)
The email, first_name and last_name represent the names of the fields within your form. So this will look different depending on which fields you have setup in your form.
To get the ’email’ value within this array, we would use a token like this: (action:email)
Gravity Forms
This action runs each time your chosen Gravity Forms form is submitted.
Below is an example of the values associated with this action.
array (
'id' => '409',
'status' => 'active',
'form_id' => '5',
'ip' => '::1',
'source_url' => 'http://localhost:8888/staging/a/',
'currency' => 'USD',
'post_id' => '',
'date_created' => '2023-07-12 03:09:21',
'date_updated' => '2023-07-12 03:09:21',
'is_starred' => '0',
'is_read' => '0',
'user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36',
'payment_status' => '',
'payment_date' => '',
'payment_amount' => '',
'payment_method' => '',
'transaction_id' => '',
'is_fulfilled' => '',
'created_by' => '1',
'transaction_type' => '',
1 => 'technology',
2 => '[email protected]',
)
Gravity Forms uses the ID’s of your fields rather than field names. The number ‘1’ and ‘2’ at the bottom of the array indicates the ID of your fields.
So if field ID number 2 within your form is an email field, you can get the field value by using a token like this: (action:2)
WPForms
This action runs each time your chosen WPForms form is submitted.
Below is an example of the values associated with this action.
array (
9 => array (
'name' => 'Name',
'value' => 'test test',
'id' => 9,
'type' => 'name',
'first' => 'test',
'middle' => '',
'last' => 'test',
),
5 => array (
'name' => 'Single Line Text',
'value' => 'test',
'id' => 5,
'type' => 'text',
),
10 => array (
'name' => 'Multiple Choice',
'value' => 'First Choice',
'value_raw' => 'First Choice',
'id' => 10,
'type' => 'radio',
),
11 => array (
'name' => 'File Upload',
'value' => 'http://localhost:8888/staging/wp-content/uploads/wpforms/57895-2c68ef3ed28e3767df892e65436a8a46/Screen-Shot-2023-07-12-at-5.04.59-pm-7cabd466ffd7824c49a1fa25dabf8c2b.png',
'value_raw' => array (
0 => array (
'name' => 'Screen-Shot-2023-07-12-at-5.04.59-pm.png',
'value' => 'http://localhost:8888/staging/wp-content/uploads/wpforms/57895-2c68ef3ed28e3767df892e65436a8a46/Screen-Shot-2023-07-12-at-5.04.59-pm-7cabd466ffd7824c49a1fa25dabf8c2b.png',
'file' => 'Screen-Shot-2023-07-12-at-5.04.59-pm-7cabd466ffd7824c49a1fa25dabf8c2b.png',
'file_original' => 'Screen-Shot-2023-07-12-at-5.04.59-pm.png',
'file_user_name' => 'Screen Shot 2023-07-12 at 5.04.59 pm.png',
'ext' => 'png',
'attachment_id' => 0,
'id' => 11,
'type' => 'image/png',
),
),
'id' => 11,
'type' => 'file-upload',
'style' => 'modern',
),
)
WPForms uses the ID’s of your fields rather than field names. To get the url of a file that was uploaded into field 11, we would need to get the field ID of 11 and then the ‘value’ key so you would use a token like this: (action:11:value)
JetFormBuilder
This action runs each time your chosen JetFormBuilder form is submitted.
Below is an example of the values associated with this action.
[
"__form_id" => 60978,
"__refer" => "http://localhost:8888/staging/a",
"__is_ajax" => FALSE,
"post_id" => "60905",
"text_field" => "test text value",
"color_picker" => "#724f4f"
]
JetFormBuilder uses the field names of your fields.
In the example data above, to get the value in the ‘color_picker’ field, you would use a token like this: (action:color_picker)
Formidable Forms
This action runs each time your chosen Formidable Forms form is submitted.
Below is an example of the values associated with this action.
[
"frm_action" => "create",
"form_id" => "1",
"form_key" => "contact-form",
"item_meta" => [
1 => "Bob",
2 => "Smith",
3 => "[email protected]",
4 => "Testing a single text field",
5 => "Testing a textarea field"
],
"frm_submit_entry_1" => "15e12e88f6",
"_wp_http_referer" => "/staging/aaaa/",
"entry_id" => 14
]
Formidable Forms uses the ID’s of your fields that are within the ‘item_meta’ array.
So if field ID number 3 within your form is an email field, you can get the field value by using a token like this: (action:item_meta:3)
Elementor Forms
This action runs each time your chosen Elementor Forms form is submitted.
Below is an example of the values associated with this action.
[
"name" => "Bob Smith",
"email" => "[email protected]",
"message" => "Testing"
]
Elementor Forms uses the field id of your fields.
In the above example, to get the ‘email’ value you would use this token: (action:email)
Fluent Forms
This action runs each time your chosen Fluent Forms form is submitted.
Below is an example of the values associated with this action.
[
"__fluent_form_embded_post_id" => "117",
"_fluentform_1_fluentformnonce" => "6cd8c08c02",
"_wp_http_referer" => "/fluent-form/",
"names" => [
"first_name" => "Bob",
"last_name" => "Smith"
],
"email" => "[email protected]",
"entry_id" => 1
]
Fluent Forms uses the field names of your fields.
In the above example, to get the ‘email’ value you would use this token: (action:email) and to get the ‘first_name’ value you would use this token: (action:names:first_name)
Paid Memberships Pro – After Checkout
This action runs each time a user checks out using Paid Memberships Pro.
Below is an example of the values associated with this action.
[
"level" => "1",
"checkjavascript" => "1",
"business_name" => "test business name",
"bcountry" => "US",
"bemail" => "[email protected]",
"bconfirmemail" => "[email protected]",
"CardType" => "Unknown Card Type",
"ExpirationMonth" => "01",
"ExpirationYear" => "2023",
"submit-checkout" => "1",
"javascriptok" => "1",
"order_id" => "48",
"user_id" => "5",
"gateway" => "free",
"CVV" => "-- sensitive value hidden --"
]
In the above example, to get the ‘business_name’ value you would use this token: (action:business_name)
Easy Digital Downloads – Complete Purchase
This action runs each time makes a purchase using Easy Digital Downloads.
Below is an example of the values associated with this action.
[
"key" => "392bf557400db696e75ee75a25cc20ee",
"email" => "[email protected]",
"date" => "2023-07-18 11:46:20",
"user_info" => [
"id" => "1",
"first_name" => "a",
"last_name" => "a",
"email" => "[email protected]"
],
"downloads" => [
0 => [
"id" => "17100",
"quantity" => "1",
"options" => [
"quantity" => "1"
]
]
],
"cart_details" => [
0 => [
"name" => "test",
"id" => "17100",
"item_number" => [
"id" => "17100",
"quantity" => "1",
"options" => [
"quantity" => "1"
]
],
"item_price" => "15.000000000",
"quantity" => "1",
"discount" => "0.000000000",
"subtotal" => "15.000000000",
"tax" => "0.000000000",
"price" => "15.000000000",
"order_item_id" => "2"
]
],
"currency" => "USD",
"tax" => "0.000000000",
"payment_id" => 17110
]
In the above example, to get the purchasers email address you would use this token: (action:user_info:user_email)