id ) && $prodigy_product->get_id() !== $post->ID ) ) { $prodigy_product = self::prodigy_get_product( $post ); } $include = false; foreach ( $elementor_options['single'] as $elementor_option ) { if ( ! preg_grep( '/include\/prodigy-product/', $elementor_option ) ) { continue; } if ( preg_grep( '/^include\/prodigy-product$/', $elementor_option ) || preg_grep( '/^include\/prodigy-product\/in_' . Prodigy::get_prodigy_tag_type() . '$/', $elementor_option ) || preg_grep( '/^include\/prodigy-product\/in_' . Prodigy::get_prodigy_category_type() . '$/', $elementor_option ) || preg_grep( '/^include\/prodigy-product\/in_' . Prodigy::get_prodigy_brand_type() . '$/', $elementor_option ) ) { $include = true; break; } $categories = preg_grep( '/include\/prodigy-product\/in_' . Prodigy::get_prodigy_category_type() . '(.*)\/(\d)/', $elementor_option ); $categories = is_array( $categories ) ? preg_replace( '/include\/prodigy-product\/in_' . Prodigy::get_prodigy_category_type() . '(.*)\//', '', $categories ) : array(); $tags = preg_grep( '/include\/prodigy-product\/in_' . Prodigy::get_prodigy_tag_type() . '(.*)\/(\d)/', $elementor_option ); $tags = is_array( $tags ) ? preg_replace( '/include\/prodigy-product\/in_' . Prodigy::get_prodigy_tag_type() . '(.*)\//', '', $tags ) : array(); $brands = preg_grep( '/include\/prodigy-product\/in_' . Prodigy::get_prodigy_brand_type() . '(.*)\/(\d)/', $elementor_option ); $brands = is_array( $brands ) ? preg_replace( '/include\/prodigy-product\/in_' . Prodigy::get_prodigy_brand_type() . '(.*)\//', '', $brands ) : array(); $match_cat = ! empty( $categories ) && self::post_has_any_terms( $categories, Prodigy::get_prodigy_category_type(), $post ); $match_tag = ! empty( $tags ) && self::post_has_any_terms( $tags, Prodigy::get_prodigy_tag_type(), $post ); $match_brand = ! empty( $brands ) && self::post_has_any_terms( $brands, Prodigy::get_prodigy_brand_type(), $post ); if ( $match_cat || $match_tag || $match_brand ) { $include = true; break; } } return $include; } /** * Check if post has any of the given term IDs for the given taxonomy. * * @param array $term_ids Term IDs (strings or ints). * @param string $taxonomy Taxonomy name. * @param \WP_Post $post Post object. * @return bool */ private static function post_has_any_terms( array $term_ids, string $taxonomy, $post ): bool { foreach ( $term_ids as $term_id ) { $term_id = is_numeric( $term_id ) ? (int) $term_id : 0; if ( $term_id > 0 && has_term( $term_id, $taxonomy, $post ) ) { return true; } } return false; } /** * @return bool */ public static function is_exclude_single_template(): bool { if ( ! is_singular( Prodigy::get_prodigy_product_type() ) ) { return false; } global $post, $prodigy_product; $elementor_options = get_option( 'elementor_pro_theme_builder_conditions' ); if ( ! isset( $elementor_options['single'] ) || ! is_array( $elementor_options['single'] ) ) { return false; } if ( empty( $prodigy_product ) ) { $product_template = new Prodigy_Product_Template_Builder( new Prodigy_Product_Template_Item() ); $prodigy_product = $product_template->set_product( (int) ( $post->ID ?? 0 ) ); } $exclude = false; foreach ( $elementor_options['single'] as $elementor_option ) { if ( ! preg_grep( '/exclude\/prodigy-product/', $elementor_option ) ) { continue; } if ( preg_grep( '/^include\/prodigy-product$/', $elementor_option ) || preg_grep( '/^include\/prodigy-product\/in_' . Prodigy::get_prodigy_tag_type() . '$/', $elementor_option ) || preg_grep( '/^include\/prodigy-product\/in_' . Prodigy::get_prodigy_category_type() . '$/', $elementor_option ) || preg_grep( '/^include\/prodigy-product\/in_' . Prodigy::get_prodigy_brand_type() . '$/', $elementor_option ) ) { $include = true; break; } $categories = preg_grep( '/include\/prodigy-product\/in_' . Prodigy::get_prodigy_category_type() . '(.*)\/(\d)/', $elementor_option ); $categories = is_array( $categories ) ? preg_replace( '/include\/prodigy-product\/in_' . Prodigy::get_prodigy_category_type() . '(.*)\//', '', $categories ) : array(); $tags = preg_grep( '/include\/prodigy-product\/in_' . Prodigy::get_prodigy_tag_type() . '(.*)\/(\d)/', $elementor_option ); $tags = is_array( $tags ) ? preg_replace( '/include\/prodigy-product\/in_' . Prodigy::get_prodigy_tag_type() . '(.*)\//', '', $tags ) : array(); $brands = preg_grep( '/include\/prodigy-product\/in_' . Prodigy::get_prodigy_brand_type() . '(.*)\/(\d)/', $elementor_option ); $brands = is_array( $brands ) ? preg_replace( '/include\/prodigy-product\/in_' . Prodigy::get_prodigy_brand_type() . '(.*)\//', '', $brands ) : array(); $match_cat = ! empty( $categories ) && self::post_has_any_terms( $categories, Prodigy::get_prodigy_category_type(), $post ); $match_tag = ! empty( $tags ) && self::post_has_any_terms( $tags, Prodigy::get_prodigy_tag_type(), $post ); $match_brand = ! empty( $brands ) && self::post_has_any_terms( $brands, Prodigy::get_prodigy_brand_type(), $post ); if ( $match_cat || $match_tag || $match_brand ) { $exclude = true; break; } } return $exclude; } /** * @return bool */ public static function is_elementor_page(): bool { return false; $shop_page_id = Prodigy_Page::prodigy_get_page_id( 'shop' ); if ( ! is_page( $shop_page_id ) ) { return false; } if ( get_post_meta( $shop_page_id, '_elementor_edit_mode', true ) === 'builder' ) { return true; } return false; } /** * @return bool */ /** * @return bool */ public static function is_use_archive_template(): bool { return self::is_include_archive_template() || self::is_exclude_archive_template() || self::is_include_shop_template() || self::is_exclude_shop_template(); } /** * Check whether Elementor should render the current Prodigy archive location. * * @return bool */ public static function is_archive_template_active(): bool { return ( self::is_include_archive_template() && ! self::is_exclude_archive_template() ) || ( self::is_include_shop_template() && ! self::is_exclude_shop_template() ); } /** * @return bool */ private static function is_current_product_archive(): bool { return is_post_type_archive( Prodigy::get_prodigy_product_type() ) || is_tax( Prodigy::get_prodigy_category_type() ) || is_tax( Prodigy::get_prodigy_tag_type() ) || is_tax( Prodigy::get_prodigy_brand_type() ) || self::is_current_shop_page() || Prodigy_Url_Helper::is_archive_page_url(); } /** * @return bool */ private static function is_current_shop_page(): bool { $shop_page_id = Prodigy_Page::prodigy_get_page_id( 'shop' ); if ( is_page( $shop_page_id ) ) { return true; } $shop_page = $shop_page_id ? get_post( $shop_page_id ) : null; if ( empty( $shop_page->post_name ) ) { return false; } $path = trim( (string) Prodigy_Url_Helper::prodigy_parse_request_uri(), '/' ); $segments = explode( '/', $path ); return isset( $segments[0] ) && $segments[0] === $shop_page->post_name; } /** * @return bool */ public static function is_use_product_template(): bool { return ( self::is_include_single_template() || self::is_exclude_single_template() ); } /** * @param array|null $options * * @return bool */ public static function is_live_mode( ?array $options = null ): ?bool { return isset( $options ); } /** * @param \WP_Post $post * * @return false|Prodigy_Product_Template_Item */ public static function prodigy_get_product( \WP_Post $post ) { $product_id = self::prodigy_get_product_id( $post ); if ( ! $product_id ) { return false; } $product_template = new Prodigy_Product_Template_Builder( new Prodigy_Product_Template_Item() ); return $product_template->set_product( (int) $product_id ); } /** * @param \WP_Post $product * * @return false|float|int */ public static function prodigy_get_product_id( \WP_Post $product ) { global $post; if ( isset( $post, $post->ID ) && get_post_type( $post->ID ) === Prodigy::PRODIGY_POST_TYPE_DEFAULT ) { return absint( $post->ID ); } if ( ! empty( $product->ID ) ) { return $product->ID; } return false; } }