Elementor 开发者文档

title: "Condition Structure" post_status: publish comment_status: open taxonomy: category: - elementor-developers-docs post_tag: - Theme Conditions - Src - Repos


Condition Structure

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 {
}

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 {}

}

Let’s break it down:

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.