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