Using workflows as WordPress filters

jetFlow.io > Documentation  > Using workflows as WordPress filters

Using workflows as WordPress filters

Yes, you can create a native WordPress filter by using a workflow. Workflows, generated by the jetFlow.io plugin are extremely fast and a filter can be made in a few minutes without coding knowledge. You get your new filter instantly, having created and enabled the workflow.

A quote from the WordPress documentation:

Filters are functions that WordPress passes data through, at certain points in execution, just before taking some action with the data (such as adding it to the database or sending it to the browser screen). Filters sit between the database and the browser (when WordPress is generating pages), and between the browser and the database (when WordPress is adding new posts and comments to the database); most input and output in WordPress passes through at least one filter. WordPress does some filtering by default, and your plugin can add its own filtering.

Let’s create a filter

To get a workflow working as a WordPress filter, you have to define, at least, two items in the workflow.

The first item is the Hook up trigger. In this trigger, you specify the name of a filter you’re going to use. The second item is the Return it action that you have to add at the end of a workflow. Both items are mandatory for filters, otherwise, you will get unpredictable results that might even break your site completely.

So, you have to start your workflow with Hook up and finish it with Return it. Optionally, you can use action Stop if somewhere in the middle of your workflow and return a value to WordPress.

Trigger: Hook up

This trigger registers a workflow with a WordPress hook system. The name of a filter is provided by WordPress, a plugin, or a theme. The filter name defines when the workflow starts and what filter is applied.

Note: You cannot use any WordPress hook (filter or action) that occurred earlier than init action.

How can you get value passed by WordPress to the workflow? Use the value {TRIGGER}. This variable holds a value that WordPress is expecting your workflow processes. Additional parameters passed by WordPress can be retrieved with variables {ARG[1]}, {ARG[2]} and so on. To figure out what parameters are passed, read the documentation on a particular filter you’re going to use.

Action: Return it

You have to add this action to the end of the workflow. It immediately ends execution of the current workflow and returns a specified value to WordPress. To return an unchanged value, use variable {ARG[0]} or {TRIGGER}.

Set up returning value according to the description of a filter hook.

Action: Stop if

Sometimes you may need to apply filter conditionally. That is not a problem and you can configure as many conditions as you need. Remember that under any conditions your workflow has to return a value to WordPress. You can use the Stop if action and specify the returning value with a field Return value. To return unchanged value. use pattern {ARG[0]} or {TRIGGER}.

Set up returning value according to the description of a filter. Read the documentation on the Stop if action.

Note: Some types of filters cannot be created due to the complexity of data passed by WordPress. Make sure that your workflow return the right type of data to WordPress. If it’s a string, a workflow may not return a list and vise versa.

Read documentation on WordPress filters: https://codex.wordpress.org/Plugin_API/Filter_Reference

 

No Comments

Sorry, the comment form is closed at this time.