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 );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user