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
acf-boolean.php
134 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Acf Boolean 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\ACF_Helper; |
| 13 | use PremiumAddons\Includes\Helper_Functions; |
| 14 | use PremiumAddons\Includes\Controls\Premium_Acf_Selector; |
| 15 | |
| 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | exit; // Exit if accessed directly. |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Class Acf_Boolean. |
| 22 | */ |
| 23 | class Acf_Boolean extends Condition { |
| 24 | |
| 25 | /** |
| 26 | * Holds defaults options for acf queries. |
| 27 | * |
| 28 | * @access protected |
| 29 | * @var $query_options_defaults. |
| 30 | */ |
| 31 | protected $query_options_defaults = array( |
| 32 | 'show_type' => false, |
| 33 | 'show_field_type' => true, |
| 34 | 'include_option' => true, |
| 35 | 'show_group' => true, |
| 36 | 'field_type' => 'boolean', |
| 37 | ); |
| 38 | |
| 39 | /** |
| 40 | * Get Controls Options. |
| 41 | * |
| 42 | * @access public |
| 43 | * @since 4.7.0 |
| 44 | * |
| 45 | * @return array|void controls options |
| 46 | */ |
| 47 | public function get_control_options() { |
| 48 | |
| 49 | return array( |
| 50 | 'label' => __( 'Value', 'premium-addons-for-elementor' ), |
| 51 | 'type' => Controls_Manager::SELECT, |
| 52 | 'label_block' => true, |
| 53 | 'options' => array( |
| 54 | 'true' => __( 'True', 'premium-addons-for-elementor' ), |
| 55 | 'false' => __( 'False', 'premium-addons-for-elementor' ), |
| 56 | ), |
| 57 | 'default' => 'true', |
| 58 | 'condition' => array( |
| 59 | 'pa_condition_key' => 'acf_boolean', |
| 60 | ), |
| 61 | ); |
| 62 | |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Get Query Options. |
| 67 | * |
| 68 | * @access public |
| 69 | * @since 4.7.0 |
| 70 | * |
| 71 | * @return array|void controls options |
| 72 | */ |
| 73 | public function get_query_options() { |
| 74 | return $this->query_options_defaults; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Get Value Controls Options. |
| 79 | * |
| 80 | * @access public |
| 81 | * @since 4.7.0 |
| 82 | * |
| 83 | * @return array controls options. |
| 84 | */ |
| 85 | public function add_value_control() { |
| 86 | |
| 87 | return array( |
| 88 | 'label' => __( 'ACF Field', 'premium-addons-for-elementor' ), |
| 89 | 'type' => Premium_Acf_Selector::TYPE, |
| 90 | 'options' => array(), |
| 91 | 'query_type' => 'acf', |
| 92 | 'label_block' => true, |
| 93 | 'multiple' => false, |
| 94 | 'query_options' => $this->get_query_options(), |
| 95 | 'description' => __( 'ACF True/False', 'premium-addons-for-elementor' ), |
| 96 | 'condition' => array( |
| 97 | 'pa_condition_key' => 'acf_boolean', |
| 98 | ), |
| 99 | ); |
| 100 | |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Compare Condition Value. |
| 105 | * |
| 106 | * @access public |
| 107 | * @since 4.7.0 |
| 108 | * |
| 109 | * @param array $settings element settings. |
| 110 | * @param string $operator condition operator. |
| 111 | * @param string $value condition value. |
| 112 | * @param string|void $compare_val compare value. |
| 113 | * @param string|bool $tz time zone. |
| 114 | * |
| 115 | * @return bool|void |
| 116 | */ |
| 117 | public function compare_value( $settings, $operator, $compare_val, $value, $tz ) { |
| 118 | |
| 119 | $field = get_field_object( $value ); |
| 120 | |
| 121 | $acf_helper = new ACF_Helper(); |
| 122 | |
| 123 | $value = $acf_helper->get_acf_field_value( $value, $field['parent'] ); |
| 124 | |
| 125 | $input_val = 'true' === sanitize_text_field( $compare_val ) ? true : false; |
| 126 | |
| 127 | $condition_result = $value === $input_val ? true : false; |
| 128 | |
| 129 | return Helper_Functions::get_final_result( $condition_result, $operator ); |
| 130 | |
| 131 | } |
| 132 | |
| 133 | } |
| 134 |