# Condition Structure

Elementor Pro Advanced

Each condition needs to have a few basic settings, such as a unique name and label. In addition, a condition should be assigned to a group. A condition could have sub-conditions. The final, and most important, is the check method that checks whether the condition complies with a set of predefined rules.

# Theme Condition Class

First, we need to create a class that extends the \ElementorPro\Modules\ThemeBuilder\Conditions\Condition_Base class:

class Elementor_Test_Condition extends \ElementorPro\Modules\ThemeBuilder\Conditions\Condition_Base {
}
1
2

# Theme Condition Structure

As mentioned above, conditions extend the \ElementorPro\Modules\ThemeBuilder\Conditions\Condition_Base class and inherit its methods. A simple condition skeleton will look as follows:

class Elementor_Test_Condition extends \ElementorPro\Modules\ThemeBuilder\Conditions\Condition_Base {

	public static function get_type(): string {}

	public function get_priority(): int {}

	public function get_name(): string {}

	public function get_label(): string {}

	public function get_all_label(): string {}

	public function register_sub_conditions(): void {}

	public function check( $args ): bool {}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

Let’s break it down:

  • Condition Type – The get_type() method returns the condition group type.

  • Condition Priority – The get_priority() method prioritize the condition in a group type.

  • Condition Name – The get_name() method returns the condition name (id) that will be used in the code.

  • Condition Label – The get_label() method returns the condition label that will be displayed to the user.

  • Condition All Label – The get_all_label() method returns the all/any label that will be displayed to the user, if the condition has sub-conditions.

  • Condition Check – The check() method is the actual method that checks if the condition complies to a certain set of rules.

  • Sub-Conditions – The register_sub_conditions() method registers sub-conditions.

Please note that the Condition_Base class has many more methods developers can use, but the methods mentioned above will cover the vast majority of your needs.