Simple Expressions are supported by some [if /]
Shortcode Attributes. They allow you to check multiple conditions within the context of a supporting Attribute, using logical operators such as AND
, OR
. You can also group conditions using round brackets, much like you would in a raw PHP expression.
Attributes Supporting Simple Expressions
- current_user_can="{capability|expr}"
- current_user_bought_product="{ID|SKU|expr}"
- current_user_can_download="{ID|SKU|expr}"
- current_user_meta="{key|expr}"
- current_user_option="{key|expr}"
- request_var="{key|expr}"
- Arbitrary Custom Attributes
Logical Operators in Simple Expressions
AND
(same as&&
, which is also supported)OR
(same as||
, which is also supported)
[if current_user_meta="first_name AND last_name"]
First and last name are both filled.
[/if]
[if current_user_meta="!first_name OR !last_name"]
First or last name is missing.
[/if]
Comparison Operators in Simple Expressions
===
(exactly equal to)!==
(not exactly equal to)==
(equal to; loose comparison)!=
(not equal to: loose comparison)<=
(less than or equal to)>=
(greater than or equal to)<>
(less than or greater than)>
(greater than)<
(less than)
[if request_var="version == 1"]
.../?version=1
[/if]
[if request_var="version === '1'"]
.../?version=1 (using strict type comparison)
[/if]
String Literals (or Strings Containing Spaces)
When you need to test a string value, please wrap it in single quotes.
[if request_var="color == 'hot pink'"]
Matches the string literal: 'hot pink'
Single quotes required when string contains spaces.
[/if]
[if request_var="color == blue"]
Valid only because the word blue does not contain spaces.
[/if]
[if request_var="color == 'blue'"]
Same as previous example, but this is a better approach.
When in doubt, use single quotes to be more specific.
[/if]
[if request_var="color == ''"]
A color was not given; i.e., equal to an empty string.
[/if]
Negating (Testing for False)
!=
As seen above (not equal to).!==
As seen above (not exactly equal to).!
Before the parameter component.
[if current_user_can="!access_ccap_extras OR !edit_posts"]
Missing access to one of these.
[/if]
[if current_user_meta="first_name != '' AND last_name != ''"]
First and last name are both filled.
[/if]
Other Simple Expression Examples
[if current_user_can="(access_pkg_elite AND access_ccap_extras) OR edit_posts"]
Has access to one of these.
[/if]
[if current_user_bought_product="(123 AND ACME-INSTALLER-PRO) OR ACME-ELITE-BUNDLE"]
Bought something.
[/if]
[if current_user_can_download="(123 AND ACME-INSTALLER-PRO) OR ACME-ELITE-BUNDLE"]
Can download something.
[/if]
[if current_user_meta="primary_blog == 1"]
Primary blog ID is string 1.
[/if]
[if current_user_meta="_custom_key == 'string value'"]
Matches the string literal 'string value'.
[/if]
[if current_user_meta="(paying_customer AND _order_count > 0) OR _money_spent > 0"]
Made a purchase.
[/if]