acf-boolean.php
9 months ago
acf-choice.php
9 months ago
acf-text.php
9 months ago
browser.php
9 months ago
condition.php
9 months ago
date-range.php
9 months ago
date.php
9 months ago
day.php
9 months ago
device.php
9 months ago
ip-location.php
9 months ago
lang.php
9 months ago
login-status.php
9 months ago
operating-system.php
9 months ago
page.php
9 months ago
post-category.php
9 months ago
post-format.php
9 months ago
post-type.php
9 months ago
post.php
9 months ago
return-visitor.php
9 months ago
shortcode.php
9 months ago
static-page.php
9 months ago
time-range.php
9 months ago
url-referer.php
9 months ago
url-string.php
9 months ago
user-role.php
9 months ago
woo-cart-products.php
9 months ago
woo-cat-page.php
9 months ago
woo-category.php
9 months ago
woo-last-purchase.php
9 months ago
woo-orders.php
9 months ago
woo-product-cat.php
9 months ago
woo-product-price.php
9 months ago
woo-product-stock.php
9 months ago
woo-purchase-products.php
9 months ago
woo-total-price.php
9 months ago
post-category.php
91 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Post Category 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 | /** |
| 20 | * Class Post_Category |
| 21 | */ |
| 22 | class Post_Category extends Condition { |
| 23 | |
| 24 | /** |
| 25 | * Get Controls Options. |
| 26 | * |
| 27 | * @access public |
| 28 | * @since 4.7.0 |
| 29 | * |
| 30 | * @return array|void controls options |
| 31 | */ |
| 32 | public function get_control_options() { |
| 33 | |
| 34 | $args = array( |
| 35 | 'taxonomy' => 'category', |
| 36 | 'fields' => 'id=>name', |
| 37 | ); |
| 38 | |
| 39 | $categories = get_categories( $args ); |
| 40 | |
| 41 | return array( |
| 42 | 'label' => __( 'Value', 'premium-addons-for-elementor' ), |
| 43 | 'type' => Controls_Manager::SELECT2, |
| 44 | 'default' => array(), |
| 45 | 'label_block' => true, |
| 46 | 'options' => $categories, |
| 47 | 'multiple' => true, |
| 48 | 'condition' => array( |
| 49 | 'pa_condition_key' => 'post_category', |
| 50 | ), |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Compare Condition Value. |
| 56 | * |
| 57 | * @access public |
| 58 | * @since 4.7.0 |
| 59 | * |
| 60 | * @param array $settings element settings. |
| 61 | * @param string $operator condition operator. |
| 62 | * @param string $value condition value. |
| 63 | * @param string $compare_val compare value. |
| 64 | * @param string|bool $tz time zone. |
| 65 | * |
| 66 | * @return bool|void |
| 67 | */ |
| 68 | public function compare_value( $settings, $operator, $value, $compare_val, $tz ) { |
| 69 | |
| 70 | $post_id = get_the_ID(); |
| 71 | |
| 72 | if ( ! $post_id ) { |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | $categories = get_the_category( $post_id ); |
| 77 | |
| 78 | $cat_ids = array(); |
| 79 | |
| 80 | foreach ( $categories as $index => $category ) { |
| 81 | |
| 82 | array_push( $cat_ids, $category->cat_ID ); |
| 83 | |
| 84 | } |
| 85 | |
| 86 | $condition_result = ! empty( array_intersect( (array) $value, $cat_ids ) ) ? true : false; |
| 87 | |
| 88 | return Helper_Functions::get_final_result( $condition_result, $operator ); |
| 89 | } |
| 90 | } |
| 91 |