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