In some cases, you may only wish to display content if the user has completed certain WLT fields. Let’s say for example, you have a page where you wish to display a chart and some text introductory text, there is no point displaying the chart if the user has not entered their weight. The shortcode [wlt-if] allows you some basic logic to specify “if exists” or “if not exists” type logic. So using the example above, you could have something like:
[wlt-if field="weight" operator="exists] Some introductory text here explaining the chart. [wlt-chart] [/wlt-if]
We can also further expand this with an [else] clause. If the above condition is not met, we can specify what should be display instead e.g.
[wlt-if field="weight" operator="exists] Some introductory text here explaining the chart. [wlt-chart] [else] Please add a weight entry or two! [/wlt-if]
Specifying more that one field (5.1.5+)
You may wish to create an AND condition where multiple fields must exist or not exist for the condition to evaluate as true. This can be done by comma separating field names – The following example states the person must have a height and recent weight:
[wlt-if field="weight,height"] Thank you - we can now calculate your BMI! [else] Please add a weight entry as well as your height. [/wlt-if]
At the moment this shortcode is in it’s infancy, so please get in touch with any suggestions. Below you can see the fields and operators it supports and further examples of its usage can be found on the [wlt-if] gist.
Nesting [wlt-if] statements (5.1.5+)
There maybe instances where you wish to nest IF statements. For example you may want to ensure a person is logged in before checking if their weight and height. To do this, you can use the additional shortcodes to nest [wlt-if-1], [wlt-if-2] and [wlt-if-3]. Each corresponds to the level of nesting. Below is a simple example:
[wlt-if field="is-logged-in"] You are logged in! [wlt-if-1 field="weight"] We have your weight! [wlt-if-2 field="height"] Great! We have all we need! [wlt-bmi] [else-2] Please add a height! [/wlt-if-2] [else-1] Please add a weight! [/wlt-if-1] [else] Please login first :) [/wlt-if]
Another example can be found at the following Gist. It is important to note, if you nest an IF statement within another, you must add the -1, -2, -3 to the shortcode as you go deeper. Failure to do so will lead to unexpected behavior.
The shortcode supports the following arguments:
|user-id||By default, the shortcode will determine the result for the current user. If you wish to determine the result based on another user, use the following argument.||A number.||[wlt-if user-id="1" field="weight"]Something[/wlt-if]|
|operator||Allows you to state whether field has been populated (exists) or not (not-exists).||exists (default) or not-exists||[wlt-if operator="exists" field="weight"]Thank you for adding a weight entry[else]Please add a weight entry[/wlt-if]|
|field||Allows you to specify which field should be examined.||weight (default), is-logged-in, target, bmr, height, aim, gender, photo, activity-level or dob.||[wlt-if field="dob" operator="not-exists"]Please enter your Date of Birth on the settings page.[/wlt-if]|
|strip-p-br (5.1.6+)|| Specifies whether to remove
andtags added by WordPress
|true or false (default).||[wlt-if strip-p-br="true"]Something[/wlt-if]|