Quickstart Guide

If Then Logic is a wordpress plugin that allows admins to create conditional logic using a set of rules. These rules are created by using conditions (if) and actions (then).

On each pagerequest done by a visitor or bot the plugin will start checking all conditions of the rules in order.
If all conditions are true, the actions for that rule will start to get processed (again in order of appearance) and once that’s done the other rules’ conditions won’t get checked.
If one condition is not true, the conditions for the next rule will start to get checked. This continues until all rules and conditions are checked.

A very basic example:

This is a rule #1 which checks if the URL is https://ifthenlogic.com/redirect AND the visitor is from the USA then it will perform a 302 redirect to https://example.com

A basic cloaking example:

Rule 1 checks to see if a cookie called ‘SecretCookie’ exists and if it does then it outputs a secret template
Rule 2 checks if the visitor is on https://ifthenlogic.com/secret-url/?blabla=1 AND does NOT have google, bing or msn in the user agent. Then it sets a cookie called ‘SecretCookie’ (which is valid for 3600 seconds/an hour) and does a 302 redirect to https://ifthenlogic.com/
Note the Negative Match checkbox next to the User Agent check

If someone is browsing the website normally, none of the rules trigger and they see the normal website.
If googlebot, bingbot, msnbot are crawling the website (or even the secret-url), none of the rules trigger and it sees the normal website.
If someone (using a normal browser and thus a normal user agent) visits https://ifthenlogic.com/secret-url/?blabla=1 the 2nd rule will match and thus (s)he will receive the SecretCookie and get redirected to https://ifthenlogic.com/. This becomes a new request (from https://ifthenlogic.com/) and the rules will get checked again at which point the 1st rule will match and that visitor will see the content: “This is normally hidden”

This could be easily used to send purchased traffic to https://ifthenlogic.com/secret-url/?blabla=1 and show them an optimized landing page that affiliate manager normally wouldn’t approve of.

(Re-)Ordering Conditions, Actions and Rules

To the right of each condition, action and rule there’s three buttons: Up, Down and Delete
These can be used to easily change the order of the actions, conditions and rules or to delete them.

Underneath there’s buttons: Add Condition, Add Action, Add Row. Which simply allow you to add more conditions, actions or a new rule.

There’s no limit to the number of rules, conditions or actions. But the more you use, the slower your website will become (as it has to do checks for each pagevisit).

Pre-made Conditions & Actions

There’s plenty of pre-made conditions and actions to make your life easier. These will all get explained somewhere else (links will be added here later as well)

Custom Conditions & Actions

If it possible to use PHP in the conditions and actions, which opens to door to have it to whatever you want if you know how to code (or know how to ask chatGPT to code something :smile:).
Some of the pre-made conditions and actions also use PHP directly. In the above basic cloaking example the condition ‘cookie check’ and the actions ‘show secret template’ and ‘set a cookie’ all use PHP directly.

Caching

If you using (page) caching on your website, the checks won’t get executed and thus you also won’t get the expected behaviour.
Thus if you’re planning on using the plugin for cloaking, don’t setup any page caching and if you’re planning on using the plugin for content generation, make sure to exclude the URL(s) you want to set as cronjob(s) from caching.
don’t forget about cloudflare caching if you’re using cloudflare :wink: