Create a simple conditionals

Estimated reading: 2 minutes

The simple conditionals are conditionals that are called by entering their hookname in the Conditional Logic section on the *Toolbox Tab.

To do this, simply add a Filter, select “Custom” from the dropdown and enter your defined hookname in the field.

But what have you just done?

Understanding what happens

Whenever a node is requested for rendering, a parameter called $is_visible is passed into the filter. The starting state is, of course set to true. Each consecutive filter that evaluates if the node should be rendered passes on that values, as long as it remains true. If a filter decides otherwise, subsequent filters need to continue returning false instead of evaluating the conditions.

Lets consider an easy example:

<?php

// simple example of a conditional filter
add_filter( 'conditional_filter_check_userloggedin' , 'my_check_userloggedin' ,10 ,2  );

function my_check_userloggedin( $is_visible , $node ) {
	return is_user_logged_in();
}

Let’s examine what happens:

We add a filter and give it any hookname we want. This hookname needs to be unique and is created specifically for this or any series of tests. Here the hookname is conditional_filter_check_userloggedin

Create a callback with two parameters:

  • $is_visible
  • $node

Here the callback name is my_check_userloggedin

On it’s own this filter doesn’t do much. It still needs to be applied from inside of our layout. Open one of your layouts and open the Settings panel on a Row, Column or Module.

Add a filter of type Custom and enter the filter hookname you’ve decided on. Notice that in the Conditional filter field you need to enter the hookname, NOT the callback.

That’s it! Once you save and reload the page it will evaluate if you are a logged on user and if not, it will stop the node from rendering to the browser.

toolbox_docs_custom_cond1

Now, this example is very simple. And the functionality is already built into Beaver Builder. But the point was to show a basic example of what little is needed to determine if a node should be displayed or not.

You can find more complex examples on the next docs-page.

Share this Doc

Create a simple conditionals

Or copy link

CONTENTS