PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.1.4
ShopBuilder – WooCommerce Builder For Elementor v1.1.4
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 +352 -327 2.0.21.1.4 View file →
@@ -1,327 +1,352 @@
1 -<?php
2 -/**
3 - * Class to build up query args.
4 - *
5 - * @package RadiusTheme\SB
6 - */
7 -
8 -namespace RadiusTheme\SB\Models;
9 -
10 -// Do not allow directly accessing this file.
11 -if ( ! defined( 'ABSPATH' ) ) {
12 - exit( 'This script cannot be accessed directly.' );
13 -}
14 -
15 -/**
16 - * Query Args Class
17 - */
18 -class QueryArgs {
19 -
20 - /**
21 - * Query Args.
22 - *
23 - * @var array
24 - */
25 - private $args = [];
26 -
27 - /**
28 - * Meta values.
29 - *
30 - * @var array
31 - */
32 - private $meta = [];
33 -
34 - /**
35 - * Method to build args
36 - *
37 - * @param array $meta Meta values.
38 - * @param string $type Query type.
39 - * @param bool $isCarousel Layout type.
40 - *
41 - * @return array
42 - */
43 - public function buildArgs( array $meta, string $type = 'product', bool $isCarousel = false ) {
44 - $this->meta = $meta;
45 -
46 - if ( 'product' === $type ) {
47 - // Post Type.
48 - $this->getPostType();
49 -
50 - // Building Args.
51 - $this
52 - ->postParams()
53 - ->orderParams()
54 - ->paginationParams( $isCarousel )
55 - ->taxParams();
56 -
57 - } else {
58 - $this
59 - ->getTaxType()
60 - ->catParams()
61 - ->catOrderParams();
62 - }
63 -
64 - return apply_filters( 'rtsb/elements/' . $type . '_query_args', $this->args, $this->meta );
65 - }
66 -
67 - /**
68 - * Post type.
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 - *
80 - * @return QueryArgs
81 - */
82 - private function getTaxType() {
83 - $this->args['taxonomy'] = [ 'product_cat' ];
84 - $this->args['post_status'] = 'publish';
85 - $this->args['hierarchical'] = 1;
86 -
87 - return $this;
88 - }
89 -
90 - /**
91 - * Post parameters.
92 - *
93 - * @return QueryArgs
94 - */
95 - private function postParams() {
96 - $post_in = isset( $this->meta['post_in'] ) ? sanitize_text_field( implode( ', ', $this->meta['post_in'] ) ) : null;
97 - $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;
99 - $limit = ( ( empty( $this->meta['limit'] ) || '-1' === $this->meta['limit'] ) ? 10000000 : absint( $this->meta['limit'] ) );
100 - $offset = ! empty( $this->meta['offset'] ) ? absint( $this->meta['offset'] ) : 0;
101 -
102 - if ( $post_in ) {
103 - $post_in = explode( ',', $post_in );
104 - $this->args['post__in'] = $post_in;
105 - }
106 -
107 - if ( $post_not_in ) {
108 - $post_not_in = explode( ',', $post_not_in );
109 - $this->args['post__not_in'] = $post_not_in;
110 - }
111 -
112 - if ( $author_in ) {
113 - $author_in = explode( ',', $author_in );
114 - $this->args['author__in'] = $author_in;
115 - }
116 -
117 - $this->args['posts_per_page'] = $limit;
118 -
119 - if ( $offset ) {
120 - $this->args['offset'] = $offset;
121 - }
122 -
123 - return $this;
124 - }
125 -
126 - /**
127 - * Category parameters.
128 - *
129 - * @return QueryArgs
130 - */
131 - private function catParams() {
132 - $cats_in = isset( $this->meta['include_cats'] ) ? sanitize_text_field( implode( ', ', $this->meta['include_cats'] ) ) : null;
133 - $cat_ids_in = isset( $this->meta['select_cat_ids'] ) ? esc_html( $this->meta['select_cat_ids'] ) : null;
134 - $cats_not_in = isset( $this->meta['exclude_cats'] ) ? sanitize_text_field( implode( ', ', $this->meta['exclude_cats'] ) ) : null;
135 - $limit = ( ( empty( $this->meta['cats_limit'] ) || '-1' === $this->meta['cats_limit'] ) ? 10000000 : absint( $this->meta['cats_limit'] ) );
136 -
137 - if ( $cats_in ) {
138 - $cats_in = explode( ',', $cats_in );
139 - }
140 -
141 - if ( $cat_ids_in ) {
142 - $cats_in = explode( ',', $cat_ids_in );
143 - }
144 -
145 - if ( ! $this->meta['show_uncategorized'] ) {
146 - $cats_not_in .= ',' . get_option( 'default_product_cat', 0 );
147 - }
148 -
149 - if ( $cats_not_in ) {
150 - $cats_not_in = array_filter( explode( ',', $cats_not_in ) );
151 - $this->args['exclude'] = $cats_not_in;
152 - }
153 -
154 - $this->args['number'] = $limit;
155 - $this->args['hide_empty'] = $this->meta['show_empty'] ? 0 : 1;
156 -
157 - if ( ! $this->meta['show_subcats'] ) {
158 - $this->args['parent'] = 0;
159 - }
160 -
161 - switch ( $this->meta['display_cat_by'] ) {
162 - case 'specific_parent':
163 - unset( $this->args['exclude'] );
164 - unset( $this->args['parent'] );
165 -
166 - if ( $this->meta['show_top_level_cats'] ) {
167 - $this->args['parent'] = absint( $this->meta['select_parent_cat'] );
168 - } else {
169 - $this->args['child_of'] = absint( $this->meta['select_parent_cat'] );
170 - }
171 - break;
172 - case 'cat_ids':
173 - case 'selection':
174 - unset( $this->args['exclude'] );
175 - unset( $this->args['parent'] );
176 -
177 - $this->args['include'] = $cats_in;
178 - break;
179 - default:
180 - break;
181 - }
182 -
183 - return $this;
184 - }
185 -
186 - /**
187 - * Order & Orderby parameters.
188 - *
189 - * @return QueryArgs
190 - */
191 - private function orderParams() {
192 - $order_by = ( isset( $this->meta['order_by'] ) ? esc_html( $this->meta['order_by'] ) : null );
193 - $order = ( isset( $this->meta['order'] ) ? esc_html( $this->meta['order'] ) : null );
194 -
195 - if ( $order ) {
196 - $this->args['order'] = $order;
197 - }
198 -
199 - if ( $order_by ) {
200 - $this->args['orderby'] = $order_by;
201 - }
202 -
203 - return $this;
204 - }
205 -
206 - /**
207 - * Order & Orderby parameters.
208 - *
209 - * @return QueryArgs
210 - */
211 - private function catOrderParams() {
212 - $order_by = ( isset( $this->meta['cats_order_by'] ) ? esc_html( $this->meta['cats_order_by'] ) : 'name' );
213 - $order = ( isset( $this->meta['cats_order'] ) ? esc_html( $this->meta['cats_order'] ) : 'DESC' );
214 -
215 - if ( $order ) {
216 - $this->args['order'] = $order;
217 - }
218 -
219 - if ( $order_by ) {
220 - $this->args['orderby'] = $order_by;
221 - }
222 -
223 - if ( 'menu_order' === $order_by ) {
224 - $this->args['menu_order'] = $order;
225 - }
226 -
227 - return $this;
228 - }
229 -
230 - /**
231 - * Pagination parameters.
232 - *
233 - * @param bool $isCarousel Layout type.
234 - *
235 - * @return QueryArgs
236 - */
237 - private function paginationParams( $isCarousel ) {
238 - $pagination = ! empty( $this->meta['pagination'] );
239 - $limit = ( ( empty( $this->meta['limit'] ) || '-1' === $this->meta['limit'] ) ? 10000000 : absint( $this->meta['limit'] ) );
240 -
241 - if ( $pagination ) {
242 - $posts_per_page = ( ! empty( $this->meta['posts_per_page'] ) ? absint( $this->meta['posts_per_page'] ) : $limit );
243 -
244 - if ( $posts_per_page > $limit ) {
245 - $posts_per_page = $limit;
246 - }
247 -
248 - $this->args['posts_per_page'] = $posts_per_page;
249 -
250 - if ( is_front_page() ) {
251 - $paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
252 - } else {
253 - $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
254 - }
255 -
256 - $offset = $posts_per_page * ( (int) $paged - 1 );
257 - $this->args['paged'] = $paged;
258 -
259 - if ( absint( $this->args['posts_per_page'] ) > $limit - $offset ) {
260 - $this->args['posts_per_page'] = $limit - $offset;
261 - $this->args['offset'] = $offset;
262 - }
263 - }
264 -
265 - if ( $isCarousel ) {
266 - $this->args['posts_per_page'] = $limit;
267 - }
268 -
269 - return $this;
270 - }
271 -
272 - /**
273 - * Taxonomy parameters.
274 - *
275 - * @return QueryArgs
276 - */
277 - private function taxParams() {
278 - $categories = isset( $this->meta['categories'] ) ? array_filter( $this->meta['categories'] ) : [];
279 - $tags = isset( $this->meta['tags'] ) ? array_filter( $this->meta['tags'] ) : [];
280 - $attributes = isset( $this->meta['attributes'] ) ? array_filter( $this->meta['attributes'] ) : [];
281 - $taxQ = [];
282 -
283 - if ( is_array( $categories ) && ! empty( $categories ) ) {
284 - $taxQ[] = [
285 - 'taxonomy' => 'product_cat',
286 - 'field' => 'term_id',
287 - 'terms' => $categories,
288 - 'operator' => 'IN',
289 - ];
290 - }
291 -
292 - if ( ! empty( $tags ) && is_array( $tags ) ) {
293 - $taxQ[] = [
294 - 'taxonomy' => 'product_tag',
295 - 'field' => 'term_id',
296 - 'terms' => $tags,
297 - 'operator' => 'IN',
298 - ];
299 - }
300 -
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 - }
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;
325 - }
326 -
327 -}
1 +<?php
2 +/**
3 + * Class to build up query args.
4 + *
5 + * @package RadiusTheme\SB
6 + */
7 +
8 +namespace RadiusTheme\SB\Models;
9 +
10 +// Do not allow directly accessing this file.
11 +if ( ! defined( 'ABSPATH' ) ) {
12 + exit( 'This script cannot be accessed directly.' );
13 +}
14 +
15 +/**
16 + * Query Args Class
17 + */
18 +class QueryArgs {
19 +
20 + /**
21 + * Query Args.
22 + *
23 + * @var array
24 + */
25 + private $args = [];
26 +
27 + /**
28 + * Meta values.
29 + *
30 + * @var array
31 + */
32 + private $meta = [];
33 +
34 + /**
35 + * Method to build args
36 + *
37 + * @param array $meta Meta values.
38 + * @param string $type Query type.
39 + * @param bool $isCarousel Layout type.
40 + *
41 + * @return array
42 + */
43 + public function buildArgs( array $meta, string $type = 'product', bool $isCarousel = false ) {
44 + $this->meta = $meta;
45 +
46 + if ( 'product' === $type ) {
47 + // Post Type.
48 + $this->getPostType();
49 +
50 + // Building Args.
51 + $this
52 + ->postParams()
53 + ->orderParams()
54 + ->paginationParams( $isCarousel )
55 + ->taxParams();
56 +
57 + } else {
58 + $this
59 + ->getTaxType()
60 + ->catParams()
61 + ->catOrderParams();
62 + }
63 +
64 + return apply_filters( 'rtsb/elements/elementor/' . $type . '_query_args', $this->args );
65 + }
66 +
67 + /**
68 + * Post type.
69 + *
70 + * @return QueryArgs
71 + */
72 + private function getPostType() {
73 + $this->args['post_type'] = [ rtsb()->post_type ];
74 + $this->args['post_status'] = 'publish';
75 +
76 + return $this;
77 + }
78 + /**
79 + * Post type.
80 + *
81 + * @return QueryArgs
82 + */
83 + private function getTaxType() {
84 + $this->args['taxonomy'] = [ 'product_cat' ];
85 + $this->args['post_status'] = 'publish';
86 + $this->args['hierarchical'] = 1;
87 +
88 + return $this;
89 + }
90 +
91 + /**
92 + * Post parameters.
93 + *
94 + * @return QueryArgs
95 + */
96 + private function postParams() {
97 + $post_in = isset( $this->meta['post_in'] ) ? sanitize_text_field( implode( ', ', $this->meta['post_in'] ) ) : null;
98 + $post_not_in = isset( $this->meta['post_not_in'] ) ? sanitize_text_field( implode( ', ', $this->meta['post_not_in'] ) ) : null;
99 + $author_in = isset( $this->meta['author_in'] ) ? sanitize_text_field( implode( ', ', $this->meta['author_in'] ) ) : null;
100 + $limit = ( ( empty( $this->meta['limit'] ) || '-1' === $this->meta['limit'] ) ? 10000000 : absint( $this->meta['limit'] ) );
101 + $offset = ! empty( $this->meta['offset'] ) ? absint( $this->meta['offset'] ) : 0;
102 +
103 + if ( $post_in ) {
104 + $post_in = explode( ',', $post_in );
105 + $this->args['post__in'] = $post_in;
106 + }
107 +
108 + if ( $post_not_in ) {
109 + $post_not_in = explode( ',', $post_not_in );
110 + $this->args['post__not_in'] = $post_not_in;
111 + }
112 +
113 + if ( $author_in ) {
114 + $author_in = explode( ',', $author_in );
115 + $this->args['author__in'] = $author_in;
116 + }
117 +
118 + $this->args['posts_per_page'] = $limit;
119 +
120 + if ( $offset ) {
121 + $this->args['offset'] = $offset;
122 + }
123 +
124 + return $this;
125 + }
126 +
127 + /**
128 + * Category parameters.
129 + *
130 + * @return QueryArgs
131 + */
132 + private function catParams() {
133 + $cats_in = isset( $this->meta['include_cats'] ) ? sanitize_text_field( implode( ', ', $this->meta['include_cats'] ) ) : null;
134 + $cat_ids_in = isset( $this->meta['select_cat_ids'] ) ? esc_html( $this->meta['select_cat_ids'] ) : null;
135 + $cats_not_in = isset( $this->meta['exclude_cats'] ) ? sanitize_text_field( implode( ', ', $this->meta['exclude_cats'] ) ) : null;
136 + $limit = ( ( empty( $this->meta['cats_limit'] ) || '-1' === $this->meta['cats_limit'] ) ? 10000000 : absint( $this->meta['cats_limit'] ) );
137 +
138 + if ( $cats_in ) {
139 + $cats_in = explode( ',', $cats_in );
140 + }
141 +
142 + if ( $cat_ids_in ) {
143 + $cats_in = explode( ',', $cat_ids_in );
144 + }
145 +
146 + if ( ! $this->meta['show_uncategorized'] ) {
147 + $cats_not_in .= ',' . get_option( 'default_product_cat', 0 );
148 + }
149 +
150 + if ( $cats_not_in ) {
151 + $cats_not_in = array_filter( explode( ',', $cats_not_in ) );
152 + $this->args['exclude'] = $cats_not_in;
153 + }
154 +
155 + $this->args['number'] = $limit;
156 + $this->args['hide_empty'] = $this->meta['show_empty'] ? 0 : 1;
157 +
158 + if ( ! $this->meta['show_subcats'] ) {
159 + $this->args['parent'] = 0;
160 + }
161 +
162 + switch ( $this->meta['display_cat_by'] ) {
163 + case 'specific_parent':
164 + unset( $this->args['exclude'] );
165 + unset( $this->args['parent'] );
166 +
167 + if ( $this->meta['show_top_level_cats'] ) {
168 + $this->args['parent'] = absint( $this->meta['select_parent_cat'] );
169 + } else {
170 + $this->args['child_of'] = absint( $this->meta['select_parent_cat'] );
171 + }
172 + break;
173 + case 'cat_ids':
174 + case 'selection':
175 + unset( $this->args['exclude'] );
176 + unset( $this->args['parent'] );
177 +
178 + $this->args['include'] = $cats_in;
179 + break;
180 + default:
181 + break;
182 + }
183 +
184 + return $this;
185 + }
186 +
187 + /**
188 + * Order & Orderby parameters.
189 + *
190 + * @return QueryArgs
191 + */
192 + private function orderParams() {
193 + $order_by = ( isset( $this->meta['order_by'] ) ? esc_html( $this->meta['order_by'] ) : null );
194 + $order = ( isset( $this->meta['order'] ) ? esc_html( $this->meta['order'] ) : null );
195 +
196 + if ( $order ) {
197 + $this->args['order'] = $order;
198 + }
199 +
200 + if ( $order_by ) {
201 + $this->args['orderby'] = $order_by;
202 + }
203 +
204 + return $this;
205 + }
206 +
207 + /**
208 + * Order & Orderby parameters.
209 + *
210 + * @return QueryArgs
211 + */
212 + private function catOrderParams() {
213 + $order_by = ( isset( $this->meta['cats_order_by'] ) ? esc_html( $this->meta['cats_order_by'] ) : 'name' );
214 + $order = ( isset( $this->meta['cats_order'] ) ? esc_html( $this->meta['cats_order'] ) : 'DESC' );
215 +
216 + if ( $order ) {
217 + $this->args['order'] = $order;
218 + }
219 +
220 + if ( $order_by ) {
221 + $this->args['orderby'] = $order_by;
222 + }
223 +
224 + if ( 'menu_order' === $order_by ) {
225 + $this->args['menu_order'] = $order;
226 + }
227 +
228 + return $this;
229 + }
230 +
231 + /**
232 + * Pagination parameters.
233 + *
234 + * @param bool $isCarousel Layout type.
235 + *
236 + * @return QueryArgs
237 + */
238 + private function paginationParams( $isCarousel ) {
239 + $pagination = ! empty( $this->meta['pagination'] );
240 + $limit = ( ( empty( $this->meta['limit'] ) || '-1' === $this->meta['limit'] ) ? 10000000 : absint( $this->meta['limit'] ) );
241 +
242 +
243 + if ( $pagination ) {
244 + $posts_per_page = ( ! empty( $this->meta['posts_per_page'] ) ? absint( $this->meta['posts_per_page'] ) : $limit );
245 +
246 + if ( $posts_per_page > $limit ) {
247 + $posts_per_page = $limit;
248 + }
249 +
250 + $this->args['posts_per_page'] = $posts_per_page;
251 +
252 + if ( is_front_page() ) {
253 + $paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
254 + } else {
255 + $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
256 + }
257 +
258 + $offset = $posts_per_page * ( (int) $paged - 1 );
259 + $this->args['paged'] = $paged;
260 +
261 + if ( absint( $this->args['posts_per_page'] ) > $limit - $offset ) {
262 + $this->args['posts_per_page'] = $limit - $offset;
263 + $this->args['offset'] = $offset;
264 + }
265 + }
266 +
267 + if ( $isCarousel ) {
268 + $this->args['posts_per_page'] = $limit;
269 + }
270 +
271 + return $this;
272 + }
273 +
274 + /**
275 + * Taxonomy parameters.
276 + *
277 + * @return QueryArgs
278 + */
279 + private function taxParams() {
280 + $categories = isset( $this->meta['categories'] ) ? array_filter( $this->meta['categories'] ) : [];
281 + $tags = isset( $this->meta['tags'] ) ? array_filter( $this->meta['tags'] ) : [];
282 + $attributes = isset( $this->meta['attributes'] ) ? array_filter( $this->meta['attributes'] ) : [];
283 + $display_by = isset( $this->meta['display_by'] ) ? $this->meta['display_by'] : null;
284 + $post_in = isset( $this->meta['post_in'] ) ? $this->meta['post_in'] : [ 0 ];
285 + $taxQ = [];
286 +
287 + if ( is_array( $categories ) && ! empty( $categories ) ) {
288 + $taxQ[] = [
289 + 'taxonomy' => 'product_cat',
290 + 'field' => 'term_id',
291 + 'terms' => $categories,
292 + 'operator' => 'IN',
293 + ];
294 + }
295 +
296 + if ( ! empty( $tags ) && is_array( $tags ) ) {
297 + $taxQ[] = [
298 + 'taxonomy' => 'product_tag',
299 + 'field' => 'term_id',
300 + 'terms' => $tags,
301 + 'operator' => 'IN',
302 + ];
303 + }
304 +
305 + if ( ! empty( $attributes ) && is_array( $attributes ) ) {
306 + $attribute_tax = null;
307 +
308 + foreach ( $attributes as $atts ) {
309 + $attribute_tax = get_term( $atts )->taxonomy;
310 +
311 + $taxQ[] = [
312 + 'taxonomy' => $attribute_tax,
313 + 'field' => 'term_id',
314 + 'terms' => [ $atts ],
315 + 'operator' => 'IN',
316 + ];
317 + }
318 + }
319 +
320 + if ( count( $taxQ ) >= 2 ) {
321 + $taxQ['relation'] = $this->meta['relation'];
322 + }
323 +
324 + if ( rtsb()->has_pro() ) {
325 + if ( 'featured' === $display_by ) {
326 + $taxQ[] = [
327 + 'taxonomy' => 'product_visibility',
328 + 'field' => 'name',
329 + 'terms' => 'featured',
330 + 'operator' => 'IN',
331 + ];
332 + } elseif ( 'recent' === $display_by ) {
333 + $this->args['orderby'] = 'date';
334 + } elseif ( 'best-selling' === $display_by ) {
335 + $this->args['meta_key'] = 'total_sales';
336 + $this->args['orderby'] = 'meta_value_num';
337 + } elseif ( 'sale' === $display_by ) {
338 + $this->args['post__in'] = array_merge( $post_in, wc_get_product_ids_on_sale() );
339 + } elseif ( 'top-rated' === $display_by ) {
340 + $this->args['meta_key'] = '_wc_average_rating';
341 + $this->args['orderby'] = 'meta_value_num';
342 + }
343 + }
344 +
345 + if ( ! empty( $taxQ ) ) {
346 + $this->args['tax_query'] = $taxQ;
347 + }
348 +
349 + return $this;
350 + }
351 +
352 +}