Howto delete items in Formidable Action Automation queue step by step

Jun 07, 2018

Hello, today i will show you how to delete an Entry from the queue of Formidable Action Automation. If you don’t use it yet and you don’t know how useful is this plugin take a look to the amazing documentation from Strategy11 team.

https://formidableforms.com/knowledgebase/schedule-autoresponder

This plugins is easy to setup and get it work. It have his own action to delete the Entries in queue as you can check in the next link.

https://formidableforms.com/knowledgebase/schedule-autoresponder/#kb-reading-the-current-queue

But what happen if you need to delete that Entries without your intervention. Today i will share with you a small code to delete an Entry, and sure i will explain the script step by step. And not forget to check my recommendation.

Requirements

  • Formidable Free/Pro
  • Formidable Action Automation
  • PHP coding skills.

Let’s do this remove from Formidable Action Automation

The first you need to know about this action is it work over the WordPress CRON. Not worry if is not clear to you, check the next link where you can find more info in the WP Codex.

This will be a peace of cake 😉

I split in 3 simple steps.

  • Get WP CRON Queue.
  • Get Formidable Action data.
  • Remove from the item from the WP CRON Queue.

The Step 1 is to get all the CRON jobs

For this will use the function of wp core _get_cron_array(), this is a private function, then we will need to take care of it. This mean we will use this function in our own and take care of all related precautions.

if ( function_exists( _get_cron_array() ) ) {
  $cron = _get_cron_array();
  if ( isset( $cron ) ) {
     $queue   = array();
     foreach ( $cron as $timestamp => $events ) {
        if ( isset( $events['formidable_send_autoresponder'] ) ) {
           foreach ( $events['formidable_send_autoresponder'] as $id => $autoresponder ) {
              $queue[] = array(
                 'timestamp'   => $timestamp,
                 'pretty_time' => date( 'Y-m-d H:i:s', $timestamp ),
                 'entry_id'    => $autoresponder['args'][0],
                 'action_id'   => $autoresponder['args'][1],
              );
           }
        }
     }
  }
}

NOTE: You can use this other function wp_get_schedule() but you will need the list of arguments.

In the $queue array you get the entry id and the related action. Will be easy for you to iterate over all the elements and match with your needs. Here i will show you how to delete certain entry in a specific action.

Step 2, Find the Formidable Notification Action.

Now we will use a function from Formidable core get_action_for_form(), with this function you can get specific types of actions related to a form in an Array. In this example you will get the email actions, because the Action Automation only is present inside the Notifications Actions.

$actions = FrmFormAction::get_action_for_form( $form_id, 'email' );
/**
* @var int      $action_id
* @var WP_Post $action_data
*/
foreach ( $actions as $action_id => $action_data ) {

}

NOTE: If you notice my comments before the foreach the variable $action_data is a WP_POST type, that mean you can get access to the action options from the post_content like the next example.

$action_data->post_content[‘key']

Step 3, remove a Formidable Entry from the WP CRON Queue.

To remove an item from the WP CRON is easy with the function wp_unschedule_event() and the correct parameters. To make this work you will need the same timestamp, the hook name and one array of the same parameters used in the original hook. Like the next code.

wp_unschedule_event( $item['timestamp'], 'formidable_send_autoresponder', array( intval( $item['entry_id'] ), intval( $item['action_id'] ) ) );

Now you have all the information in your mind, maybe not make sense, but continue reading and check the complete code used in a simple example.

All in one place, the example.

I love to use my imagination, is my best tool. Then imagine with me a case where you have a form where the user will be notified one week later of the entry is created, but you like to avoid that notification if the Entry is edited before the timeframe.

The code is in github in the next link, with the explanation inline.

https://github.com/gfirem/ExampleRemoveEntryFromAutomation.git

Recommendations.

Use WP CRON drain resource from our WordPress site, because it use an internal timer on each page load and trigger in certain timeframe to ensure execute the schedules, but at the cost of your users navigations. I recommend you to disable it and trigger using some external tool like crontab in linux or other.

To disable is easy you need to add the next line to your wp-config.php

define('DISABLE_WP_CRON', true);

Then point your external tool to trigger the cron hitting your site http://www.url.com/wp-con.php or direct to the file system /path/to/site/wp-cron.php

Is easy.

If you have any doubt or question, let me know to help you. I would happy if you send me your feedback with a comment on the site, or the FB page, Twitter, Skype … where you like most  😉

El Guille.

PD if you have any block in your project or there is something about what you would like me to write let me know it would be a pleasure to help you.

No comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Interested to get more tips!