acf-boolean.php
7 months ago
acf-choice.php
7 months ago
acf-text.php
7 months ago
browser.php
7 months ago
condition.php
7 months ago
date-range.php
7 months ago
date.php
7 months ago
day.php
7 months ago
device.php
7 months ago
ip-location.php
7 months ago
lang.php
7 months ago
login-status.php
7 months ago
operating-system.php
7 months ago
page.php
7 months ago
post-category.php
7 months ago
post-format.php
7 months ago
post-type.php
7 months ago
post.php
7 months ago
return-visitor.php
7 months ago
shortcode.php
7 months ago
static-page.php
7 months ago
time-range.php
7 months ago
url-referer.php
7 months ago
url-string.php
7 months ago
user-role.php
7 months ago
woo-cart-products.php
7 months ago
woo-cat-page.php
7 months ago
woo-category.php
7 months ago
woo-last-purchase.php
7 months ago
woo-orders.php
7 months ago
woo-product-cat.php
7 months ago
woo-product-price.php
7 months ago
woo-product-stock.php
7 months ago
woo-purchase-products.php
7 months ago
woo-total-price.php
7 months ago
acf-text.php
125 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Acf Text 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_Text. |
| 22 | */ |
| 23 | class Acf_Text 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' => 'textual', |
| 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::TEXT, |
| 52 | 'label_block' => true, |
| 53 | 'condition' => array( |
| 54 | 'pa_condition_key' => 'acf_text', |
| 55 | ), |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Get Query Options. |
| 61 | * |
| 62 | * @access public |
| 63 | * @since 4.7.0 |
| 64 | * |
| 65 | * @return array|void controls options |
| 66 | */ |
| 67 | public function get_query_options() { |
| 68 | return $this->query_options_defaults; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Get Value Controls Options. |
| 73 | * |
| 74 | * @access public |
| 75 | * @since 4.7.0 |
| 76 | * |
| 77 | * @return array controls options. |
| 78 | */ |
| 79 | public function add_value_control() { |
| 80 | |
| 81 | return array( |
| 82 | 'label' => __( 'ACF Field', 'premium-addons-for-elementor' ), |
| 83 | 'type' => Premium_Acf_Selector::TYPE, |
| 84 | 'options' => array(), |
| 85 | 'query_type' => 'acf', |
| 86 | 'label_block' => true, |
| 87 | 'multiple' => false, |
| 88 | 'query_options' => $this->get_query_options(), |
| 89 | 'description' => __( 'ACF Textual ( text, textarea, wysiwyg, number, range, email, url, and password ).', 'premium-addons-for-elementor' ), |
| 90 | 'condition' => array( |
| 91 | 'pa_condition_key' => 'acf_text', |
| 92 | ), |
| 93 | ); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Compare Condition Value. |
| 98 | * |
| 99 | * @access public |
| 100 | * @since 4.7.0 |
| 101 | * |
| 102 | * @param array $settings element settings. |
| 103 | * @param string $operator condition operator. |
| 104 | * @param string $value condition value. |
| 105 | * @param string|void $compare_val compare value. |
| 106 | * @param string|bool $tz time zone. |
| 107 | * |
| 108 | * @return bool|void |
| 109 | */ |
| 110 | public function compare_value( $settings, $operator, $compare_val, $value, $tz ) { |
| 111 | |
| 112 | $field = get_field_object( $value ); |
| 113 | |
| 114 | $acf_helper = new ACF_Helper(); |
| 115 | |
| 116 | $value = $acf_helper->get_acf_field_value( $value, $field['parent'] ); |
| 117 | |
| 118 | $input_val = sanitize_text_field( $compare_val ); |
| 119 | |
| 120 | $condition_result = ( $value === $input_val ) ? true : false; |
| 121 | |
| 122 | return Helper_Functions::get_final_result( $condition_result, $operator ); |
| 123 | } |
| 124 | } |
| 125 |