} $addSqls['color']['withCount'] = false; $addSqls['color']['fields'] = 'tt.term_id, tt.taxonomy, wpf_temp.ID'; $addSqls['color']['taxonomyList'] = "'" . implode( "', '", $taxonomyList ) . "'"; } foreach ( $addSqls as $key => $addSql ) { $sql[ $key ] = 'SELECT ' . $addSql['fields'] . ' FROM ' . $listTable . ' AS wpf_temp INNER JOIN ' . $wpdb->term_relationships . ' tr ON (tr.object_id=wpf_temp.ID) INNER JOIN ' . $wpdb->term_taxonomy . ' tt ON (tt.term_taxonomy_id=tr.term_taxonomy_id) '; if ( $addSql['withCount'] && $param['isInStockOnly'] ) { $sql[ $key ] .= $stockJoin; } if ( $byVariations ) { $sql[ $key ] .= ' INNER JOIN ' . $wpdb->terms . ' ttt ON (ttt.term_id=tt.term_id) ' . $typeJoin; } $sql[ $key ] .= ' WHERE tt.taxonomy IN ( ' . $addSql['taxonomyList'] . ' )'; if ( $byVariations ) { $sql[ $key ] .= ' AND (md_type.val_id!=' . $variableMetaId . ' OR tt.taxonomy NOT IN (\'' . implode( "','", array_keys( $attrTaxonomyList ) ) . '\')' . ' OR EXISTS(SELECT 1 FROM ' . $listVariationAttributes . ' as p_childs' . ' WHERE p_childs.id=wpf_temp.id and p_childs.taxonomy=tt.taxonomy and p_childs.value=ttt.slug LIMIT 1))'; } if ( $addSql['withCount'] ) { $sql[ $key ] .= ' GROUP BY tr.term_taxonomy_id'; } } // 4.0.0: the 3.4 `addCustomAttributesSql` arguments for every Pro from 3.4.0 on. WPF_PRO_REQUIRES became // 4.0.0, which must not hand a Pro 3.4.x site (Free auto updated first) the pre 3.4 arguments. if ( WooBeWoo_PF_Frame::_()->proVersionCompare( WooBeWoo_PF_Legacy_Compat::PRO_OLDEST, '>=' ) ) { $termProducts = ! isset( $sql['main'] ) ? array() : WooBeWoo_PF_Db::get( $sql['main'] ); if ( false === $termProducts ) { $termProducts = array(); } $termProducts = WooBeWoo_PF_Dispatcher::applyFilters( 'addCustomAttributesSql', $termProducts, array( 'taxonomies' => $param['taxonomy'], 'withCount' => $param['withCount'], 'listTable' => $listTable, 'generalSettings' => $param['generalSettings'], 'currentSettings' => $param['currentSettings'], ) ); } else { $sql['main'] = $sql['main'] ?? ''; $sql['main'] = WooBeWoo_PF_Dispatcher::applyFilters( 'addCustomAttributesSql', $sql['main'], array( 'taxonomies' => $param['taxonomy'], 'withCount' => $param['withCount'], 'productList' => '(select id from ' . $listTable . ')', 'generalSettings' => $param['generalSettings'], 'currentSettings' => $param['currentSettings'], ) ); $termProducts = ( '' === $sql['main'] ) ? array() : WooBeWoo_PF_Db::get( $sql['main'] ); } $existTerms = array(); foreach ( $termProducts as $term ) { $taxonomy = $term['taxonomy']; $isCat = 'product_cat' === $taxonomy; $name = urldecode( $taxonomy ); $names[ $name ] = $taxonomy; if ( ! isset( $existTerms[ $name ] ) ) { $existTerms[ $name ] = array(); } $termId = $term['term_id']; if ( $isCat && isset( $param['only_children_category'] ) && ! in_array( (int) $termId, $param['only_children_category'], true ) ) { continue; } if ( $isCat && ! empty( $param['onlyCategories'] ) ) { $found = true; foreach ( $param['onlyCategories'] as $catIds ) { if ( ! in_array( (int) $termId, $catIds, true ) ) { $found = false; break; } } if ( ! $found ) { continue; } } $cnt = $param['withCount'] ? intval( $term['cnt'] ) : 0; $existTerms[ $name ][ $termId ] = $cnt; $parent = ( isset( $term['parent'] ) ) ? (int) $term['parent'] : 0; if ( $isCat && $param['isCalcCategory'] && $param['calcCategory'] === $parent ) { $calcCategories[ $termId ] = $cnt; } if ( 0 !== $parent ) { if ( isset( $isHierarchicalTaxonomy ) && ! key_exists( $name, $isHierarchicalTaxonomy ) ) { $isHierarchicalTaxonomy[ $name ] = $termProducts; } $children = array( $termId ); do { if ( ! isset( $existTerms[ $name ][ $parent ] ) ) { $existTerms[ $name ][ $parent ] = 0; } if ( isset( $childs[ $parent ] ) ) { array_merge( $childs[ $parent ], $children ); } else { $childs[ $parent ] = $children; } $parentTerm = get_term( $parent, $taxonomy ); $children[] = $parent; if ( $parentTerm && isset( $parentTerm->parent ) ) { $parent = $parentTerm->parent; if ( $isCat && $param['isCalcCategory'] && $param['calcCategory'] === $parent ) { $calcCategories[ $parentTerm->term_id ] = 0; } } else { $parent = 0; } } while ( 0 !== $parent ); } } if ( 'light' !== $param['mode'] && $param['withCount'] ) { foreach ( $existTerms as $taxonomy => $terms ) { $allCalc = in_array( $taxonomy, $param['forCount'], true ); $calcWithChildren = in_array( $taxonomy, $param['forCountWithChildren'], true ); if ( ! ( $allCalc || ( $param['isCalcCategory'] && 'product_cat' === $taxonomy ) || $calcWithChildren ) ) { continue; } foreach ( $terms as $termId => $cnt ) { if ( $calcWithChildren ) { $termIds = $this->getTermChildrenArray( $termId, $names[ $taxonomy ] ); } elseif ( isset( $childs[ $termId ] ) && ( $allCalc || isset( $calcCategories[ $termId ] ) ) ) { $termIds = $childs[ $termId ]; } else { continue; } $termIds[] = $termId; $sqlTemp = "SELECT count(DISTINCT tr.`object_id`) FROM {$listTable} AS wpf_temp INNER JOIN {$wpdb->term_relationships} AS tr ON (tr.`object_id`=wpf_temp.`ID`) INNER JOIN {$wpdb->term_taxonomy} AS wtf ON tr.`term_taxonomy_id` = wtf.`term_taxonomy_id` WHERE wtf.`term_id` IN (" . implode( ',', $termIds ) . ')'; $cnt = intval( WooBeWoo_PF_Db::get( $sqlTemp, 'one' ) ); $existTerms[ $taxonomy ][ $termId ] = $cnt; if ( isset( $calcCategories[ $termId ] ) ) { $calcCategories[ $termId ] = $cnt; } } } } if ( ! empty( $colorGroup ) && isset( $sql['color'] ) ) { $termProducts = WooBeWoo_PF_Db::get( $sql['color'] ); $existTerms = WooBeWoo_PF_Dispatcher::applyFilters( 'getExistTermsColor', $existTerms, $colorGroup, $termProducts ); } if ( isset( $isHierarchicalTaxonomy ) && ! empty( $isHierarchicalTaxonomy ) ) { $existTerms = $this->filterToOnlyChildrenOfSelectedParent( $existTerms, $isHierarchicalTaxonomy ); } return array( $existTerms, $calcCategories ); } /** * filterToOnlyChildrenOfSelectedParent. * * @version 3.4.0 */ public function filterToOnlyChildrenOfSelectedParent( $existTerms, $isHierarchicalTaxonomy ) { $urlQuery = WooBeWoo_PF_Req::get( 'get' ); if ( empty( $urlQuery ) ) { $params = WooBeWoo_PF_Req::get( 'post' ); if ( ! empty( $params ) && isset( $params['currenturl'] ) ) { $curUrl = $params['currenturl']; $parts = wp_parse_url( $curUrl ); if ( ! empty( $parts['query'] ) ) { parse_str( $parts['query'], $urlQuery ); } } } foreach ( $isHierarchicalTaxonomy as $name => $terms ) { $matchingKeys = ( ! empty( $urlQuery ) ) ? preg_grep( '/^wpf_filter_' . preg_quote( $name, '/' ) . '_\d+$/', array_keys( $urlQuery ) ) : array(); $termChildren = array(); $rootTermIds = array(); foreach ( $terms as $term ) { $termId = (int) $term['term_id']; $parentId = (int) $term['parent']; if ( ! isset( $termChildren[ $parentId ] ) ) { $termChildren[ $parentId ] = array(); } $termChildren[ $parentId ][] = $termId; if ( 0 === $parentId ) { $rootTermIds[] = $termId; } } if ( ! empty( $matchingKeys ) ) { $maxIndex = 0; $maxKey = reset( $matchingKeys ); foreach ( $matchingKeys as $key ) { preg_match( '/^wpf_filter_' . preg_quote( $name, '/' ) . '_(\d+)$/', $key, $matches ); if ( isset( $matches[1] ) && (int) $matches[1] > $maxIndex ) { $maxIndex = (int) $matches[1]; $maxKey = $key; } } if ( ! empty( $maxKey ) ) { $allowed = array(); $term = get_term_by( 'slug', $urlQuery[ $maxKey ], $name ); if ( $term ) { $term_id = (int) $term->term_id; $parent_id = (int) $term->parent; $allowed[] = $term_id; $descendants = $this->getDescendantIds( $terms, $term_id ); $ancestors = get_ancestors( $term_id, $name, 'taxonomy' ); $siblings = array(); foreach ( $terms as $t ) { if ( (int) $t['parent'] === $parent_id ) { $siblings[] = (int) $t['term_id']; } } $allowed = array_merge( $allowed, $descendants, $ancestors, $siblings ); $allowed = array_unique( $allowed ); $hierarchicalByLevel = array(); foreach ( $terms as $t ) { $term_id = (int) $t['term_id']; if ( in_array( $term_id, $allowed, true ) ) { $level = 0; $parentId = (int) $t['parent']; while ( 0 !== $parentId ) { ++$level; $found = false; foreach ( $terms as $pt ) { if ( (int) $pt['term_id'] === $parentId ) { $parentId = (int) $pt['parent']; $found = true; break; } } if ( ! $found ) { break; } } if ( ! isset( $hierarchicalByLevel[ $level ] ) ) { $hierarchicalByLevel[ $level ] = array(); } $hierarchicalByLevel[ $level ][ $term_id ] = $existTerms[ $name ][ $term_id ]; } } ksort( $hierarchicalByLevel ); if ( ! empty( $hierarchicalByLevel ) ) { $existTerms[ $name . '_hierarchical' ] = $hierarchicalByLevel; } if ( ! empty( $existTerms[ $name ] ) ) { $existTerms[ $name ] = array_intersect_key( $existTerms[ $name ], array_flip( $allowed ) ); } } } } elseif ( ! empty( $existTerms[ $name ] ) ) { $existTerms[ $name ] = array_intersect_key( $existTerms[ $name ], array_flip( $rootTermIds ) ); $maxLevel = 0; $cache = array(); foreach ( $terms as $term ) { $level = 0; $parentId = (int) $term['parent']; if ( isset( $cache[ $parentId ] ) ) { continue; } $firstParent = $parentId; while ( 0 !== $parentId ) { if ( isset( $cache[ $parentId ] ) ) { $level += $cache[ $parentId ]; break; } ++$level; $found = false; foreach ( $terms as $pt ) { if ( (int) $pt['term_id'] === $parentId ) { $parentId = (int) $pt['parent']; $found = true; break; } } if ( ! $found ) { break; } } $cache[ $firstParent ] = $level; $maxLevel = max( $maxLevel, $level ); } $hierarchicalByLevel = array(); for ( $i = 0; $i <= $maxLevel; $i++ ) { $hierarchicalByLevel[ $i ] = array(); if ( 0 === $i ) { foreach ( $rootTermIds as $termId ) { if ( isset( $existTerms[ $name ][ $termId ] ) ) { $hierarchicalByLevel[0][ $termId ] = $existTerms[ $name ][ $termId ]; } } } } $existTerms[ $name . '_hierarchical' ] = $hierarchicalByLevel; } } return $existTerms; } /** * getDescendantIds. */ public function getDescendantIds( array $terms, $parentId ) { $descendants = array(); foreach ( $terms as $term ) { if ( (int) $term['parent'] === (int) $parentId ) { $term_id = (int) $term['term_id']; $descendants[] = $term_id; $descendants = array_merge( $descendants, $this->getDescendantIds( $terms, $term_id ) ); } } return $descendants; } /** * Returns additional data on minimum and maximum prices and users. * * @version 3.4.7 * * @param $args * @param $param * * @return mixed */ public function getExistsMore( $args, $param, $result ) { global $wpdb; if ( ! isset( $result['existsPrices'] ) ) { $result['existsPrices'] = new stdClass(); $result['existsPrices']->wpfMinPrice = 1000000000; $result['existsPrices']->wpfMaxPrice = 0; $result['existsPrices']->decimal = 0; $result['existsPrices']->dataStep = '1'; $result['existsUsers'] = array(); } $listTable = $param['listTable']; if ( empty( $listTable ) ) { return $result; } $mode = $param['calcMode']; $need = ( 'full' === $mode && ! key_exists( 'light', $param['calcVars'] ) ) || 'light' === $mode; if ( $param['havePosts'] && ! empty( $param['taxonomies']['other_names'] ) ) { foreach ( $param['generalSettings'] as $setting ) { if ( ! isset( $setting['id'] ) ) { continue; } if ( in_array( $setting['id'], $param['taxonomies']['other_names'], true ) ) { if ( 'wpfPrice' == $setting['id'] ) { $keep = $param['taxonomies']['keep_recount_price']; if ( ( ! $keep && ! $need ) || ( $keep && 'full' != $mode ) ) { continue; } } elseif ( ! $need ) { continue; } switch ( $setting['id'] ) { case 'wpfPrice': case 'wpfPriceRange': $listTableForPrice = $listTable; if ( isset( $args['meta_query'] ) && is_array( $args['meta_query'] ) ) { $issetArgsPrice = false; foreach ( $args['meta_query'] as $key => $row ) { if ( isset( $row['price_filter'] ) ) { $issetArgsPrice = true; unset( $args['meta_query'][ $key ] ); } } if ( $issetArgsPrice ) { $filterLoop = new WP_Query( $args ); if ( $filterLoop->have_posts() ) { $priceTable = $this->createTemporaryTable( $this->tempFilterTable . '_price', $filterLoop->request ); if ( ! empty( $priceTable ) ) { $listTableForPrice = $priceTable; } } } } list( $result['existsPrices']->decimal, $result['existsPrices']->dataStep ) = WooBeWoo_PF_Dispatcher::applyFilters( 'getDecimal', array( 0, 1, ), $setting['settings'] ); if ( 'wpfPriceRange' === $setting['id'] ) { $price = $this->getView()->wpfGetFilteredPriceFromProductList( $setting['settings'], $listTableForPrice, false, $result['existsPrices']->decimal ); } else { $price = $this->getView()->wpfGetFilteredPriceFromProductList( $setting['settings'], $listTableForPrice, true, $result['existsPrices']->decimal ); } if ( is_object( $price ) ) { $result['existsPrices']->wpfMinPrice = $price->wpfMinPrice; $result['existsPrices']->wpfMaxPrice = $price->wpfMaxPrice; if ( isset( $price->tax ) ) { $result['existsPrices']->tax = $price->tax; } } break; case 'wpfAuthor': case 'wpfVendors': if ( empty( $result['existsUsers'] ) ) { $query = 'SELECT DISTINCT ' . $wpdb->users . '.ID' . ' FROM ' . $listTable . ' AS wpf_temp' . ' INNER JOIN ' . $wpdb->posts . ' p ON (p.ID=wpf_temp.ID)' . ' JOIN ' . $wpdb->users . ' ON p.post_author = ' . $wpdb->users . '.ID'; $result['existsUsers'] = WooBeWoo_PF_Db::get( $query ); } break; case 'wpfAttribute': if ( false === $param['ajax'] ) { $frontendType = $this->getFilterSetting( $setting['settings'], 'f_frontend_type', '' ); if ( 'slider' === $frontendType ) { $showAllSliderAttributes = $this->getFilterSetting( $setting['settings'], 'f_show_all_slider_attributes', false ); if ( $showAllSliderAttributes ) { $this->clauses = array(); $name = $setting['name']; $data = WooBeWoo_PF_Req::get( 'get' ); unset( $data[ $name ] ); $args['meta_query'] = WooBeWoo_PF_Dispatcher::applyFilters( 'addCustomMetaQueryPro', $args['meta_query'], $data, 'url' ); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query $filterLoop = new WP_Query( $args ); if ( $filterLoop->have_posts() ) { $listTable = $this->createTemporaryTable( $this->tempFilterTable . '_attribute', $filterLoop->request ); if ( ! empty( $listTable ) ) { list( $existsTerms, $calcCategories ) = $this->getTerms( $listTable, $param, $result['exists'] ); $customPrefixes = WooBeWoo_PF_Dispatcher::applyFilters( 'getCustomPrefixes', array(), false ); foreach ( $customPrefixes as $prefix ) { if ( strpos( $name, $prefix ) === 0 ) { $name = str_replace( $prefix, '', $name ); } } if ( isset( $existsTerms[ $name ] ) ) { $result['exists'][ $name ] = $existsTerms[ $name ]; } } } } } } break; } } } } return $result; } /** * addAjaxFilterForYithWoocompare. * * @version 3.3.0 */ public function addAjaxFilterForYithWoocompare( $actions ) { return array_merge( $actions, array( 'woobewoo_pf_filters_frontend' ) ); } /** * getAllPages. * * @version 3.4.0 */ public function getAllPages() { global $wpdb; $allPages = WooBeWoo_PF_Db::get( "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'page' AND post_status IN ('publish','draft') ORDER BY post_title" ); $pages = array(); if ( ! empty( $allPages ) ) { foreach ( $allPages as $p ) { $pages[ $p['ID'] ] = $p['post_title']; } } return $pages; } /** * isWcVendorsPluginActivated. */ public function isWcVendorsPluginActivated() { return class_exists( 'WC_Vendors' ); } /** * Get logic for filtering. * * @version 3.4.0 * * @return array */ public function getAttrFilterLogic( $mode = '' ) { $logic = array( 'display' => array( 'and' => 'And', 'or' => 'Or', ), 'loop' => array( 'and' => 'AND', 'or' => 'IN', ), 'delimetr' => array( 'and' => ',', 'or' => '|', ), ); $logic = WooBeWoo_PF_Dispatcher::applyFilters( 'getAttrFilterLogic', $logic ); return empty( $mode ) ? $logic : ( isset( $logic[ $mode ] ) ? $logic[ $mode ] : array() ); } /** * getFilterTagsList. */ public function getFilterTagsList() { return array( 0 => 'Default', 1 => 'h1', 2 => 'h2', 3 => 'h3', 4 => 'h4', 5 => 'h5', ); } /** * getCategoriesDisplay. */ public function getCategoriesDisplay( $tax = 'product_cat' ) { $catArgs = array( 'taxonomy' => $tax, 'orderby' => 'name', 'order' => 'asc', 'hide_empty' => false, ); $productCategories = get_terms( $catArgs ); $categoryDisplay = array(); $parentCategories = array(); if ( is_array( $productCategories ) ) { foreach ( $productCategories as $c ) { if ( 0 == $c->parent ) { array_push( $parentCategories, $c->term_id ); } $categoryDisplay[ $c->term_id ] = '[' . $c->term_id . '] ' . $c->name; } } return array( $categoryDisplay, $parentCategories ); } /** * getTagsDisplay. */ public function getTagsDisplay() { $tagArgs = array( 'taxonomy' => 'product_tag', 'orderby' => 'name', 'order' => 'asc', 'hide_empty' => false, 'parent' => 0, ); $productTags = get_terms( $tagArgs ); $tagsDisplay = array(); if ( is_array( $productTags ) ) { foreach ( $productTags as $t ) { $tagsDisplay[ $t->term_id ] = $t->name; } } return array( $tagsDisplay ); } /** * getAttributesDisplay. * * @version 3.4.0 */ public function getAttributesDisplay( $withCustom = true ) { $productAttr = function_exists( 'wc_get_attribute_taxonomies' ) ? wc_get_attribute_taxonomies() : array(); if ( $withCustom ) { $productAttr = WooBeWoo_PF_Dispatcher::applyFilters( 'addCustomAttributes', $productAttr ); } $attrDisplay = array( 0 => esc_html__( 'Select...', 'woo-product-filter' ) ); $attrTypes = array(); $attrNames = array(); foreach ( $productAttr as $attr ) { $attrId = (int) $attr->attribute_id; $slug = empty( $attrId ) ? $attr->attribute_slug : $attrId; $attrDisplay[ $slug ] = $attr->attribute_label; $attrTypes[ $slug ] = isset( $attr->custom_type ) ? $attr->custom_type : ''; $attrNames[ $slug ] = isset( $attr->filter_name ) ? $attr->filter_name : 'wpf_filter_' . $attr->attribute_name; } return array( $attrDisplay, $attrTypes, $attrNames ); } /** * getRolesDisplay. */ public function getRolesDisplay() { if ( ! function_exists( 'get_editable_roles' ) ) { require_once ABSPATH . '/wp-admin/includes/user.php'; } $rolesMain = get_editable_roles(); $roles = array(); foreach ( $rolesMain as $key => $r ) { $roles[ $key ] = $r['name']; } return array( $roles ); } /** * Exclude parent terms from term list. * * @param array $termList * @param string $taxonomy * * @return array */ public function exludeParentTems( $termList, $taxonomy ) { foreach ( $termList as $key => $termId ) { $parents = get_ancestors( $termId, $taxonomy, 'taxonomy' ); if ( is_array( $parents ) ) { // remove all parent termsId from main parent list foreach ( $parents as $parentId ) { if ( array_search( $parentId, $termList ) !== false ) { $keyParent = array_search( $parentId, $termList ); unset( $termList[ $keyParent ] ); } } } } return $termList; } /** * Exclude child terms from term list. * * @param array $termList * @param string $taxonomy * * @return array */ public function exludeChildTems( $termList, $taxonomy ) { foreach ( $termList as $key => $termId ) { $children = get_term_children( $termId, $taxonomy ); if ( is_array( $children ) ) { // remove all child termsId from main list foreach ( $children as $childId ) { if ( array_search( $childId, $termList ) !== false ) { $keyParent = array_search( $childId, $termList ); unset( $termList[ $keyParent ] ); } } } } return $termList; } /** * Add shortcode attributes to additional html data attributes. * * @version 3.4.0 * * @param array $attributes */ public function addWoocommerceShortcodeQuerySettings( $attributes ) { $shortcodeAttr = htmlentities( WooBeWoo_PF_Utils::jsonEncode( $attributes ), ENT_COMPAT ); echo ''; } /** * getProductsShortcode. */ public static function getProductsShortcode( $content ) { $shortcode_tags = array( 'products' => 'WC_Shortcodes::products', 'sale_products' => 'WC_Shortcodes::sale_products', ); $original = $content; if ( empty( $content ) ) { $id = get_the_ID(); if ( $id ) { $p = get_post( $id ); if ( $p ) { $content = $p->post_content; } } } if ( false === strpos( $content, '[' ) ) { return $original; } if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) { return $original; } preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches ); $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); if ( empty( $tagnames ) ) { // some themes hide woocommerce shortcodes inside their shortcodes, // so there is nothing left to do but let them run for execution $theme = wp_get_theme(); if ( $theme instanceof WP_Theme ) { $themeName = ( '' !== $theme['Parent Theme'] ) ? $theme['Parent Theme'] : $theme['Name']; if ( 'Divi' === $themeName ) { add_filter( 'pre_do_shortcode_tag', function ( $return, $tag, $attr ) { if ( 'et_pb_shop' === $tag ) { if ( isset( $attr['module_class'] ) && '' !== $attr['module_class'] ) { self::$otherShortcodeAttr['class'] = $attr['module_class']; } else { unset( self::$otherShortcodeAttr['class'] ); } } return $return; }, 10, 3 ); preg_match_all( '@(\[et_pb_shop.*?\/et_pb_shop\])@', $content, $diviShortCodes ); if ( isset( $diviShortCodes[1] ) ) { foreach ( $diviShortCodes[1] as $diviShortCode ) { do_shortcode( $diviShortCode ); } } } elseif ( 'Shoptimizer' === $themeName ) { preg_match_all( '@(\[elementor-template.*?\])@', $content, $elementorTemplates ); if ( isset( $elementorTemplates[1] ) ) { foreach ( $elementorTemplates[1] as $elementorTemplate ) { do_shortcode( $elementorTemplate ); } } } } return $original; } $pattern = get_shortcode_regex( $tagnames ); preg_match_all( "/$pattern/", $content, $matches ); if ( count( $matches ) > 3 ) { foreach ( (array) $matches[3] as $key => $m ) { if ( 'sale_products' === $matches[2][ $key ] ) { $m .= ' on_sale="true"'; } new WC_Shortcode_Products( shortcode_parse_atts( $m ), 'products' ); } } return $original; } /** * queryResults. * * @version 3.4.0 */ public function queryResults( $result ) { if ( 0 === $result->total && $this->isFiltered( false ) ) { $options = WooBeWoo_PF_Frame::_()->getModule( 'options' )->getModel( 'options' )->getAll(); if ( isset( $options['not_found_products_message'] ) && '1' === $options['not_found_products_message']['value'] ) { echo '
' . esc_html__( 'No products were found matching your selection.', 'woo-product-filter' ) . '
'; } } return $result; } /** * getElementorClass. */ public function getElementorClass( $data ) { $rawData = $data->get_raw_data(); if ( isset( $rawData['settings']['_css_classes'] ) && '' !== $rawData['settings']['_css_classes'] ) { self::$currentElementorClass = $rawData['settings']['_css_classes']; } } /** * shortcodeAttsProducts. */ public function shortcodeAttsProducts( $out, $pairs, $atts ) { if ( isset( $atts['on_sale'] ) && ! isset( $out['on_sale'] ) ) { $out['on_sale'] = $atts['on_sale']; } $out['cache'] = false; return $out; } /** * addWpfMetaClauses. * * @version 3.4.0 */ public function addWpfMetaClauses( $params ) { if ( empty( $params['values'] || $params['keyId'] ) ) { return; } global $wpdb; $isLight = empty( $params['isLight'] ) ? false : $params['isLight']; $isAnd = isset( $params['isAnd'] ) && true === $params['isAnd']; $isBetween = isset( $params['isAnd'] ) && 'BETWEEN' === $params['isAnd']; $keyId = $params['keyId']; $field = empty( $params['field'] ) ? 'id' : $params['field']; $values = WooBeWoo_PF_Utils::controlNumericValues( $params['values'], $field ); $i = 0; $clauses = array( 'join' => array(), 'where' => array(), ); if ( empty( $params['searchLogic'] ) ) { foreach ( $values as $val ) { ++$i; $clauses['join'][ $i ] = ' INNER JOIN ' . WooBeWoo_PF_Db::getTableName( 'meta_data' ) . ' AS wpf_meta__#i ON (wpf_meta__#i.product_id=' . $wpdb->posts . '.ID AND wpf_meta__#i.key_id' . ( is_array( $keyId ) ? ' IN (' . implode( ',', $keyId ) . ')' : '=' . $keyId ) . ')'; $clauses['where'][ $i ] = ' AND wpf_meta__#i.val_' . $field . ( $isAnd ? '=' . $val : ( $isBetween ? ' BETWEEN ' . ( empty( $values[0] ) ? 0 : $values[0] ) . ' AND ' . ( empty( $values[1] ) ? 0 : $values[1] ) : ' IN (' . implode( ',', $values ) . ')' ) ); if ( ! $isAnd ) { break; } } } else { ++$i; $keyDec = ! empty( $params['keyName'] ) && $this->getMetaKeyId( $params['keyName'], 'meta_type' ) == 1; $clauses['join'][ $i ] = ' INNER JOIN ' . WooBeWoo_PF_Db::getTableName( 'meta_data' ) . ' AS wpf_meta__#i ON (wpf_meta__#i.product_id=' . $wpdb->posts . '.ID AND wpf_meta__#i.key_id' . ( is_array( $keyId ) ? ' IN (' . implode( ',', $keyId ) . ')' : '=' . $keyId ) . ')'; if ( $keyDec ) { $clauses['where'][ $i ] = ' AND wpf_meta__#i.val_dec' . $params['searchLogic'] . $params['values'][0]; } else { $clauses['join'][ $i ] .= ' INNER JOIN ' . WooBeWoo_PF_Db::getTableName( 'meta_values' ) . ' AS wpf_meta_values__#i ON (wpf_meta_values__#i.id=wpf_meta__#i.val_id)'; $clauses['where'][ $i ] = ' AND wpf_meta_values__#i.value+0' . $params['searchLogic'] . $params['values'][0]; } } $this->addFilterClauses( $clauses, $isLight, $params['urlParam'] ); return; } /** * getOtherShortcodeAttr. */ public function getOtherShortcodeAttr( $return, $tag, $attr ) { if ( 'et_pb_shop' === $tag ) { if ( isset( $attr['module_class'] ) && '' !== $attr['module_class'] ) { self::$otherShortcodeAttr['class'] = $attr['module_class']; } else { unset( self::$otherShortcodeAttr['class'] ); } } return $return; } /** * getFilterLoopFromMode. */ public function getFilterLoopFromMode( $mode, $args ) { $clauses = $this->clauses; if ( 'full' === $mode ) { foreach ( $this->clausesByParam as $mode => $clausesMode ) { if ( 'variation' !== $mode ) { foreach ( $clausesMode as $key => $clausesRemove ) { if ( isset( $this->clauses[ $key ] ) ) { $this->clauses[ $key ] = array_diff( $this->clauses[ $key ], $clausesRemove ); } } } } } elseif ( isset( $this->clausesByParam[ $mode ] ) ) { foreach ( $this->clausesByParam[ $mode ] as $key => $clausesRemove ) { if ( isset( $this->clauses[ $key ] ) ) { $this->clauses[ $key ] = array_diff( $this->clauses[ $key ], $clausesRemove ); } } } $filterLoop = new WP_Query( $args ); $this->clauses = $clauses; return $filterLoop; } /** * getTaxonomyByUrl. */ public function getTaxonomyByUrl( $param ) { $taxonomy = null; $param = preg_replace( '/(_\d+)$/', '', $param ); if ( 0 === strpos( $param, 'wpf_filter_cat_' ) ) { $taxonomy = 'product_cat'; } elseif ( 0 === strpos( $param, 'product_tag_' ) ) { $taxonomy = 'product_tag'; } elseif ( 0 === strpos( $param, 'wpf_filter_pwb.' ) ) { $taxonomy = 'pwb-brand'; } elseif ( 0 === strpos( $param, 'fmeta-' ) ) { $taxonomy = $param; } elseif ( 0 === strpos( $param, 'wpf_filter_' ) ) { $taxonomy = preg_replace( '/^wpf_filter_/', 'pa_', $param ); } return $taxonomy; } /** * getDefaultSettings. * * @version 3.4.0 */ public function getDefaultSettings() { $defaults = array( 'force_theme_templates' => '', ); return WooBeWoo_PF_Dispatcher::applyFilters( 'getDefaultSettings', $defaults ); } /** * getTermChildrenArray. * * @version 2.9.4 * @since 2.8.7 */ function getTermChildrenArray( $term_id, $taxonomy ) { $children = get_term_children( $term_id, $taxonomy ); return ( ! is_wp_error( $children ) ? $children : array() ); } /** * maybeGetQueriedObjectID. * * @version 2.9.4 * @since 2.9.2 */ function maybeGetQueriedObjectID() { global $wp_query; return ( $wp_query ? $wp_query->get_queried_object_id() : 0 ); } /** * isWpfSlugFormatRewriteActive. * * @version 3.1.7 * @since 3.1.7 */ protected function isWpfSlugFormatRewriteActive() { return (bool) (int) get_option( 'wpf_slug_format_rewrite_active', 0 ); } /** * registerWpfSlugFormatRewrites. * * @version 3.1.7 * @since 3.1.7 */ public function registerWpfSlugFormatRewrites() { if ( ! $this->isWpfSlugFormatRewriteActive() ) { return; } $shop_page_id = (int) get_option( 'woocommerce_shop_page_id' ); if ( $shop_page_id <= 0 ) { return; } $slug = get_post_field( 'post_name', $shop_page_id ); if ( ! is_string( $slug ) || '' === $slug ) { return; } $escaped = preg_quote( $slug, '/' ); add_rewrite_rule( '^' . $escaped . '/wbw/(.+?)/?$', 'index.php?pagename=' . $slug . '&wbw_custom_filters=$matches[1]', 'top' ); } /** * addWpfSlugFormatQueryVars. * * @version 3.1.7 * @since 3.1.7 */ public function addWpfSlugFormatQueryVars( $vars ) { if ( ! $this->isWpfSlugFormatRewriteActive() ) { return $vars; } $vars[] = 'wbw_custom_filters'; return $vars; } /** * maybeParseWpfSlugFormatRequest. * * @version 3.1.7 * @since 3.1.7 */ public function maybeParseWpfSlugFormatRequest( $wp ) { if ( is_admin() || ! $this->isWpfSlugFormatRewriteActive() ) { return; } if ( ! $wp instanceof WP || empty( $wp->query_vars['wbw_custom_filters'] ) ) { return; } $this->getController()->handleSlugFiltersTemplateRedirect( $wp ); } /** * wpfMaybeBootstrapSlugFormatRewriteOption. * * @version 3.1.7 * @since 3.1.7 */ public function wpfMaybeBootstrapSlugFormatRewriteOption() { $flush_needed = false; if ( '1' == get_option( 'wpf_slug_format_rewrite_flush_needed' ) ) { $flush_needed = true; delete_option( 'wpf_slug_format_rewrite_flush_needed' ); } if ( '1' !== get_option( 'wpf_slug_format_rewrite_option_bootstrapped', '' ) ) { $this->getModel( 'woofilters' )->syncSlugFormatRewriteSiteOption(); update_option( 'wpf_slug_format_rewrite_option_bootstrapped', '1', true ); $flush_needed = true; } // Recover if another plugin flushed rules while our plugin was inactive. if ( $flush_needed || ( $this->isWpfSlugFormatRewriteActive() && ! $this->hasWpfSlugRewriteRule() ) ) { flush_rewrite_rules( false ); } } /** * hasWpfSlugRewriteRule. * * @version 3.1.7 * @since 3.1.7 */ protected function hasWpfSlugRewriteRule() { $shop_page_id = (int) get_option( 'woocommerce_shop_page_id' ); if ( $shop_page_id <= 0 ) { return false; } $slug = get_post_field( 'post_name', $shop_page_id ); if ( ! is_string( $slug ) || '' === $slug ) { return false; } $rules = get_option( 'rewrite_rules', array() ); if ( ! is_array( $rules ) ) { return false; } $pattern = '^' . preg_quote( $slug, '/' ) . '/wbw/(.+?)/?$'; return isset( $rules[ $pattern ] ); } }