acf-boolean.php
3 years ago
acf-choice.php
3 years ago
acf-text.php
3 years ago
browser.php
3 years ago
condition.php
3 years ago
date-range.php
3 years ago
date.php
3 years ago
day.php
3 years ago
device.php
3 years ago
ip-location.php
3 years ago
lang.php
3 years ago
login-status.php
3 years ago
operating-system.php
3 years ago
page.php
3 years ago
post-type.php
3 years ago
post.php
3 years ago
return-visitor.php
3 years ago
shortcode.php
3 years ago
static-page.php
3 years ago
time-range.php
3 years ago
url-referer.php
3 years ago
url-string.php
3 years ago
user-role.php
3 years ago
woo-cart-products.php
3 years ago
woo-cat-page.php
3 years ago
woo-category.php
3 years ago
woo-last-purchase.php
3 years ago
woo-orders.php
3 years ago
woo-product-cat.php
3 years ago
woo-product-price.php
3 years ago
woo-product-stock.php
3 years ago
woo-total-price.php
3 years ago
time-range.php
99 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Time Range Condition Handler. |
| 4 | */ |
| 5 | |
| 6 | namespace PremiumAddons\Includes\PA_Display_Conditions\Conditions; |
| 7 | |
| 8 | // Elementor Classes. |
| 9 | use Elementor\Controls_Manager; |
| 10 | |
| 11 | // PA Classes. |
| 12 | use PremiumAddons\Includes\Helper_Functions; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; // Exit if accessed directly. |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Class Time_Range. |
| 20 | */ |
| 21 | class Time_Range extends Condition { |
| 22 | |
| 23 | /** |
| 24 | * Get Controls Options. |
| 25 | * |
| 26 | * @access public |
| 27 | * @since 4.7.0 |
| 28 | * |
| 29 | * @return array|void controls options |
| 30 | */ |
| 31 | public function get_control_options() { |
| 32 | |
| 33 | return array( |
| 34 | 'label' => __( 'To', 'premium-addons-for-elementor' ), |
| 35 | 'type' => Controls_Manager::DATE_TIME, |
| 36 | 'label_block' => true, |
| 37 | 'picker_options' => array( |
| 38 | 'noCalendar' => true, |
| 39 | 'enableTime' => true, |
| 40 | 'dateFormat' => 'H:i', |
| 41 | ), |
| 42 | 'condition' => array( |
| 43 | 'pa_condition_key' => 'time_range', |
| 44 | ), |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Get Value Controls Options. |
| 50 | * |
| 51 | * @access public |
| 52 | * @since 4.7.0 |
| 53 | * |
| 54 | * @return array controls options. |
| 55 | */ |
| 56 | public function add_value_control() { |
| 57 | |
| 58 | return array( |
| 59 | 'label' => __( 'From', 'premium-addons-for-elementor' ), |
| 60 | 'type' => Controls_Manager::DATE_TIME, |
| 61 | 'label_block' => true, |
| 62 | 'picker_options' => array( |
| 63 | 'noCalendar' => true, |
| 64 | 'enableTime' => true, |
| 65 | 'dateFormat' => 'H:i', |
| 66 | ), |
| 67 | 'condition' => array( |
| 68 | 'pa_condition_key' => 'time_range', |
| 69 | ), |
| 70 | ); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Compare Condition Value. |
| 75 | * |
| 76 | * @access public |
| 77 | * @since 4.7.0 |
| 78 | * |
| 79 | * @param array $settings element settings. |
| 80 | * @param string $operator condition operator. |
| 81 | * @param string $to range start value. |
| 82 | * @param string $from range end value. |
| 83 | * @param string|bool $tz time zone. |
| 84 | * |
| 85 | * @return bool|void |
| 86 | */ |
| 87 | public function compare_value( $settings, $operator, $to, $from, $tz ) { |
| 88 | |
| 89 | $to = strtotime( gmdate( 'H:i', strtotime( $to ) ) ); |
| 90 | $from = strtotime( gmdate( 'H:i', strtotime( $from ) ) ); |
| 91 | |
| 92 | $now = 'local' === $tz ? strtotime( Helper_Functions::get_local_time( 'H:i' ) ) : strtotime( Helper_Functions::get_site_server_time( 'H:i' ) ); |
| 93 | $condition_result = ( ( $now >= $from ) && ( $now <= $to ) ); |
| 94 | |
| 95 | return Helper_Functions::get_final_result( $condition_result, $operator ); |
| 96 | } |
| 97 | |
| 98 | } |
| 99 |