first commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Classes;
|
||||
|
||||
class And_Condition {
|
||||
/**
|
||||
* @var $conditions_manager Object
|
||||
*/
|
||||
private $conditions_manager;
|
||||
|
||||
/**
|
||||
* @var $conditions array
|
||||
*/
|
||||
private $conditions;
|
||||
|
||||
public function __construct( $conditions_manager, $conditions ) {
|
||||
$this->conditions_manager = $conditions_manager;
|
||||
$this->conditions = $conditions;
|
||||
}
|
||||
|
||||
public function check() {
|
||||
foreach ( $this->conditions as $condition_options ) {
|
||||
$condition_result = $this->is_condition_passing_check( $condition_options );
|
||||
|
||||
if ( ! $condition_result ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function is_condition_passing_check( $condition_options ) {
|
||||
$condition_instance = $this->get_condition_instance( $condition_options );
|
||||
|
||||
return $condition_instance
|
||||
? $condition_instance->check( $condition_options )
|
||||
: true;
|
||||
}
|
||||
|
||||
private function get_condition_instance( $condition ) {
|
||||
if ( ! isset( $condition['condition'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->conditions_manager->get_condition( $condition['condition'] );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Classes;
|
||||
|
||||
use Elementor\Core\Editor\Editor;
|
||||
|
||||
class Cache_Notice {
|
||||
const OPTION_NAME_DC_CACHE_NOTICE_DISMISSED = 'elementor_pro_dc_cache_notice_dismissed';
|
||||
const NOTICE_STATUS_YES = 'yes';
|
||||
|
||||
public function should_show_notice() : bool {
|
||||
return self::NOTICE_STATUS_YES !== get_option( self::OPTION_NAME_DC_CACHE_NOTICE_DISMISSED );
|
||||
}
|
||||
|
||||
public function set_notice_status() : bool {
|
||||
if ( ! current_user_can( Editor::EDITING_CAPABILITY ) ) {
|
||||
throw new \Exception( 'Access denied.' );
|
||||
}
|
||||
|
||||
return add_option( self::OPTION_NAME_DC_CACHE_NOTICE_DISMISSED, self::NOTICE_STATUS_YES, '', 'no' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Classes;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Comparator_Provider {
|
||||
|
||||
private static array $comparators = [];
|
||||
|
||||
public const COMPARATOR_IS = 'is';
|
||||
public const COMPARATOR_IS_NOT = 'is_not';
|
||||
public const COMPARATOR_IS_ONE_OF = 'is_one_of';
|
||||
public const COMPARATOR_IS_NONE_OF = 'is_none_of';
|
||||
public const COMPARATOR_CONTAINS = 'contains';
|
||||
public const COMPARATOR_NOT_CONTAIN = 'not_contain';
|
||||
|
||||
public const COMPARATOR_IS_BEFORE = 'is_before';
|
||||
public const COMPARATOR_IS_AFTER = 'is_after';
|
||||
public const COMPARATOR_IS_LESS_THAN_INCLUSIVE = 'is_less_than_inclusive';
|
||||
public const COMPARATOR_IS_GREATER_THAN_INCLUSIVE = 'is_greater_than_inclusive';
|
||||
public const COMPARATOR_IS_BEFORE_INCLUSIVE = 'is_before_inclusive';
|
||||
public const COMPARATOR_IS_AFTER_INCLUSIVE = 'is_after_inclusive';
|
||||
public const COMPARATOR_IS_EMPTY = 'is_empty';
|
||||
public const COMPARATOR_IS_NOT_EMPTY = 'is_not_empty';
|
||||
|
||||
public static function get_comparators( array $comparators ): array {
|
||||
self::init_comparators_array_if_empty();
|
||||
|
||||
return array_intersect_key( self::$comparators, array_flip( $comparators ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private static function init_comparators_array_if_empty(): void {
|
||||
if ( ! empty( self::$comparators ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::$comparators[ static::COMPARATOR_IS ] = esc_html__( 'Is', 'elementor-pro' );
|
||||
self::$comparators[ static::COMPARATOR_IS_NOT ] = esc_html__( 'Is Not', 'elementor-pro' );
|
||||
self::$comparators[ static::COMPARATOR_IS_ONE_OF ] = esc_html__( 'Is', 'elementor-pro' );
|
||||
self::$comparators[ static::COMPARATOR_IS_NONE_OF ] = esc_html__( 'Is Not', 'elementor-pro' );
|
||||
self::$comparators[ static::COMPARATOR_CONTAINS ] = esc_html__( 'Contains', 'elementor-pro' );
|
||||
self::$comparators[ static::COMPARATOR_NOT_CONTAIN ] = esc_html__( 'Does not contain', 'elementor-pro' );
|
||||
self::$comparators[ static::COMPARATOR_IS_BEFORE ] = esc_html__( 'Is Before', 'elementor-pro' );
|
||||
self::$comparators[ static::COMPARATOR_IS_AFTER ] = esc_html__( 'Is After', 'elementor-pro' );
|
||||
self::$comparators[ static::COMPARATOR_IS_LESS_THAN_INCLUSIVE ] = esc_html__( 'Less than or equal', 'elementor-pro' );
|
||||
self::$comparators[ static::COMPARATOR_IS_GREATER_THAN_INCLUSIVE ] = esc_html__( 'Greater than or equal', 'elementor-pro' );
|
||||
self::$comparators[ static::COMPARATOR_IS_BEFORE_INCLUSIVE ] = esc_html__( 'Is on or before', 'elementor-pro' );
|
||||
self::$comparators[ static::COMPARATOR_IS_AFTER_INCLUSIVE ] = esc_html__( 'Is on or after', 'elementor-pro' );
|
||||
self::$comparators[ static::COMPARATOR_IS_EMPTY ] = esc_html__( 'Is Empty', 'elementor-pro' );
|
||||
self::$comparators[ static::COMPARATOR_IS_NOT_EMPTY ] = esc_html__( 'Is not Empty', 'elementor-pro' );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Classes;
|
||||
|
||||
use DateTime;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Comparators_Checker {
|
||||
|
||||
/**
|
||||
* @param string $comparator
|
||||
* @param string|DateTime $value_to_check
|
||||
* @param string|DateTime $set_value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function check_date_time( string $comparator, $value_to_check, $set_value ): bool {
|
||||
switch ( $comparator ) {
|
||||
case Comparator_Provider::COMPARATOR_IS:
|
||||
return $set_value == $value_to_check;
|
||||
case Comparator_Provider::COMPARATOR_IS_NOT:
|
||||
return $set_value != $value_to_check;
|
||||
case Comparator_Provider::COMPARATOR_IS_AFTER:
|
||||
return $set_value < $value_to_check;
|
||||
case Comparator_Provider::COMPARATOR_IS_BEFORE:
|
||||
return $set_value > $value_to_check;
|
||||
case Comparator_Provider::COMPARATOR_IS_AFTER_INCLUSIVE:
|
||||
return $set_value <= $value_to_check;
|
||||
case Comparator_Provider::COMPARATOR_IS_BEFORE_INCLUSIVE:
|
||||
return $set_value >= $value_to_check;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function check_array_contains( string $comparator, array $expected_values, array $array_of_values ): bool {
|
||||
$is_contained = ! empty( array_intersect( $expected_values, $array_of_values ) );
|
||||
switch ( $comparator ) {
|
||||
case Comparator_Provider::COMPARATOR_IS:
|
||||
case Comparator_Provider::COMPARATOR_IS_ONE_OF:
|
||||
return $is_contained;
|
||||
|
||||
case Comparator_Provider::COMPARATOR_IS_NOT:
|
||||
case Comparator_Provider::COMPARATOR_IS_NONE_OF:
|
||||
return ! $is_contained;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function check_string_contains( string $comparator, string $expected_value, string $actual_value ): bool {
|
||||
$expected_value = strtolower( $expected_value );
|
||||
$actual_value = strtolower( $actual_value );
|
||||
|
||||
switch ( $comparator ) {
|
||||
case Comparator_Provider::COMPARATOR_IS:
|
||||
return $expected_value === $actual_value;
|
||||
|
||||
case Comparator_Provider::COMPARATOR_IS_NOT:
|
||||
return $expected_value !== $actual_value;
|
||||
|
||||
case Comparator_Provider::COMPARATOR_CONTAINS:
|
||||
return str_contains( $actual_value, $expected_value );
|
||||
|
||||
case Comparator_Provider::COMPARATOR_NOT_CONTAIN:
|
||||
return ! str_contains( $actual_value, $expected_value );
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function check_string_contains_and_empty( string $comparator, string $expected_value, string $actual_value ): bool {
|
||||
if ( self::check_string_contains( $comparator, $expected_value, $actual_value ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch ( $comparator ) {
|
||||
case Comparator_Provider::COMPARATOR_IS_EMPTY:
|
||||
return empty( $actual_value );
|
||||
|
||||
case Comparator_Provider::COMPARATOR_IS_NOT_EMPTY:
|
||||
return ! empty( $actual_value );
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function check_equality( string $comparator, string $value, string $compare_to ): bool {
|
||||
switch ( $comparator ) {
|
||||
case Comparator_Provider::COMPARATOR_IS:
|
||||
return $value === $compare_to;
|
||||
|
||||
case Comparator_Provider::COMPARATOR_IS_NOT:
|
||||
return $value !== $compare_to;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $comparator
|
||||
* @param int $value
|
||||
* @param int $compare_to
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function check_numeric_constraints( string $comparator, int $value, int $compare_to ): bool {
|
||||
switch ( $comparator ) {
|
||||
case Comparator_Provider::COMPARATOR_IS:
|
||||
return $compare_to === $value;
|
||||
case Comparator_Provider::COMPARATOR_IS_NOT:
|
||||
return $compare_to !== $value;
|
||||
case Comparator_Provider::COMPARATOR_IS_LESS_THAN_INCLUSIVE:
|
||||
return $compare_to <= $value;
|
||||
case Comparator_Provider::COMPARATOR_IS_GREATER_THAN_INCLUSIVE:
|
||||
return $compare_to >= $value;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Classes;
|
||||
|
||||
use ElementorPro\Core\Isolation\Wordpress_Adapter;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Condition_Base;
|
||||
use ElementorPro\Modules\DisplayConditions\Module;
|
||||
use ElementorPro\Plugin;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Conditions_Manager {
|
||||
/**
|
||||
* @var Condition_Base[]
|
||||
*/
|
||||
private $conditions = [];
|
||||
|
||||
private $groups;
|
||||
|
||||
private const CONDITIONS = [
|
||||
// Page
|
||||
'Page_Title_Condition',
|
||||
'Page_Parent_Condition',
|
||||
'Page_Author_Condition',
|
||||
|
||||
// Post
|
||||
'Post_Title_Condition',
|
||||
'In_Categories_Condition',
|
||||
'In_Tags_Condition',
|
||||
'Date_Of_Modification_Condition',
|
||||
'Date_Of_Publish_Condition',
|
||||
'Post_Author_Condition',
|
||||
'Post_Number_Of_Comments_Condition',
|
||||
'Featured_Image_Condition',
|
||||
|
||||
// User
|
||||
'Login_Status_Condition',
|
||||
'User_Role_Condition',
|
||||
'User_Registration_Date_Condition',
|
||||
|
||||
// Date and time
|
||||
'Day_Of_The_Week_Condition',
|
||||
'Time_Of_The_Day_Condition',
|
||||
'Current_Date_Condition',
|
||||
|
||||
// Archive
|
||||
'Archive_Of_Category_Condition',
|
||||
'Archive_Of_Tag_Condition',
|
||||
'Archive_Of_Author_Condition',
|
||||
|
||||
// Other
|
||||
'From_URL_Condition',
|
||||
'Dynamic_Tags_Condition',
|
||||
];
|
||||
|
||||
private Module $display_conditions_module;
|
||||
|
||||
public function __construct( $display_conditions_module ) {
|
||||
$this->display_conditions_module = $display_conditions_module;
|
||||
$this->register_conditions();
|
||||
}
|
||||
|
||||
private function init_groups() {
|
||||
$this->groups = [
|
||||
'page' => [
|
||||
'label' => esc_html__( 'Page', 'elementor-pro' ),
|
||||
],
|
||||
'post' => [
|
||||
'label' => esc_html__( 'Post', 'elementor-pro' ),
|
||||
],
|
||||
'user' => [
|
||||
'label' => esc_html__( 'User', 'elementor-pro' ),
|
||||
],
|
||||
'date' => [
|
||||
'label' => esc_html__( 'Date and Time', 'elementor-pro' ),
|
||||
],
|
||||
'archive' => [
|
||||
'label' => esc_html__( 'Archive', 'elementor-pro' ),
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Registration of a group for the display conditions.
|
||||
*
|
||||
* Fires when a new display condition groups is registered. This hook allows developers
|
||||
* to register new display conditions groups using add_group().
|
||||
*
|
||||
* @param Conditions_Manager $this An instance of conditions manager.
|
||||
*/
|
||||
do_action( 'elementor/display_conditions/register_groups', $this );
|
||||
|
||||
$this->groups['other'] = [ 'label' => esc_html__( 'Other', 'elementor-pro' ) ];
|
||||
}
|
||||
|
||||
private function register_condition( $id, $args = [] ) {
|
||||
if ( isset( $this->conditions[ $id ] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$args[] = new Wordpress_Adapter();
|
||||
$class_name = '\\ElementorPro\\Modules\\DisplayConditions\\Conditions\\' . $id;
|
||||
|
||||
/** @var Condition_Base $condition */
|
||||
$condition = new $class_name( $args );
|
||||
|
||||
$this->register_condition_instance( $condition );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Condition_Base $instance
|
||||
* @return false|void
|
||||
*/
|
||||
public function register_condition_instance( Condition_Base $instance ) {
|
||||
$id = $instance->get_name();
|
||||
$is_exist = $this->get_condition( $id );
|
||||
|
||||
if ( false !== $is_exist ) {
|
||||
return false; // Already registered.
|
||||
}
|
||||
|
||||
$this->conditions[ $id ] = $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add condition group.
|
||||
*
|
||||
* Register new group for the condition.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $group_name Group name.
|
||||
* @param array $group_properties Group properties.
|
||||
*/
|
||||
public function add_group( $group_name, $group_properties ) {
|
||||
if ( null === $this->groups ) {
|
||||
$this->get_groups();
|
||||
}
|
||||
|
||||
if ( ! isset( $this->groups[ $group_name ] ) ) {
|
||||
$this->groups[ $group_name ] = $group_properties;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get condition groups.
|
||||
*
|
||||
* Retrieve the list of groups for the conditions.
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @return array Condition groups.
|
||||
*/
|
||||
private function get_groups() {
|
||||
if ( null === $this->groups ) {
|
||||
$this->init_groups();
|
||||
}
|
||||
|
||||
return $this->groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
*
|
||||
* @return Condition_Base|bool
|
||||
*/
|
||||
public function get_condition( $id ) {
|
||||
return isset( $this->conditions[ $id ] ) ? $this->conditions[ $id ] : false;
|
||||
}
|
||||
|
||||
public function get_conditions_config() {
|
||||
$config = [];
|
||||
|
||||
$config['conditions'] = [];
|
||||
|
||||
foreach ( $this->conditions as $condition ) {
|
||||
$config['conditions'][ $condition->get_name() ] = $condition->get_config();
|
||||
}
|
||||
|
||||
$config['groups'] = $this->get_groups();
|
||||
$config['show_cache_notice'] = $this->display_conditions_module->get_component( 'cache_notice' )->should_show_notice();
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function register_conditions() {
|
||||
$conditions = self::CONDITIONS;
|
||||
|
||||
foreach ( $conditions as $condition ) {
|
||||
$this->register_condition( $condition );
|
||||
}
|
||||
|
||||
/**
|
||||
* Elementor display conditions registration.
|
||||
*
|
||||
* Fires when a new display condition is registered. This hook allows developers
|
||||
* to register new display conditions using register_condition_instance().
|
||||
*
|
||||
* @param Conditions_Manager $this An instance of conditions manager.
|
||||
*/
|
||||
do_action( 'elementor/display_conditions/register', $this );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Classes\DynamicTags;
|
||||
|
||||
class Custom_Fields_Data_Provider implements Data_Provider {
|
||||
|
||||
const CUSTOM_FIELDS_META_LIMIT = 50;
|
||||
|
||||
/**
|
||||
* Build the custom fields options for the control. Add the groups and the items.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_control_options(): array {
|
||||
global $wpdb;
|
||||
|
||||
$keys = $wpdb->get_col(
|
||||
$wpdb->prepare(
|
||||
"SELECT DISTINCT meta_key
|
||||
FROM $wpdb->postmeta
|
||||
WHERE meta_key NOT BETWEEN '_' AND '_z'
|
||||
HAVING meta_key NOT LIKE %s
|
||||
ORDER BY meta_key
|
||||
LIMIT %d",
|
||||
$wpdb->esc_like( '_' ) . '%',
|
||||
apply_filters( 'elementor_pro/display_conditions/dynamic_tags/custom_fields_meta_limit', static::CUSTOM_FIELDS_META_LIMIT )
|
||||
)
|
||||
);
|
||||
|
||||
if ( empty( $keys ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->get_control_groups() + array_combine( $keys, $keys );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $args
|
||||
*
|
||||
* @return string | bool
|
||||
*/
|
||||
public function get_value( array $args ) {
|
||||
if ( ! metadata_exists( 'post', get_the_ID(), $args['dynamic_tag'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return get_post_meta( get_the_ID(), $args['dynamic_tag'], true );
|
||||
}
|
||||
|
||||
private function get_control_groups(): array {
|
||||
return [
|
||||
'custom_field' => [
|
||||
'label' => esc_html__( 'Custom Field', 'elementor-pro' ),
|
||||
'type' => 'group',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Classes\DynamicTags;
|
||||
|
||||
interface Data_Provider {
|
||||
|
||||
/**
|
||||
* @param array $args
|
||||
* @return string | bool
|
||||
*/
|
||||
public function get_value( array $args );
|
||||
|
||||
public function get_control_options(): array;
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Classes\DynamicTags;
|
||||
|
||||
use ElementorPro\Plugin;
|
||||
|
||||
class Dynamic_Tags_Data_Provider implements Data_Provider {
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $dynamic_tags_options = [];
|
||||
|
||||
/**
|
||||
* Build the dynamic tags options for the control. Add the groups and the items.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_control_options(): array {
|
||||
$result = [];
|
||||
$dynamic_tags_options = $this->get_dynamic_tags_options();
|
||||
|
||||
foreach ( $this->get_control_groups() as $group_key => $group_name ) {
|
||||
$result[ $group_key ] = [
|
||||
'label' => $group_name,
|
||||
'type' => 'group',
|
||||
];
|
||||
|
||||
$group_items = array_filter( $dynamic_tags_options, function( $item ) use ( $group_key ) {
|
||||
return $group_key === $item['group'];
|
||||
} );
|
||||
|
||||
$group_items = array_map( function( $item ) {
|
||||
return $item['label'];
|
||||
}, $group_items );
|
||||
|
||||
$result = $result + $group_items;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function get_default_control_option(): string {
|
||||
return array_key_first( $this->get_dynamic_tags_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return array
|
||||
*/
|
||||
public function get_dynamic_tag_options( string $key ): array {
|
||||
$dt_config = $this->get_dynamic_tags_options();
|
||||
|
||||
return ! empty( $dt_config[ $key ] ) ? $dt_config[ $key ] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function get_dynamic_tags_options(): array {
|
||||
if ( ! empty( $this->dynamic_tags_options ) ) {
|
||||
return $this->dynamic_tags_options;
|
||||
}
|
||||
|
||||
$dynamic_tags_config = Plugin::elementor()->dynamic_tags->get_config();
|
||||
|
||||
foreach ( $dynamic_tags_config['tags'] as $dynamic_tag_config ) {
|
||||
if ( empty( $dynamic_tag_config['display_conditions'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$new_options = array_map( function( $item ) use ( $dynamic_tag_config ) {
|
||||
return $item + [ 'dynamic_tag_name' => $dynamic_tag_config['name'] ];
|
||||
}, $dynamic_tag_config['display_conditions'] );
|
||||
|
||||
$this->dynamic_tags_options = $this->dynamic_tags_options + $new_options;
|
||||
}
|
||||
|
||||
return $this->dynamic_tags_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $args
|
||||
* @return string | bool
|
||||
*/
|
||||
public function get_value( array $args ) {
|
||||
$dt_options = $this->get_dynamic_tag_options( $args['dynamic_tag'] );
|
||||
|
||||
if ( empty( $dt_options ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Plugin::elementor()->dynamic_tags->get_tag_data_content( null, $dt_options['dynamic_tag_name'], $dt_options['settings'] ) ?? false;
|
||||
}
|
||||
|
||||
private function get_control_groups(): array {
|
||||
return [
|
||||
'archive' => esc_html__( 'Archive', 'elementor-pro' ),
|
||||
'featured_image' => esc_html__( 'Featured Image', 'elementor-pro' ),
|
||||
'author' => esc_html__( 'Author', 'elementor-pro' ),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Classes;
|
||||
|
||||
use Elementor\Core\Experiments\Manager;
|
||||
use ElementorPro\Plugin;
|
||||
use ElementorPro\Modules\DisplayConditions\Module as Display_Conditions_Module;
|
||||
|
||||
class Experiments {
|
||||
public static function register_dc_experiment() {
|
||||
Plugin::elementor()->experiments->add_feature( [
|
||||
'name' => Display_Conditions_Module::LICENSE_FEATURE_NAME,
|
||||
'title' => esc_html__( 'Display Conditions', 'elementor-pro' ),
|
||||
'description' => sprintf(
|
||||
/* translators: 1: opening link tag, 2: closing link tag, 3: line break, 4: opening span tag, 5: closing span tag. */
|
||||
esc_html__( 'Define one or multiple conditions per widget, controlling when they\'re visible. Widgets will only appear on the front end if these conditions are met. It\'s ideal for showing content to specific audiences based on time, date, user role, and more. %1$sLearn More%2$s%3$s%4$sRequires: Elementor version 3.19%5$s', 'elementor-pro' ),
|
||||
'<a href="https://go.elementor.com/wp-dash-display-conditions/" target="_blank">',
|
||||
'</a>',
|
||||
'<br>',
|
||||
'<span style="display: block; font-weight: 700; color: #21759b; font-style: italic; line-height: 18px; padding-block-start: 10px; margin-block-end: -5px;">',
|
||||
'</span>',
|
||||
),
|
||||
'release_status' => Manager::RELEASE_STATUS_BETA,
|
||||
'default' => Manager::STATE_INACTIVE,
|
||||
'new_site' => [
|
||||
'default_active' => true,
|
||||
'minimum_installation_version' => '3.20',
|
||||
],
|
||||
] );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Classes;
|
||||
|
||||
class Or_Condition {
|
||||
/**
|
||||
* @var $conditions_manager Object
|
||||
*/
|
||||
private $conditions_manager;
|
||||
|
||||
/**
|
||||
* @var $and_conditions And_Condition[]
|
||||
*/
|
||||
private $and_conditions;
|
||||
|
||||
public function __construct( $conditions_manager, $sets ) {
|
||||
$this->conditions_manager = $conditions_manager;
|
||||
$this->set_and_conditions( $sets );
|
||||
}
|
||||
|
||||
public function check() {
|
||||
if ( empty( $this->and_conditions ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ( $this->and_conditions as $condition ) {
|
||||
if ( $condition->check() ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function set_and_conditions( $groups ) {
|
||||
$this->and_conditions = array_map( function ( $condition ) {
|
||||
return new And_Condition( $this->conditions_manager, $condition );
|
||||
}, $groups );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Condition_Base;
|
||||
use ElementorPro\Modules\QueryControl\Module as QueryControlModule;
|
||||
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Archive_Of_Author_Condition extends Condition_Base {
|
||||
|
||||
public function get_name() {
|
||||
return 'archive_of_authors';
|
||||
}
|
||||
|
||||
public function get_label(): string {
|
||||
return esc_html__( 'Of Authors', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'archive';
|
||||
}
|
||||
|
||||
public function check( $args ) : bool {
|
||||
if ( empty( $args['authors'] ) ) {
|
||||
return parent::check( $args );
|
||||
}
|
||||
|
||||
$author_ids = array_column( $args['authors'], 'id' );
|
||||
|
||||
switch ( $args['comparator'] ) {
|
||||
case Comparator_Provider::COMPARATOR_IS:
|
||||
return $this->wordpress_adapter->is_author( $author_ids );
|
||||
|
||||
case Comparator_Provider::COMPARATOR_IS_NOT:
|
||||
return ! $this->wordpress_adapter->is_author( $author_ids );
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$comparators = Comparator_Provider::get_comparators( [
|
||||
Comparator_Provider::COMPARATOR_IS,
|
||||
Comparator_Provider::COMPARATOR_IS_NOT,
|
||||
] );
|
||||
|
||||
$this->add_control(
|
||||
'comparator',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => $comparators,
|
||||
'default' => Comparator_Provider::COMPARATOR_IS,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'authors',
|
||||
[
|
||||
'type' => QueryControlModule::QUERY_CONTROL_ID,
|
||||
'autocomplete' => [
|
||||
'object' => QueryControlModule::QUERY_OBJECT_AUTHOR,
|
||||
],
|
||||
'multiple' => true,
|
||||
'required' => true,
|
||||
'placeholder' => esc_html__( 'Type to search', 'elementor-pro' ),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Archive_Condition_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Archive_Of_Category_Condition extends Archive_Condition_Base {
|
||||
public function __construct() {
|
||||
parent::__construct( 'categories' );
|
||||
}
|
||||
|
||||
public function get_name() {
|
||||
return 'archive_of_categories';
|
||||
}
|
||||
|
||||
public function get_label(): string {
|
||||
return esc_html__( 'Of Categories', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function check( $args ): bool {
|
||||
return parent::check_is_of_taxonomy( $args );
|
||||
}
|
||||
|
||||
protected function is_of_taxonomy( $args ): bool {
|
||||
return is_category( array_column( $args['categories'], 'id' ) );
|
||||
}
|
||||
|
||||
protected function get_taxonomy() {
|
||||
return 'category';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Archive_Condition_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Archive_Of_Tag_Condition extends Archive_Condition_Base {
|
||||
public function __construct() {
|
||||
parent::__construct( 'tags' );
|
||||
}
|
||||
|
||||
public function get_name() {
|
||||
return 'archive_of_tags';
|
||||
}
|
||||
|
||||
public function get_label(): string {
|
||||
return esc_html__( 'Of Tags', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function check( $args ): bool {
|
||||
return parent::check_is_of_taxonomy( $args );
|
||||
}
|
||||
|
||||
protected function is_of_taxonomy( $args ): bool {
|
||||
return is_tag( array_column( $args['tags'], 'id' ) );
|
||||
}
|
||||
|
||||
protected function get_taxonomy() {
|
||||
return 'post_tag';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions\Base;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\QueryControl\Module as QueryControlModule;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
abstract class Archive_Condition_Base extends Condition_Base {
|
||||
|
||||
private string $condition_key;
|
||||
|
||||
public function __construct( $condition_key ) {
|
||||
$this->condition_key = $condition_key;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
abstract public function get_name();
|
||||
|
||||
abstract public function get_label();
|
||||
|
||||
abstract protected function get_taxonomy();
|
||||
|
||||
public function get_group(): string {
|
||||
return 'archive';
|
||||
}
|
||||
|
||||
abstract protected function is_of_taxonomy( $args ): bool;
|
||||
|
||||
protected function check_is_of_taxonomy( $args ) {
|
||||
switch ( $args['comparator'] ) {
|
||||
case Comparator_Provider::COMPARATOR_IS:
|
||||
return $this->is_of_taxonomy( $args );
|
||||
case Comparator_Provider::COMPARATOR_IS_NOT:
|
||||
return ! $this->is_of_taxonomy( $args );
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$comparators = Comparator_Provider::get_comparators( [
|
||||
Comparator_Provider::COMPARATOR_IS,
|
||||
Comparator_Provider::COMPARATOR_IS_NOT,
|
||||
] );
|
||||
$taxonomy = $this->get_taxonomy();
|
||||
|
||||
$this->add_control(
|
||||
'comparator',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => $comparators,
|
||||
'default' => Comparator_Provider::COMPARATOR_IS,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
$this->condition_key,
|
||||
[
|
||||
'type' => QueryControlModule::QUERY_CONTROL_ID,
|
||||
'autocomplete' => [
|
||||
'object' => QueryControlModule::QUERY_OBJECT_TAX,
|
||||
'query' => [
|
||||
'taxonomy' => $taxonomy,
|
||||
],
|
||||
],
|
||||
'multiple' => true,
|
||||
'required' => true,
|
||||
'placeholder' => esc_html__( 'Type to search', 'elementor-pro' ),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions\Base;
|
||||
|
||||
use Elementor\Controls_Stack;
|
||||
use ElementorPro\Core\Isolation\Wordpress_Adapter_Interface;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
abstract class Condition_Base extends Controls_Stack {
|
||||
|
||||
/**
|
||||
* @var Wordpress_Adapter_Interface
|
||||
*/
|
||||
protected $wordpress_adapter;
|
||||
|
||||
public function __construct( array $data = [] ) {
|
||||
$this->wordpress_adapter = array_pop( $data );
|
||||
parent::__construct( $data );
|
||||
}
|
||||
|
||||
abstract public function get_label();
|
||||
|
||||
abstract public function get_options();
|
||||
|
||||
public function get_group() {
|
||||
return 'other';
|
||||
}
|
||||
|
||||
public function check( $args ) : bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function register_controls() {
|
||||
$this->start_controls_section(
|
||||
'__settings'
|
||||
);
|
||||
|
||||
$this->get_options();
|
||||
|
||||
$this->end_controls_section();
|
||||
}
|
||||
|
||||
protected function get_initial_config() {
|
||||
$config = parent::get_initial_config();
|
||||
|
||||
$config['label'] = $this->get_label();
|
||||
$config['group'] = $this->get_group();
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions\Base;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparators_Checker;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
abstract class Date_Condition_Base extends Condition_Base {
|
||||
private $condition_key;
|
||||
private $group_key;
|
||||
|
||||
const COMPARATOR_KEY = 'comparator';
|
||||
const OPTION_KEY = 'date_type';
|
||||
|
||||
const DATE_FORMAT = 'm-d-Y';
|
||||
const OPTION_SERVER = 'server';
|
||||
const OPTION_CLIENT = 'client';
|
||||
|
||||
public function __construct( $condition_key, $group_key ) {
|
||||
$this->condition_key = $condition_key;
|
||||
$this->group_key = $group_key;
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return $this->group_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function get_time_options(): array {
|
||||
return [
|
||||
self::OPTION_SERVER => esc_html__( 'Server Time', 'elementor-pro' ),
|
||||
self::OPTION_CLIENT => esc_html__( 'Visitor Time', 'elementor-pro' ),
|
||||
];
|
||||
}
|
||||
|
||||
protected function check_date( $args, $date_to_check ): bool {
|
||||
$comparator = $args[ self::COMPARATOR_KEY ];
|
||||
$date_string = $args[ $this->condition_key ];
|
||||
$set_date = date_create_from_format( self::DATE_FORMAT, $date_string );
|
||||
|
||||
if ( ! $set_date || ! $date_to_check || ! $comparator || $set_date->format( self::DATE_FORMAT ) !== $date_string ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Comparators_Checker::check_date_time( $comparator, $date_to_check, $set_date );
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$this->add_control(
|
||||
self::COMPARATOR_KEY,
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => Comparator_Provider::get_comparators(
|
||||
[
|
||||
Comparator_Provider::COMPARATOR_IS,
|
||||
Comparator_Provider::COMPARATOR_IS_NOT,
|
||||
Comparator_Provider::COMPARATOR_IS_BEFORE,
|
||||
Comparator_Provider::COMPARATOR_IS_AFTER,
|
||||
Comparator_Provider::COMPARATOR_IS_BEFORE_INCLUSIVE,
|
||||
Comparator_Provider::COMPARATOR_IS_AFTER_INCLUSIVE,
|
||||
]
|
||||
),
|
||||
'default' => Comparator_Provider::COMPARATOR_IS,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
$this->condition_key,
|
||||
[
|
||||
'type' => Controls_Manager::DATE_TIME,
|
||||
'label' => $this::get_label(),
|
||||
'variant' => 'date',
|
||||
'required' => true,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
self::OPTION_KEY,
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => self::get_time_options(),
|
||||
'default' => self::OPTION_SERVER,
|
||||
'disabled_options' => [ self::OPTION_CLIENT ],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions\Base;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparators_Checker;
|
||||
use ElementorPro\Modules\QueryControl\Module as QueryControlModule;
|
||||
|
||||
abstract class Title_Condition_Base extends Condition_Base {
|
||||
abstract protected function get_query();
|
||||
|
||||
public function check( $args ) : bool {
|
||||
$titles = array_column( $args['titles'], 'text' );
|
||||
$title = get_the_title();
|
||||
$comparator = $args['comparator'];
|
||||
|
||||
return Comparators_Checker::check_array_contains( $comparator, [ $title ], $titles );
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$comparators = Comparator_Provider::get_comparators(
|
||||
[
|
||||
Comparator_Provider::COMPARATOR_IS,
|
||||
Comparator_Provider::COMPARATOR_IS_NOT,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'comparator',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => $comparators,
|
||||
'default' => Comparator_Provider::COMPARATOR_IS,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'titles',
|
||||
[
|
||||
'type' => QueryControlModule::QUERY_CONTROL_ID,
|
||||
'autocomplete' => [
|
||||
'object' => QueryControlModule::QUERY_OBJECT_POST,
|
||||
'query' => $this->get_query(),
|
||||
],
|
||||
'multiple' => true,
|
||||
'placeholder' => esc_html__( 'Type to search', 'elementor-pro' ),
|
||||
'required' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Date_Condition_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Current_Date_Condition extends Date_Condition_Base {
|
||||
const CONDITION_KEY = 'date';
|
||||
const GROUP_KEY = 'date';
|
||||
|
||||
public function get_name() {
|
||||
return 'current_date';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Current Date', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct( self::CONDITION_KEY, self::GROUP_KEY );
|
||||
}
|
||||
|
||||
public function check( $args ) : bool {
|
||||
return parent::check_date( $args, $this->get_current_date() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime|false
|
||||
*/
|
||||
private function get_current_date() {
|
||||
return date_create_from_format( self::DATE_FORMAT, gmdate( self::DATE_FORMAT ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Date_Condition_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Date_Of_Modification_Condition extends Date_Condition_Base {
|
||||
const CONDITION_KEY = 'date';
|
||||
const GROUP_KEY = 'date';
|
||||
|
||||
public function get_name() {
|
||||
return 'date_of_modification';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Date Modified', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'post';
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct( self::CONDITION_KEY, self::GROUP_KEY );
|
||||
}
|
||||
|
||||
public function check( $args ): bool {
|
||||
return parent::check_date( $args, $this->get_modification_date() );
|
||||
}
|
||||
|
||||
private function get_modification_date() {
|
||||
return date_create_from_format(
|
||||
self::DATE_FORMAT,
|
||||
get_the_modified_date( self::DATE_FORMAT, get_the_ID() )
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Date_Condition_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Date_Of_Publish_Condition extends Date_Condition_Base {
|
||||
const CONDITION_KEY = 'date';
|
||||
const GROUP_KEY = 'date';
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct( self::CONDITION_KEY, self::GROUP_KEY );
|
||||
}
|
||||
|
||||
public function get_name() {
|
||||
return 'date_of_publish';
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'post';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Date of Publish', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function check( $args ): bool {
|
||||
return parent::check_date( $args, $this->get_post_date() );
|
||||
}
|
||||
|
||||
private function get_post_date() {
|
||||
return date_create_from_format(
|
||||
self::DATE_FORMAT,
|
||||
get_the_date( self::DATE_FORMAT, get_the_ID() )
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparators_Checker;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Condition_Base;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Date_Condition_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Day_Of_The_Week_Condition extends Condition_Base {
|
||||
const CONDITION_KEY = 'days';
|
||||
|
||||
public function get_name() {
|
||||
return 'day_of_the_week';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Day of the week', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'date';
|
||||
}
|
||||
|
||||
public function check( $args ) : bool {
|
||||
return Comparators_Checker::check_array_contains( $args['comparator'], [ strtolower( gmdate( 'l' ) ) ], $args['days'] );
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$comparators = Comparator_Provider::get_comparators(
|
||||
[
|
||||
Comparator_Provider::COMPARATOR_IS_ONE_OF,
|
||||
Comparator_Provider::COMPARATOR_IS_NONE_OF,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'comparator',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => $comparators,
|
||||
'default' => Comparator_Provider::COMPARATOR_IS_ONE_OF,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
self::CONDITION_KEY,
|
||||
[
|
||||
'type' => Controls_Manager::SELECT2,
|
||||
'options' => [
|
||||
'monday' => esc_html__( 'Monday', 'elementor-pro' ),
|
||||
'tuesday' => esc_html__( 'Tuesday', 'elementor-pro' ),
|
||||
'wednesday' => esc_html__( 'Wednesday', 'elementor-pro' ),
|
||||
'thursday' => esc_html__( 'Thursday', 'elementor-pro' ),
|
||||
'friday' => esc_html__( 'Friday', 'elementor-pro' ),
|
||||
'saturday' => esc_html__( 'Saturday', 'elementor-pro' ),
|
||||
'sunday' => esc_html__( 'Sunday', 'elementor-pro' ),
|
||||
],
|
||||
'multiple' => true,
|
||||
'required' => true,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'time_type',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => Date_Condition_Base::get_time_options(),
|
||||
'default' => Date_Condition_Base::OPTION_SERVER,
|
||||
'disabled_options' => [ Date_Condition_Base::OPTION_CLIENT ],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparators_Checker;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\DynamicTags\Custom_Fields_Data_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\DynamicTags\Dynamic_Tags_Data_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Condition_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Dynamic_Tags_Condition extends Condition_Base {
|
||||
|
||||
/**
|
||||
* @var Dynamic_Tags_Data_Provider
|
||||
*/
|
||||
private $dynamic_tags_data_provider;
|
||||
|
||||
/**
|
||||
* @var Custom_Fields_Data_Provider
|
||||
*/
|
||||
private $custom_fields_data_provider;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->dynamic_tags_data_provider = new Dynamic_Tags_Data_Provider();
|
||||
$this->custom_fields_data_provider = new Custom_Fields_Data_Provider();
|
||||
}
|
||||
|
||||
public function get_name() {
|
||||
return 'dynamic_tags';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Dynamic Tags', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'other';
|
||||
}
|
||||
|
||||
public function check( $args ) : bool {
|
||||
$value = $this->get_condition_value( $args );
|
||||
|
||||
if ( false === $value ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Comparators_Checker::check_string_contains_and_empty( $args['comparator'], $args['dynamic_tag_value'], $value );
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$this->add_control(
|
||||
'dynamic_tag',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => $this->dynamic_tags_data_provider->get_control_options() + $this->custom_fields_data_provider->get_control_options(),
|
||||
'default' => $this->dynamic_tags_data_provider->get_default_control_option(),
|
||||
'disabled_options' => ! current_user_can( 'manage_options' ) ? [ 'author_info_email' ] : [],
|
||||
'disabled_type' => 'hidden',
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'comparator',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => Comparator_Provider::get_comparators(
|
||||
[
|
||||
Comparator_Provider::COMPARATOR_IS,
|
||||
Comparator_Provider::COMPARATOR_IS_NOT,
|
||||
Comparator_Provider::COMPARATOR_CONTAINS,
|
||||
Comparator_Provider::COMPARATOR_NOT_CONTAIN,
|
||||
Comparator_Provider::COMPARATOR_IS_EMPTY,
|
||||
Comparator_Provider::COMPARATOR_IS_NOT_EMPTY,
|
||||
]
|
||||
),
|
||||
'default' => Comparator_Provider::COMPARATOR_IS,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'dynamic_tag_value',
|
||||
[
|
||||
'placeholder' => esc_html__( 'Type a value', 'elementor-pro' ),
|
||||
'required' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Conditionally retrieve the value of a dynamic tag or custom field.
|
||||
*
|
||||
* @return string | bool
|
||||
*/
|
||||
private function get_condition_value( array $args ) {
|
||||
$dt_value = $this->dynamic_tags_data_provider->get_value( $args );
|
||||
|
||||
if ( $dt_value ) {
|
||||
return $dt_value;
|
||||
}
|
||||
|
||||
return $this->custom_fields_data_provider->get_value( $args );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparators_Checker;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Condition_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Featured_Image_Condition extends Condition_Base {
|
||||
|
||||
public function get_name() {
|
||||
return 'featured_image';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Featured Image', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'post';
|
||||
}
|
||||
|
||||
public function check( $args ) : bool {
|
||||
return Comparators_Checker::check_equality(
|
||||
$args['comparator'],
|
||||
'set' === $args['status'],
|
||||
$this->wordpress_adapter->has_post_thumbnail()
|
||||
);
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$comparators = Comparator_Provider::get_comparators(
|
||||
[
|
||||
Comparator_Provider::COMPARATOR_IS,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'comparator',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => $comparators,
|
||||
'default' => Comparator_Provider::COMPARATOR_IS,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'status',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => [
|
||||
'set' => esc_html__( 'Set', 'elementor-pro' ),
|
||||
'not_set' => esc_html__( 'Not Set', 'elementor-pro' ),
|
||||
],
|
||||
'default' => 'set',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparators_Checker;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Condition_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class From_URL_Condition extends Condition_Base {
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'From URL', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$comparators = Comparator_Provider::get_comparators(
|
||||
[
|
||||
Comparator_Provider::COMPARATOR_IS,
|
||||
Comparator_Provider::COMPARATOR_IS_NOT,
|
||||
Comparator_Provider::COMPARATOR_CONTAINS,
|
||||
Comparator_Provider::COMPARATOR_NOT_CONTAIN,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'comparator',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => $comparators,
|
||||
'default' => Comparator_Provider::COMPARATOR_IS,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'from_url',
|
||||
[
|
||||
'label' => esc_html__( 'URL', 'elementor-pro' ),
|
||||
'type' => Controls_Manager::TEXT,
|
||||
'placeholder' => esc_html__( 'URL', 'elementor-pro' ),
|
||||
'required' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function get_name() {
|
||||
return 'from_url';
|
||||
}
|
||||
|
||||
public function wp_get_referer() {
|
||||
return wp_get_raw_referer();
|
||||
}
|
||||
|
||||
public function check( $args ) : bool {
|
||||
$referrer = $this->wp_get_referer();
|
||||
|
||||
return Comparators_Checker::check_string_contains( $args['comparator'], $args['from_url'], $referrer );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparators_Checker;
|
||||
use ElementorPro\Modules\QueryControl\Module as QueryControlModule;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Condition_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class In_Categories_Condition extends Condition_Base {
|
||||
|
||||
public function get_name() {
|
||||
return 'in_categories';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'In Categories', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'post';
|
||||
}
|
||||
|
||||
public function check( $args ): bool {
|
||||
if ( empty( $args['categories'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$post_categories = wp_get_post_categories( get_the_ID(), [ 'fields' => 'ids' ] ) ?? [];
|
||||
|
||||
if ( empty( $post_categories ) ) {
|
||||
return ! ( Comparator_Provider::COMPARATOR_IS === $args['comparator'] );
|
||||
}
|
||||
|
||||
$category_ids = array_column( $args['categories'], 'id' );
|
||||
|
||||
return Comparators_Checker::check_array_contains( $args['comparator'], $category_ids, $post_categories );
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$comparators = Comparator_Provider::get_comparators(
|
||||
[
|
||||
Comparator_Provider::COMPARATOR_IS,
|
||||
Comparator_Provider::COMPARATOR_IS_NOT,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'comparator',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => $comparators,
|
||||
'default' => Comparator_Provider::COMPARATOR_IS,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'categories',
|
||||
[
|
||||
'type' => QueryControlModule::QUERY_CONTROL_ID,
|
||||
'autocomplete' => [
|
||||
'object' => QueryControlModule::QUERY_OBJECT_TAX,
|
||||
'query' => [
|
||||
'taxonomy' => 'category',
|
||||
],
|
||||
],
|
||||
'multiple' => true,
|
||||
'placeholder' => esc_html__( 'Type to search', 'elementor-pro' ),
|
||||
'required' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparators_Checker;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Condition_Base;
|
||||
use ElementorPro\Modules\QueryControl\Module as QueryControlModule;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class In_Tags_Condition extends Condition_Base {
|
||||
|
||||
public function get_name() {
|
||||
return 'in_tags';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'In Tags', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'post';
|
||||
}
|
||||
|
||||
public function check( $args ) : bool {
|
||||
if ( empty( $args['tags'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$post_tags = wp_get_post_tags( get_the_ID(), [ 'fields' => 'ids' ] ) ?? [];
|
||||
|
||||
$tag_ids = array_column( $args['tags'], 'id' );
|
||||
|
||||
return Comparators_Checker::check_array_contains( $args['comparator'], $tag_ids, $post_tags );
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$comparators = Comparator_Provider::get_comparators(
|
||||
[
|
||||
Comparator_Provider::COMPARATOR_IS,
|
||||
Comparator_Provider::COMPARATOR_IS_NOT,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'comparator',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => $comparators,
|
||||
'default' => Comparator_Provider::COMPARATOR_IS,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'tags',
|
||||
[
|
||||
'type' => QueryControlModule::QUERY_CONTROL_ID,
|
||||
'autocomplete' => [
|
||||
'object' => QueryControlModule::QUERY_OBJECT_TAX,
|
||||
'query' => [
|
||||
'taxonomy' => 'post_tag',
|
||||
],
|
||||
],
|
||||
'multiple' => true,
|
||||
'placeholder' => esc_html__( 'Type to search', 'elementor-pro' ),
|
||||
'required' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparators_Checker;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Condition_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Login_Status_Condition extends Condition_Base {
|
||||
|
||||
public function get_name() {
|
||||
return 'login_status';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Login Status', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'user';
|
||||
}
|
||||
|
||||
public function check( $args ) : bool {
|
||||
return Comparators_Checker::check_equality( $args['comparator'], 'logged_in' === $args['status'], is_user_logged_in() );
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$comparators = Comparator_Provider::get_comparators(
|
||||
[
|
||||
Comparator_Provider::COMPARATOR_IS,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'comparator',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => $comparators,
|
||||
'default' => Comparator_Provider::COMPARATOR_IS,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'status',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => [
|
||||
'logged_in' => esc_html__( 'Logged In', 'elementor-pro' ),
|
||||
'logged_out' => esc_html__( 'Logged Out', 'elementor-pro' ),
|
||||
],
|
||||
'default' => 'logged_in',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparators_Checker;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Condition_Base;
|
||||
use ElementorPro\Modules\QueryControl\Module as QueryControlModule;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Page_Author_Condition extends Condition_Base {
|
||||
|
||||
public function get_name() {
|
||||
return 'page_author';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Author', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'page';
|
||||
}
|
||||
|
||||
public function check( $args ) : bool {
|
||||
if ( empty( $args['authors'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$current_post = get_post();
|
||||
|
||||
if ( ! $current_post ) {
|
||||
return parent::check( $args );
|
||||
}
|
||||
|
||||
$author_ids = array_column( $args['authors'], 'id' );
|
||||
|
||||
return Comparators_Checker::check_array_contains( $args['comparator'], [ $current_post->post_author ], $author_ids );
|
||||
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$comparators = Comparator_Provider::get_comparators(
|
||||
[
|
||||
Comparator_Provider::COMPARATOR_IS,
|
||||
Comparator_Provider::COMPARATOR_IS_NOT,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'comparator',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => $comparators,
|
||||
'default' => Comparator_Provider::COMPARATOR_IS,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'authors',
|
||||
[
|
||||
'label' => esc_html__( 'Author', 'elementor-pro' ),
|
||||
'type' => QueryControlModule::QUERY_CONTROL_ID,
|
||||
'autocomplete' => [
|
||||
'object' => QueryControlModule::QUERY_OBJECT_AUTHOR,
|
||||
],
|
||||
'multiple' => true,
|
||||
'placeholder' => esc_html__( 'Type to search', 'elementor-pro' ),
|
||||
'required' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparators_Checker;
|
||||
use ElementorPro\Modules\QueryControl\Module as QueryControlModule;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Condition_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Page_Parent_Condition extends Condition_Base {
|
||||
|
||||
public function get_name() {
|
||||
return 'page_parent';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Page Parent', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'page';
|
||||
}
|
||||
|
||||
public function check( $args ) : bool {
|
||||
if ( empty( $args['pages'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$current_post = get_post();
|
||||
|
||||
$parent_page_ids = array_column( $args['pages'], 'id' );
|
||||
|
||||
return Comparators_Checker::check_array_contains( $args['comparator'], [ $current_post->post_parent ], $parent_page_ids );
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$comparators = Comparator_Provider::get_comparators(
|
||||
[
|
||||
Comparator_Provider::COMPARATOR_IS_ONE_OF,
|
||||
Comparator_Provider::COMPARATOR_IS_NONE_OF,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'comparator',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => $comparators,
|
||||
'default' => Comparator_Provider::COMPARATOR_IS_ONE_OF,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'pages',
|
||||
[
|
||||
'type' => QueryControlModule::QUERY_CONTROL_ID,
|
||||
'autocomplete' => [
|
||||
'object' => QueryControlModule::QUERY_OBJECT_POST,
|
||||
'query' => [
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'page',
|
||||
],
|
||||
],
|
||||
'multiple' => true,
|
||||
'placeholder' => esc_html__( 'Type to search', 'elementor-pro' ),
|
||||
'required' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Title_Condition_Base;
|
||||
|
||||
class Page_Title_Condition extends Title_Condition_Base {
|
||||
|
||||
public function get_name() {
|
||||
return 'page_title';
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'page';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Page Title', 'elementor-pro' );
|
||||
}
|
||||
|
||||
protected function get_query() {
|
||||
return [
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'page',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
class Post_Author_Condition extends Page_Author_Condition {
|
||||
|
||||
public function get_name() {
|
||||
return 'post_author';
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'post';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparators_Checker;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Condition_Base;
|
||||
|
||||
class Post_Number_Of_Comments_Condition extends Condition_Base {
|
||||
|
||||
public function get_name() {
|
||||
return 'number_of_comments';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Number of Comments', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return esc_html__( 'post', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function check( $args ): bool {
|
||||
$actual_number_of_comments = $this->wordpress_adapter->get_comments_number();
|
||||
|
||||
return Comparators_Checker::check_numeric_constraints( $args['comparator'], (int) $args['number_of_comments'], (int) $actual_number_of_comments );
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$comparators = Comparator_Provider::get_comparators(
|
||||
[
|
||||
Comparator_Provider::COMPARATOR_IS_GREATER_THAN_INCLUSIVE,
|
||||
Comparator_Provider::COMPARATOR_IS_LESS_THAN_INCLUSIVE,
|
||||
Comparator_Provider::COMPARATOR_IS,
|
||||
Comparator_Provider::COMPARATOR_IS_NOT,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'comparator',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => $comparators,
|
||||
'default' => Comparator_Provider::COMPARATOR_IS,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'number_of_comments',
|
||||
[
|
||||
'type' => Controls_Manager::TEXT,
|
||||
'input_type' => 'number',
|
||||
'variant' => 'number',
|
||||
'placeholder' => 'Type a number...',
|
||||
'step' => 1,
|
||||
'min' => 0,
|
||||
'default' => 1,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Title_Condition_Base;
|
||||
|
||||
class Post_Title_Condition extends Title_Condition_Base {
|
||||
|
||||
public function get_name() {
|
||||
return 'post_title';
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'post';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Post Title', 'elementor-pro' );
|
||||
}
|
||||
|
||||
protected function get_query() {
|
||||
return [
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'post',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use DateTime;
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparators_Checker;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Condition_Base;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Date_Condition_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Time_Of_The_Day_Condition extends Condition_Base {
|
||||
|
||||
public function get_name() {
|
||||
return 'time_of_the_day';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Time of the day', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'date';
|
||||
}
|
||||
|
||||
public function get_gm_date() {
|
||||
return gmdate( 'H:i' );
|
||||
}
|
||||
|
||||
public function check( $args ) : bool {
|
||||
if ( empty( $args['time'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$time_now = $this->get_gm_date();
|
||||
$expected_time = $this->convert_date_time_to_24_hour_format( $args['time'] );
|
||||
|
||||
return Comparators_Checker::check_date_time( $args['comparator'], $time_now, $expected_time );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $date_time_string
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function convert_date_time_to_24_hour_format( $date_time_string ): string {
|
||||
|
||||
if ( ! $this->is_valid_date_time_string( $date_time_string ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$date_time = DateTime::createFromFormat( 'm-d-Y H:i', $date_time_string );
|
||||
|
||||
return $date_time->format( 'H:i' );
|
||||
}
|
||||
|
||||
private function is_valid_date_time_string( $date_time_string ): bool {
|
||||
$date_time = DateTime::createFromFormat( 'm-d-Y H:i', $date_time_string );
|
||||
|
||||
if ( ! $date_time || $date_time->format( 'm-d-Y H:i' ) !== $date_time_string ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$comparators = Comparator_Provider::get_comparators(
|
||||
[
|
||||
Comparator_Provider::COMPARATOR_IS,
|
||||
Comparator_Provider::COMPARATOR_IS_NOT,
|
||||
Comparator_Provider::COMPARATOR_IS_BEFORE,
|
||||
Comparator_Provider::COMPARATOR_IS_AFTER,
|
||||
Comparator_Provider::COMPARATOR_IS_BEFORE_INCLUSIVE,
|
||||
Comparator_Provider::COMPARATOR_IS_AFTER_INCLUSIVE,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'comparator',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => $comparators,
|
||||
'default' => Comparator_Provider::COMPARATOR_IS,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'time',
|
||||
[
|
||||
'type' => Controls_Manager::DATE_TIME,
|
||||
'variant' => 'time',
|
||||
'required' => true,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'time_type',
|
||||
[
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => Date_Condition_Base::get_time_options(),
|
||||
'default' => Date_Condition_Base::OPTION_SERVER,
|
||||
'disabled_options' => Date_Condition_Base::OPTION_CLIENT,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparators_Checker;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Date_Condition_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class User_Registration_Date_Condition extends Date_Condition_Base {
|
||||
const CONDITION_KEY = 'date';
|
||||
const GROUP_KEY = 'user';
|
||||
|
||||
public function get_name() {
|
||||
return 'user_registration_date';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Registration Date', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct( self::CONDITION_KEY, self::GROUP_KEY );
|
||||
}
|
||||
|
||||
public function check( $args ) : bool {
|
||||
return parent::check_date( $args, $this->get_user_registration_date() );
|
||||
}
|
||||
|
||||
private function get_user_registration_date() {
|
||||
$registration_date = date_create( wp_get_current_user()->user_registered )->format( self::DATE_FORMAT );
|
||||
$registration_date = date_create_from_format( self::DATE_FORMAT, $registration_date );
|
||||
|
||||
return $registration_date;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions\Conditions;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparator_Provider;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Comparators_Checker;
|
||||
use ElementorPro\Modules\DisplayConditions\Conditions\Base\Condition_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class User_Role_Condition extends Condition_Base {
|
||||
const CONDITION_KEY = 'roles';
|
||||
|
||||
public function get_name() {
|
||||
return 'user_role';
|
||||
}
|
||||
|
||||
public function get_label() {
|
||||
return esc_html__( 'Role', 'elementor-pro' );
|
||||
}
|
||||
|
||||
public function get_group() {
|
||||
return 'user';
|
||||
}
|
||||
|
||||
public function check( $args ) : bool {
|
||||
$current_user = wp_get_current_user();
|
||||
$current_user_roles = $current_user ? $current_user->roles : [];
|
||||
|
||||
return Comparators_Checker::check_array_contains( $args['comparator'], $current_user_roles, $args['roles'] );
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
$user_roles = $this->get_available_roles();
|
||||
|
||||
$comparators = Comparator_Provider::get_comparators(
|
||||
[
|
||||
Comparator_Provider::COMPARATOR_IS_ONE_OF,
|
||||
Comparator_Provider::COMPARATOR_IS_NONE_OF,
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control( 'comparator', [
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'options' => $comparators,
|
||||
'default' => Comparator_Provider::COMPARATOR_IS_ONE_OF,
|
||||
] );
|
||||
|
||||
$this->add_control( self::CONDITION_KEY, [
|
||||
'type' => Controls_Manager::SELECT2,
|
||||
'options' => $user_roles,
|
||||
'multiple' => true,
|
||||
'required' => true,
|
||||
'default' => [],
|
||||
] );
|
||||
}
|
||||
|
||||
private function get_available_roles(): array {
|
||||
$user_roles = [];
|
||||
|
||||
foreach ( get_editable_roles() as $role_slug => $role_data ) {
|
||||
$role = $role_data['name'];
|
||||
$user_roles[ $role_slug ] = esc_html( $role );
|
||||
}
|
||||
|
||||
return $user_roles;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\DisplayConditions;
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use Elementor\Utils;
|
||||
use ElementorPro\Base\Module_Base;
|
||||
use ElementorPro\License\API;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Experiments;
|
||||
use ElementorPro\Modules\DisplayConditions\Classes\Or_Condition;
|
||||
use ElementorPro\Plugin;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Module extends Module_Base {
|
||||
|
||||
private $hidden_elements_ids = array();
|
||||
|
||||
const LICENSE_FEATURE_NAME = 'display-conditions';
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
if ( ! self::can_use_display_conditions() ) {
|
||||
$this->add_common_actions();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->register_display_conditions_experiments();
|
||||
$this->maybe_add_actions_and_components();
|
||||
}
|
||||
|
||||
public static function is_experiment_active(): bool {
|
||||
return Plugin::elementor()::$instance->experiments->is_feature_active( self::LICENSE_FEATURE_NAME );
|
||||
}
|
||||
|
||||
public static function should_show_promo(): bool {
|
||||
return ! self::can_use_display_conditions();
|
||||
}
|
||||
|
||||
private function add_actions() {
|
||||
$this->add_render_actions();
|
||||
|
||||
add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
|
||||
}
|
||||
|
||||
private function add_components() {
|
||||
$this->add_component( 'conditions', new Classes\Conditions_Manager( $this ) );
|
||||
$this->add_component( 'cache_notice', new Classes\Cache_Notice() );
|
||||
}
|
||||
|
||||
private function add_common_actions() {
|
||||
$this->add_advanced_tab_actions();
|
||||
|
||||
add_action( 'elementor/editor/before_enqueue_scripts', function() {
|
||||
$this->enqueue_main_script();
|
||||
} );
|
||||
}
|
||||
|
||||
private function enqueue_main_script() {
|
||||
$min_suffix = Utils::is_script_debug() ? '' : '.min';
|
||||
|
||||
wp_enqueue_script(
|
||||
'e-display-conditions',
|
||||
ELEMENTOR_PRO_ASSETS_URL . 'js/display-conditions' . $min_suffix . '.js',
|
||||
[
|
||||
'react',
|
||||
'react-dom',
|
||||
'backbone-marionette',
|
||||
'elementor-web-cli',
|
||||
'wp-date',
|
||||
'elementor-common',
|
||||
'elementor-editor-modules',
|
||||
'elementor-editor-document',
|
||||
'elementor-v2-ui',
|
||||
'elementor-v2-icons',
|
||||
],
|
||||
ELEMENTOR_PRO_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
wp_set_script_translations( 'e-display-conditions', 'elementor-pro' );
|
||||
}
|
||||
|
||||
private function add_advanced_tab_actions() {
|
||||
$hooks = array(
|
||||
'elementor/element/section/section_advanced/after_section_end' => 'css_classes', // Sections
|
||||
'elementor/element/column/section_advanced/after_section_end' => 'css_classes', // Columns
|
||||
'elementor/element/common/_section_style/after_section_end' => '_css_classes', // Widgets
|
||||
'elementor/element/container/section_layout/after_section_end' => 'css_classes', // Containers
|
||||
);
|
||||
|
||||
foreach ( $hooks as $hook => $injection_position ) {
|
||||
add_action(
|
||||
$hook,
|
||||
function( $element, $args ) use ( $injection_position ) {
|
||||
$this->add_control_to_advanced_tab( $element, $args, $injection_position );
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function add_render_actions() {
|
||||
$element_types = array(
|
||||
'section',
|
||||
'column',
|
||||
'widget',
|
||||
'container',
|
||||
);
|
||||
|
||||
foreach ( $element_types as $el ) {
|
||||
add_action( 'elementor/frontend/' . $el . '/before_render', array( $this, 'before_element_render' ) );
|
||||
add_action( 'elementor/frontend/' . $el . '/after_render', array( $this, 'after_element_render' ) );
|
||||
}
|
||||
}
|
||||
|
||||
private function add_control_to_advanced_tab( $element, $args, $injection_position ) {
|
||||
$element->start_injection(
|
||||
array(
|
||||
'of' => $injection_position,
|
||||
)
|
||||
);
|
||||
|
||||
$element->add_control(
|
||||
'e_display_conditions_trigger',
|
||||
array(
|
||||
'type' => Controls_Manager::RAW_HTML,
|
||||
'separator' => 'before',
|
||||
'raw' => $this->get_display_conditions_control_template(),
|
||||
)
|
||||
);
|
||||
|
||||
$element->add_control(
|
||||
'e_display_conditions',
|
||||
array(
|
||||
'type' => Controls_Manager::HIDDEN,
|
||||
)
|
||||
);
|
||||
|
||||
$element->end_injection();
|
||||
}
|
||||
|
||||
private function get_display_conditions_control_template() {
|
||||
$icon_class = 'e-control-display-conditions';
|
||||
$show_promo = self::should_show_promo();
|
||||
|
||||
if ( $show_promo ) {
|
||||
$icon_class .= '-promo';
|
||||
}
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div class="e-control-display-conditions__wrapper">
|
||||
<span class="e-control-display-conditions__desc">
|
||||
<?php echo esc_html__( 'Display Conditions', 'elementor-pro' ); ?>
|
||||
<?php if ( $show_promo ) : ?>
|
||||
<i class="eicon-lock"></i>
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
<i class="eicon-flow <?php echo esc_attr( $icon_class ); ?>"></i>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
protected function get_saved_conditions( $settings ) {
|
||||
$conditions_json = ! empty( $settings['e_display_conditions'] ) ? $settings['e_display_conditions'] : [];
|
||||
|
||||
return ! empty( $conditions_json ) && ! empty( $conditions_json[0] )
|
||||
? json_decode( $conditions_json[0], true )
|
||||
: [];
|
||||
}
|
||||
|
||||
public function before_element_render( $element ) {
|
||||
$settings = $element->get_settings_for_display();
|
||||
$is_visible = true;
|
||||
$saved_conditions = $this->get_saved_conditions( $settings );
|
||||
|
||||
if ( empty( $settings['e_display_conditions'] ) || Plugin::elementor()->editor->is_edit_mode() || empty( $saved_conditions ) ) {
|
||||
return $is_visible;
|
||||
}
|
||||
|
||||
$saved_conditions = $this->get_converted_conditions( $saved_conditions );
|
||||
$saved_conditions = new Or_Condition( $this->get_conditions_manager(), $saved_conditions );
|
||||
$is_visible = $saved_conditions->check();
|
||||
|
||||
if ( ! $is_visible ) {
|
||||
add_filter( 'elementor/element/get_child_type', '__return_false' ); // Prevent getting content of inner elements.
|
||||
add_filter( 'elementor/frontend/' . $element->get_type() . '/should_render', '__return_false' );
|
||||
|
||||
$this->hidden_elements_ids[] = $element->get_id();
|
||||
}
|
||||
}
|
||||
|
||||
public function after_element_render( $element ) {
|
||||
if ( ! in_array( $element->get_id(), $this->hidden_elements_ids, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
remove_filter( 'elementor/element/get_child_type', '__return_false' );
|
||||
remove_filter( 'elementor/frontend/' . $element->get_type() . '/should_render', '__return_false' );
|
||||
}
|
||||
|
||||
public function register_display_conditions_experiments() {
|
||||
if ( ! self::can_use_display_conditions() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Experiments::register_dc_experiment();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_name() {
|
||||
return static::LICENSE_FEATURE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Classes\Conditions_Manager
|
||||
*/
|
||||
public function get_conditions_manager() {
|
||||
return $this->get_component( 'conditions' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Ajax $ajax_manager
|
||||
*/
|
||||
public function register_ajax_actions( $ajax_manager ) {
|
||||
$ajax_manager->register_ajax_action( 'display_conditions_set_cache_notice_status', [ $this->get_component( 'cache_notice' ), 'set_notice_status' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function can_use_display_conditions(): bool {
|
||||
return API::is_license_active() && API::is_licence_has_feature( self::LICENSE_FEATURE_NAME, API::BC_VALIDATION_CALLBACK );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function maybe_add_actions_and_components(): void {
|
||||
if ( self::is_experiment_active() ) {
|
||||
$this->add_common_actions();
|
||||
$this->add_actions();
|
||||
$this->add_components();
|
||||
}
|
||||
}
|
||||
|
||||
private function get_converted_conditions( $conditions ) {
|
||||
foreach ( $conditions as $condition ) {
|
||||
if ( ! isset( $condition['condition'] ) ) {
|
||||
return $conditions;
|
||||
}
|
||||
}
|
||||
return count( $conditions )
|
||||
? [ $conditions ]
|
||||
: [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user