PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.0.2
ShopBuilder – WooCommerce Builder For Elementor v2.0.2
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
← All changes | app/Models/QueryArgs.php +87 -48 2.2.12.0.2 View file →
@@ -7,10 +7,8 @@
7 7
8 8 namespace RadiusTheme\SB\Models;
9 9
10 10 // Do not allow directly accessing this file.
11 -use RadiusTheme\SB\Helpers\Fns;
12 -
13 11 if ( ! defined( 'ABSPATH' ) ) {
14 12 exit( 'This script cannot be accessed directly.' );
15 13 }
16 14
@@ -45,19 +43,23 @@
45 43 public function buildArgs( array $meta, string $type = 'product', bool $isCarousel = false ) {
46 44 $this->meta = $meta;
47 45
48 46 if ( 'product' === $type ) {
47 + // Post Type.
48 + $this->getPostType();
49 +
50 + // Building Args.
49 51 $this
50 - ->post_params()
51 - ->order_params()
52 - ->pagination_params( $isCarousel )
53 - ->tax_params();
52 + ->postParams()
53 + ->orderParams()
54 + ->paginationParams( $isCarousel )
55 + ->taxParams();
54 56
55 57 } else {
56 58 $this
57 - ->get_tax_type()
58 - ->cat_params()
59 - ->cat_order_params();
59 + ->getTaxType()
60 + ->catParams()
61 + ->catOrderParams();
60 62 }
61 63
62 64 return apply_filters( 'rtsb/elements/' . $type . '_query_args', $this->args, $this->meta );
63 65 }
@@ -64,11 +66,21 @@
64 66
65 67 /**
66 68 * Post type.
67 69 *
70 + * @return void
71 + */
72 + private function getPostType() {
73 + $this->args['post_type'] = [ rtsb()->post_type ];
74 + $this->args['post_status'] = 'publish';
75 + }
76 +
77 + /**
78 + * Post type.
79 + *
68 80 * @return QueryArgs
69 81 */
70 - private function get_tax_type() {
82 + private function getTaxType() {
71 83 $this->args['taxonomy'] = [ 'product_cat' ];
72 84 $this->args['post_status'] = 'publish';
73 85 $this->args['hierarchical'] = 1;
74 86
@@ -75,34 +87,35 @@
75 87 return $this;
76 88 }
77 89
78 90 /**
79 - * WC Post parameters.
91 + * Post parameters.
80 92 *
81 93 * @return QueryArgs
82 94 */
83 - private function post_params() {
84 - $post_in = isset( $this->meta['post_in'] ) ? sanitize_text_field( implode( ',', $this->meta['post_in'] ) ) : null;
95 + private function postParams() {
96 + $post_in = isset( $this->meta['post_in'] ) ? sanitize_text_field( implode( ', ', $this->meta['post_in'] ) ) : null;
85 97 $post_not_in = isset( $this->meta['post_not_in'] ) ? sanitize_text_field( implode( ', ', $this->meta['post_not_in'] ) ) : null;
86 - $author_in = isset( $this->meta['author_in'] ) ? sanitize_text_field( implode( ',', $this->meta['author_in'] ) ) : null;
98 + $author_in = isset( $this->meta['author_in'] ) ? sanitize_text_field( implode( ', ', $this->meta['author_in'] ) ) : null;
87 99 $limit = ( ( empty( $this->meta['limit'] ) || '-1' === $this->meta['limit'] ) ? 10000000 : absint( $this->meta['limit'] ) );
88 100 $offset = ! empty( $this->meta['offset'] ) ? absint( $this->meta['offset'] ) : 0;
89 101
90 102 if ( $post_in ) {
91 - $post_in = explode( ',', $post_in );
92 - $this->args['include'] = $post_in;
103 + $post_in = explode( ',', $post_in );
104 + $this->args['post__in'] = $post_in;
93 105 }
94 106
95 107 if ( $post_not_in ) {
96 - $post_not_in = explode( ',', $post_not_in );
97 - $this->args['exclude'] = $post_not_in; // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude
108 + $post_not_in = explode( ',', $post_not_in );
109 + $this->args['post__not_in'] = $post_not_in;
98 110 }
99 111
100 112 if ( $author_in ) {
101 - $this->args['author'] = $author_in;
113 + $author_in = explode( ',', $author_in );
114 + $this->args['author__in'] = $author_in;
102 115 }
103 116
104 - $this->args['limit'] = $limit;
117 + $this->args['posts_per_page'] = $limit;
105 118
106 119 if ( $offset ) {
107 120 $this->args['offset'] = $offset;
108 121 }
@@ -114,9 +127,9 @@
114 127 * Category parameters.
115 128 *
116 129 * @return QueryArgs
117 130 */
118 - private function cat_params() {
131 + private function catParams() {
119 132 $cats_in = isset( $this->meta['include_cats'] ) ? sanitize_text_field( implode( ', ', $this->meta['include_cats'] ) ) : null;
120 133 $cat_ids_in = isset( $this->meta['select_cat_ids'] ) ? esc_html( $this->meta['select_cat_ids'] ) : null;
121 134 $cats_not_in = isset( $this->meta['exclude_cats'] ) ? sanitize_text_field( implode( ', ', $this->meta['exclude_cats'] ) ) : null;
122 135 $limit = ( ( empty( $this->meta['cats_limit'] ) || '-1' === $this->meta['cats_limit'] ) ? 10000000 : absint( $this->meta['cats_limit'] ) );
@@ -134,9 +147,9 @@
134 147 }
135 148
136 149 if ( $cats_not_in ) {
137 150 $cats_not_in = array_filter( explode( ',', $cats_not_in ) );
138 - $this->args['exclude'] = $cats_not_in; // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude
151 + $this->args['exclude'] = $cats_not_in;
139 152 }
140 153
141 154 $this->args['number'] = $limit;
142 155 $this->args['hide_empty'] = $this->meta['show_empty'] ? 0 : 1;
@@ -170,13 +183,13 @@
170 183 return $this;
171 184 }
172 185
173 186 /**
174 - * WC Order & Orderby parameters.
187 + * Order & Orderby parameters.
175 188 *
176 189 * @return QueryArgs
177 190 */
178 - private function order_params() {
191 + private function orderParams() {
179 192 $order_by = ( isset( $this->meta['order_by'] ) ? esc_html( $this->meta['order_by'] ) : null );
180 193 $order = ( isset( $this->meta['order'] ) ? esc_html( $this->meta['order'] ) : null );
181 194
182 195 if ( $order ) {
@@ -184,12 +197,8 @@
184 197 }
185 198
186 199 if ( $order_by ) {
187 200 $this->args['orderby'] = $order_by;
188 -
189 - if ( 'menu_order' === $order_by ) {
190 - $this->args['orderby'] = 'menu_order title';
191 - }
192 201 }
193 202
194 203 return $this;
195 204 }
@@ -198,9 +207,9 @@
198 207 * Order & Orderby parameters.
199 208 *
200 209 * @return QueryArgs
201 210 */
202 - private function cat_order_params() {
211 + private function catOrderParams() {
203 212 $order_by = ( isset( $this->meta['cats_order_by'] ) ? esc_html( $this->meta['cats_order_by'] ) : 'name' );
204 213 $order = ( isset( $this->meta['cats_order'] ) ? esc_html( $this->meta['cats_order'] ) : 'DESC' );
205 214
206 215 if ( $order ) {
@@ -224,15 +233,13 @@
224 233 * @param bool $isCarousel Layout type.
225 234 *
226 235 * @return QueryArgs
227 236 */
228 - private function pagination_params( $isCarousel ) {
237 + private function paginationParams( $isCarousel ) {
229 238 $pagination = ! empty( $this->meta['pagination'] );
230 239 $limit = ( ( empty( $this->meta['limit'] ) || '-1' === $this->meta['limit'] ) ? 10000000 : absint( $this->meta['limit'] ) );
231 240
232 241 if ( $pagination ) {
233 - unset( $this->args['offset'] );
234 -
235 242 $posts_per_page = ( ! empty( $this->meta['posts_per_page'] ) ? absint( $this->meta['posts_per_page'] ) : $limit );
236 243
237 244 if ( $posts_per_page > $limit ) {
238 245 $posts_per_page = $limit;
@@ -237,10 +244,9 @@
237 244 if ( $posts_per_page > $limit ) {
238 245 $posts_per_page = $limit;
239 246 }
240 247
241 - $this->args['paginate'] = true;
242 - $this->args['limit'] = $posts_per_page;
248 + $this->args['posts_per_page'] = $posts_per_page;
243 249
244 250 if ( is_front_page() ) {
245 251 $paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
246 252 } else {
@@ -246,19 +252,19 @@
246 252 } else {
247 253 $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
248 254 }
249 255
250 - $offset = $posts_per_page * ( (int) $paged - 1 );
251 - $this->args['page'] = $paged;
256 + $offset = $posts_per_page * ( (int) $paged - 1 );
257 + $this->args['paged'] = $paged;
252 258
253 - if ( absint( $this->args['limit'] ) > $limit - $offset ) {
254 - $this->args['limit'] = $limit - $offset;
255 - $this->args['offset'] = $offset;
259 + if ( absint( $this->args['posts_per_page'] ) > $limit - $offset ) {
260 + $this->args['posts_per_page'] = $limit - $offset;
261 + $this->args['offset'] = $offset;
256 262 }
257 263 }
258 264
259 265 if ( $isCarousel ) {
260 - $this->args['limit'] = $limit;
266 + $this->args['posts_per_page'] = $limit;
261 267 }
262 268
263 269 return $this;
264 270 }
@@ -265,24 +271,57 @@
265 271
266 272 /**
267 273 * Taxonomy parameters.
268 274 *
269 - * @return void
275 + * @return QueryArgs
270 276 */
271 - private function tax_params(): void {
277 + private function taxParams() {
272 278 $categories = isset( $this->meta['categories'] ) ? array_filter( $this->meta['categories'] ) : [];
273 279 $tags = isset( $this->meta['tags'] ) ? array_filter( $this->meta['tags'] ) : [];
274 280 $attributes = isset( $this->meta['attributes'] ) ? array_filter( $this->meta['attributes'] ) : [];
281 + $taxQ = [];
275 282
276 - if ( ! empty( $categories ) ) {
277 - $this->args['product_category_id'] = $categories;
283 + if ( is_array( $categories ) && ! empty( $categories ) ) {
284 + $taxQ[] = [
285 + 'taxonomy' => 'product_cat',
286 + 'field' => 'term_id',
287 + 'terms' => $categories,
288 + 'operator' => 'IN',
289 + ];
278 290 }
279 291
280 - if ( ! empty( $tags ) ) {
281 - $this->args['product_tag_id'] = $tags;
292 + if ( ! empty( $tags ) && is_array( $tags ) ) {
293 + $taxQ[] = [
294 + 'taxonomy' => 'product_tag',
295 + 'field' => 'term_id',
296 + 'terms' => $tags,
297 + 'operator' => 'IN',
298 + ];
282 299 }
283 300
284 - if ( ! empty( $attributes ) ) {
285 - $this->args['product_attribute_id'] = $attributes;
301 + if ( ! empty( $attributes ) && is_array( $attributes ) ) {
302 + $attribute_tax = null;
303 +
304 + foreach ( $attributes as $atts ) {
305 + $attribute_tax = get_term( $atts )->taxonomy;
306 +
307 + $taxQ[] = [
308 + 'taxonomy' => $attribute_tax,
309 + 'field' => 'term_id',
310 + 'terms' => [ $atts ],
311 + 'operator' => 'IN',
312 + ];
313 + }
286 314 }
315 +
316 + if ( count( $taxQ ) >= 2 ) {
317 + $taxQ['relation'] = $this->meta['relation'];
318 + }
319 +
320 + if ( ! empty( $taxQ ) ) {
321 + $this->args['tax_query'] = $taxQ;
322 + }
323 +
324 + return $this;
287 325 }
326 +
288 327 }