Note: This trigger requires some technical knowledge to configure. Unfortunately, we can’t provide information about another plugin’s action hooks or arguments. This trigger may not work on all plugin hooks. See notes at end of article.
Introduction
Uncanny Automator integrates with all of the most popular WordPress plugins like WooCommerce, WP Forms, LearnDash and more. But with hundreds of thousands of plugins in existence and more being created each day, it’s not possible to create triggers to cover every possible scenario.
That’s why we created the Plugin Actions integration with the trigger Create a custom trigger on a plugin action hook. To explain how this custom trigger works, we need to look at how triggers are built.
How it works
Our WordPress plugin triggers are created by registering a hook that is called by the function do_action when a plugin does something. Plugin authors add these do_action hooks to their code to make their plugins extendable. For example, when a user completes a course in LearnDash, the plugin calls the do_action hook learndash_course_completed. The LearnDash trigger A user completes a course is hooked into the learndash_course_completed hook, so that we can start our recipe when that hook is “fired” by LearnDash.
Each do_action hook has a specific name (like the learndash_course_completed example above), and this is how the trigger Create a custom trigger on a plugin action hook works. If you know the name of the do_action hook being called in your plugin, you can enter it into this trigger, and your recipe will run when that do_action hook is called.
Finding a plugin’s do_action hooks
Unfortunately, since do_action hooks are really intended for developers, to find the name of the do_action hook you need, you’ll need to contact the creator of your plugin and ask them a couple of questions:
- I’d like to hook into your plugin when [a specific event happens]. Is there a do_action hook for that?
- If the answer is yes, then ask for the name of the hook. You can then enter this name into the Create a custom trigger on a plugin action hook trigger.
- If the answer is no, you would need to request that the plugin author adds a hook that fires when when that specific event happens.
Capturing arguments as tokens
Once you’ve entered the hook name into the Action hook field, you’ll need to capture the Arguments the hook passes. This is data that goes along with the hook, that you will probably want to use in your recipe. For example, the learndash_course_completed passes along the ID of the course that was completed. Each argument passed into the hook becomes a token you can use in your recipe’s actions.
It would not be sensible for Automator to scan all the code on your site to locate the action and figure out the arguments passed along with it. The only way Automator can detect the arguments is if it were able to listen to the firing of the hook and detect the arguments in real time.
For this to work, you’d need to do the following:
- Save the trigger so that the name of the hook is saved in the system.
- learndash_course_completed example above, you would get everything ready to complete a LearnDash course.
- Click Capture hook data, so that Automator starts listening and gets ready to capture the firing of the saved hook by name.
- Execute the workflow/process/action so that the hook is fired and Automator is able to “catch” its arguments.
You would then see a dialog that shows the list of arguments detected by Automator
If everything looks fine, click Use these tokens. Once you do that, the recipe will automatically save and the editor will reload and all the arguments will become available as tokens for the actions in your recipe.
Setting up actions
Once you’ve specified the number of arguments, you can move on to setting up your recipe’s actions. You’ll see the tokens from the trigger listed as:
- argument_0
- argument_1
- argument_2
- etc.
Unfortunately, there’s really no way to figure out what data is being passed in those arguments until you run the trigger and check the output. To do that, you can use the Send an email action, or the Write data to the log action (in the Logging integration). Once you’ve figured out what data is being passed into the hook, you can use it to set up your recipes.
That’s it! With this trigger, you can turn an unsupported plugin into a supported plugin and use the plugin in your Automator workflows.
Notes
- Action hooks that occur earlier than
plugins_loaded
cannot be used with this trigger. For example, the following hooks run beforeplugins_loaded
and will not work when used with this trigger:
-
muplugins_loaded
init
wp_loaded
before_setup_theme
after_setup_theme
load-{page_hook}
- If you’re having trouble getting this trigger to work, you can ask the developer of the plugin to build an integration for Uncanny Automator. Resources can be found at developer.automatorplugin.com. Building an integration with Uncanny Automator is an easy way to quickly integrate a plugin with a huge ecosystem of other plugins and apps.