PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.6.5
ShopBuilder – WooCommerce Builder For Elementor v2.6.5
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/Controllers/Admin/Ajax/ModalTemplate.php +198 -60 2.1.122.6.5 View file →
@@ -3,9 +3,11 @@
3 3 namespace RadiusTheme\SB\Controllers\Admin\Ajax;
4 4
5 5 use Elementor\Plugin;
6 6 use RadiusTheme\SB\Helpers\BuilderFns;
7 +use RadiusTheme\SB\Helpers\Cache;
7 8 use RadiusTheme\SB\Helpers\Fns;
9 +use RadiusTheme\SB\Models\TemplateSettings;
8 10 use RadiusTheme\SB\Traits\SingletonTrait;
9 11 use Elementor\Core\Files\Uploads_Manager;
10 12
11 13 // Do not allow directly accessing this file.
@@ -27,9 +29,9 @@
27 29 */
28 30 private function __construct() {
29 31 add_action( 'wp_ajax_rtsb_builder_modal_template', [ $this, 'response' ] );
30 32 add_action( 'wp_ajax_rtsb_modal_product_search', [ $this, 'product_search' ] );
31 - add_action( 'wp_ajax_rtsb_modal_category_search', [ $this, 'category_search' ] );
33 + add_action( 'wp_ajax_rtsb_modal_term_search', [ $this, 'term_search' ] );
32 34 }
33 35
34 36 /**
35 37 * Popups For Create Template
@@ -54,9 +56,18 @@
54 56 'content' => esc_html__( 'Permission Denied...', 'shopbuilder' ),
55 57 ];
56 58 wp_send_json( $return );
57 59 }
60 + if ( ! defined( 'ELEMENTOR_VERSION' ) ) {
61 + $return = [
62 + 'success' => true,
63 + 'title' => $title,
64 + 'content' => '<h2 style="text-align: center;">' . esc_html__( 'Permission Denied. Please Install elementor', 'shopbuilder' ) . '</h2>',
65 + ];
58 66
67 + wp_send_json( $return );
68 + }
69 +
59 70 add_filter( 'option_' . Uploads_Manager::UNFILTERED_FILE_UPLOADS_KEY, '__return_true' );
60 71 Plugin::$instance->files_manager->clear_cache();
61 72
62 73 // user capability check.
@@ -62,13 +73,14 @@
62 73 // user capability check.
63 74 $user = wp_get_current_user();
64 75 $allowed_roles = [ 'editor', 'administrator', 'author' ];
65 76
66 - if ( ! array_intersect( $allowed_roles, $user->roles ) ) {
77 + if ( ! array_intersect( $allowed_roles, Fns::get_current_user_roles() ) ) {
67 78 wp_die( esc_html__( 'You don\'t have permission to perform this action', 'shopbuilder' ) );
68 79 }
69 80
70 81 // Check if the user is not logged in and the provided 'user_id' in the request does not match the currently logged-in user's ID.
82 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
71 83 if ( ! is_user_logged_in() && $user->ID !== sanitize_text_field( $_REQUEST['user_id'] ) ) {
72 84 wp_die( esc_html__( 'You don\'t have proper authorization to perform this action', 'shopbuilder' ) );
73 85 }
74 86
@@ -75,8 +87,9 @@
75 87 $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : null;
76 88 $layout_id = isset( $_POST['layout_id'] ) ? absint( $_POST['layout_id'] ) : null;
77 89
78 90 $template_type = null;
91 + $product_page_for = 'all_products';
79 92 $template_default = null;
80 93 $url = '';
81 94 $tmp_title = '';
82 95 $_rtsb_import_id = '';
@@ -82,13 +95,16 @@
82 95 $_rtsb_import_id = '';
83 96 $edit_by = did_action( 'elementor/loaded' ) ? 'elementor' : 'elementor';
84 97 if ( $post_id ) {
85 98 $tmp_title = get_the_title( $post_id );
86 - $type = get_post_meta( $post_id, BuilderFns::template_type_meta_key() );
87 - $template_type = isset( $type[0] ) ? $type[0] : '';
88 - $template_default = absint( BuilderFns::builder_page_id_by_type( $template_type ) );
99 + $template_type = get_post_meta( $post_id, BuilderFns::template_type_meta_key(), true );
100 + $options = BuilderFns::option_name( $template_type );
101 + $template_default = TemplateSettings::instance()->get_option( $options );
89 102 $edit_by = Fns::page_edit_with( $post_id );
90 103 $action = 'edit';
104 + if ( rtsb()->has_pro() ) {
105 + $product_page_for = get_post_meta( $post_id, '_is_product_page_template_for', true );
106 + }
91 107
92 108 // TODO:: This Condition Will remove after release Gutenberg Addons.
93 109 if ( 'gutenberg' == $edit_by ) {
94 110 $action = 'elementor';
@@ -109,8 +125,9 @@
109 125
110 126 $_rtsb_import_id = get_post_meta( $post_id, '_rtsb_import_id', true );
111 127 }
112 128
129 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
113 130 $status = $_REQUEST['status'] ?? '';
114 131 $post_args = [ 'timeout' => 120 ];
115 132 $post_args['body'] = [
116 133 'status' => $status,
@@ -137,10 +154,9 @@
137 154 placeholder="<?php esc_attr_e( 'Enter Template Name', 'shopbuilder' ); ?>"
138 155 value="<?php echo esc_attr( $tmp_title ); ?>"
139 156 autocomplete="off"
140 157 >
141 - <span class="message"
142 - style="display: none; color:red"><?php esc_html_e( 'This field is required', 'shopbuilder' ); ?></span>
158 + <span class="message" style="display: none; color:red"><?php esc_html_e( 'This field is required', 'shopbuilder' ); ?></span>
143 159 </div>
144 160 <div class="rtsb-template-type rtsb-tb-field-wraper">
145 161 <label for="rtsb_tb_template_type"><?php esc_html_e( 'Select Template Type', 'shopbuilder' ); ?></label>
146 162 <select class="rtsb-field" id="rtsb_tb_template_type" name="rtsb_tb_template_type">
@@ -152,37 +168,111 @@
152 168 <?php } ?>
153 169 </select>
154 170 </div>
155 171
156 - <div class="rtsb-product-page-field rtsb-tb-field-wraper" style="display:none;">
172 + <div class="rtsb-product-page-for rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;" >
173 + <label for="product_page_for">
174 + <?php esc_html_e( 'Product Template For', 'shopbuilder' ); ?>
175 + <?php if ( ! rtsb()->has_pro() ) { ?>
176 + <div class="card-label">
177 + <span class="rtsb-btn-import pro-btn">
178 + <?php echo esc_html( 'PRO' ); ?>
179 + </span>
180 + </div>
181 + <?php } ?>
182 + </label>
183 +
184 + <select class="rtsb-field" id="product_page_for" name="product_page_for">
185 + <?php
186 + $builder_page_types = [
187 + 'all_products' => esc_html__( 'All Products', 'shopbuilder' ),
188 + 'product_cats' => esc_html__( 'Product Categories', 'shopbuilder' ),
189 + 'product_tags' => esc_html__( 'Product Tags', 'shopbuilder' ),
190 + 'specific_products' => esc_html__( 'Selected Products', 'shopbuilder' ),
191 + ];
192 + foreach ( $builder_page_types as $key => $value ) {
193 + ?>
194 + <option <?php echo esc_attr( $key === $product_page_for ? 'selected="selected"' : '' ); ?> value="<?php echo esc_attr( $key ); ?>"> <?php echo esc_html( $value ); ?> </option>
195 + <?php } ?>
196 + </select>
197 + </div>
198 +
199 + <?php if ( ! rtsb()->has_pro() ) { ?>
200 + <div class="rtsb-product-page-for rtsb-tb-field-wraper" style="display:none;" >
201 + <label for="product_page_for"> </label>
202 + <span class="elementor-pro-notice"><a target="_blank" href="<?php echo esc_url( rtsb()->pro_version_link() ); ?>">Upgrade to PRO</a> to unlock Product Categories, Product Tags, Selected Products</span>
203 + </div>
204 + <?php } ?>
205 +
206 + <!-- Product Page For Categories -->
207 + <div class="rtsb-categories-page-field rtsb-product-page-for-the-categories rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;">
157 208 <?php
158 - $default_items = '';
159 - $product_id = get_post_meta( $post_id, BuilderFns::$product_template_meta, true );
160 - if ( $product_id ) {
161 - $default_items = '<option selected="selected" value="' . $product_id . '">' . get_the_title( $product_id ) . ' - ( ID ' . $product_id . ' )</option>';
209 + $default_items_link = '';
210 + $default_items = '';
211 + $categories_name = apply_filters( 'rtsb/template/builder/selected/categories', [], $post_id, $template_type );
212 + if ( ! empty( $categories_name ) && is_array( $categories_name ) ) {
213 + foreach ( $categories_name as $c_name ) {
214 + $cat = get_term_by( 'slug', $c_name, 'product_cat' );
215 + $title_cat = $cat->name;
216 + $link = get_term_link( $cat );
217 + if ( ! is_wp_error( $link ) ) {
218 + $default_items_link .= '<a target="_blank" href="' . get_term_link( $cat ) . '">' . $title_cat . '</a>';
219 + }
220 + $default_items .= '<option selected="selected" value="' . $c_name . '">' . $title_cat . '</option>';
221 + }
162 222 }
163 223 ?>
164 - <label for="rtsb_product_page_preview"><?php esc_html_e( 'Select Product For Preview', 'shopbuilder' ); ?></label>
165 - <select class="rtsb-field" id="rtsb_product_page_preview" name="rtsb_product_page_preview">
224 + <label for="rtsb_page_for_the_products">
225 + <?php esc_html_e( 'Select Product Categories', 'shopbuilder' ); ?>
226 + <?php if ( ! rtsb()->has_pro() ) { ?>
227 + <div class="card-label">
228 + <span class="rtsb-btn-import pro-btn">
229 + <?php echo esc_html( 'PRO' ); ?>
230 + </span>
231 + </div>
232 + <?php } ?>
233 + </label>
234 + <select class="rtsb-field" id="rtsb_page_for_the_categories" name="rtsb_page_for_the_categories" multiple="multiple">
166 235 <?php Fns::print_html( $default_items, true ); ?>
167 236 </select>
168 - <p style="margin:0;"> This Product is only used for preview And Elementor edit page. </p>
237 + <p style="margin:0;">Select a Product Category to apply this template. You can select multiple Categories. Keep it blank to apply to all Categories.
238 + <?php
239 + if ( ! empty( $default_items_link ) ) {
240 + ?>
241 + <span style="display: flex; gap: 3px 7px; flex-wrap: wrap; margin-top: 10px;"> <?php Fns::print_html( 'View Category Archive Pages: ' . $default_items_link ); ?> </span>
242 + <?php
243 + }
244 + ?>
245 + </p>
169 246 </div>
170 247
171 - <div class="rtsb-product-page-field rtsb-page-for-the-products rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;">
248 + <?php if ( ! rtsb()->has_pro() ) { ?>
249 + <div class="rtsb-categories-page-field rtsb-product-page-for-the-categories rtsb-tb-field-wraper" style="display:none;">
250 + <label for="product_page_for"> </label>
251 + <span class="elementor-pro-notice"><a target="_blank" href="<?php echo esc_url( rtsb()->pro_version_link() ); ?>">Upgrade to PRO</a> to unlock Categories Base Prodcut Page.</span>
252 + </div>
253 + <?php } ?>
254 +
255 + <!-- Product Page for Selected Product Tags-->
256 + <div class="rtsb-product-tags-page-field rtsb-product-page-for-the-tags rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;">
172 257 <?php
173 258 $default_items_link = '';
174 259 $default_items = '';
175 - $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id );
176 - if ( ! empty( $product_ids ) && is_array( $product_ids ) ) {
177 - foreach ( $product_ids as $p_id ) {
178 - $title = get_the_title( $p_id );
179 - $default_items_link .= '<a target="_blank" href="' . get_the_permalink( $p_id ) . '">' . $title . '</a>';
180 - $default_items .= '<option selected="selected" value="' . $p_id . '">' . $title . ' - ( ID ' . $p_id . ' )</option>';
260 + $tags_name = apply_filters( 'rtsb/template/builder/selected/tags', [], $post_id, $template_type );
261 + if ( ! empty( $tags_name ) && is_array( $tags_name ) ) {
262 + foreach ( $tags_name as $tg_name ) {
263 + $tag = get_term_by( 'slug', $tg_name, 'product_tag' );
264 + $title_tag = $tag->name;
265 + $link = get_term_link( $tag );
266 + if ( ! is_wp_error( $link ) ) {
267 + $default_items_link .= '<a target="_blank" href="' . get_term_link( $tag ) . '">' . $title_tag . '</a>';
268 + }
269 + $default_items .= '<option selected="selected" value="' . $tg_name . '">' . $title_tag . '</option>';
181 270 }
182 271 }
183 272 ?>
184 - <label for="rtsb_page_for_the_products "><?php esc_html_e( 'Layout For the Products ', 'shopbuilder' ); ?>
273 + <label for="rtsb_page_for_the_products_tags">
274 + <?php esc_html_e( 'Select Product Tags', 'shopbuilder' ); ?>
185 275 <?php if ( ! rtsb()->has_pro() ) { ?>
186 276 <div class="card-label">
187 277 <span class="rtsb-btn-import pro-btn">
188 278 <?php echo esc_html( 'PRO' ); ?>
@@ -189,34 +279,38 @@
189 279 </span>
190 280 </div>
191 281 <?php } ?>
192 282 </label>
193 - <select class="rtsb-field" id="rtsb_page_for_the_products" name="rtsb_page_for_the_products" multiple="multiple">
283 + <select class="rtsb-field" id="rtsb_page_for_the_products_tags" name="rtsb_page_for_the_products_tags" multiple="multiple">
194 284 <?php Fns::print_html( $default_items, true ); ?>
195 285 </select>
196 - <p style="margin:0;"> The Products Display in this layout. <span style="display:inline-flex; gap :10px"> <?php Fns::print_html( ! empty( $default_items_link ) ? 'Visit: ' . $default_items_link : '' ); ?> </span>
286 + <p style="margin:0;">Select a Product Tags to apply this template. You can select multiple Tags. Keep it blank to apply to All.
287 + <?php
288 + if ( ! empty( $default_items_link ) ) {
289 + ?>
290 + <span style="display: flex; gap: 3px 7px; flex-wrap: wrap; margin-top: 10px;"> <?php Fns::print_html( 'View Tags Archive Pages: ' . $default_items_link ); ?> </span>
291 + <?php
292 + }
293 + ?>
197 294 </p>
198 295 </div>
199 296
200 - <div class="rtsb-categories-page-field rtsb-page-for-the-categories rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;">
297 +
298 + <!-- Product Page for Selected Product -->
299 + <div class="rtsb-page-for-the-products rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;">
201 300 <?php
202 301 $default_items_link = '';
203 302 $default_items = '';
204 - $categories_name = apply_filters( 'rtsb/archive/page/builder/selected/categories', [], $post_id );
205 - if ( ! empty( $categories_name ) && is_array( $categories_name ) ) {
206 - foreach ( $categories_name as $c_name ) {
207 - $cat = get_term_by( 'slug', $c_name, 'product_cat' );
208 - $title = $cat->name;
209 - $link = get_term_link( $cat );
210 - if ( ! is_wp_error( $link ) ) {
211 - $default_items_link .= '<a target="_blank" href="' . get_term_link( $cat ) . '">' . $title . '</a>';
212 - }
213 - $default_items .= '<option selected="selected" value="' . $c_name . '">' . $title . '</option>';
303 + $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id );
304 + if ( ! empty( $product_ids ) && is_array( $product_ids ) ) {
305 + foreach ( $product_ids as $p_id ) {
306 + $p_title = get_the_title( $p_id );
307 + $default_items_link .= '<a target="_blank" href="' . get_the_permalink( $p_id ) . '">' . $p_title . '</a>';
308 + $default_items .= '<option selected="selected" value="' . $p_id . '">' . $p_title . ' - ( ID ' . $p_id . ' )</option>';
214 309 }
215 310 }
216 311 ?>
217 - <label for="rtsb_page_for_the_products">
218 - <?php esc_html_e( 'Layout For the Products categories', 'shopbuilder' ); ?>
312 + <label for="rtsb_page_for_the_products "><?php esc_html_e( 'Select Products ', 'shopbuilder' ); ?>
219 313 <?php if ( ! rtsb()->has_pro() ) { ?>
220 314 <div class="card-label">
221 315 <span class="rtsb-btn-import pro-btn">
222 316 <?php echo esc_html( 'PRO' ); ?>
@@ -223,15 +317,41 @@
223 317 </span>
224 318 </div>
225 319 <?php } ?>
226 320 </label>
227 - <select class="rtsb-field" id="rtsb_page_for_the_categories" name="rtsb_page_for_the_categories" multiple="multiple">
321 + <select class="rtsb-field" id="rtsb_page_for_the_products" name="rtsb_page_for_the_products" multiple="multiple">
228 322 <?php Fns::print_html( $default_items, true ); ?>
229 323 </select>
230 - <p style="margin:0;"> The Product Categories Display in this layout. <span style="display:inline-flex; gap :10px"> <?php Fns::print_html( ! empty( $default_items_link ) ? 'Visit: ' . $default_items_link : '' ); ?> </span>
324 + <p style="margin:0;">Select a Product to apply this template. You can select multiple Products. Keep it blank to apply to all Products.
325 + <?php
326 + if ( ! empty( $default_items_link ) ) {
327 + ?>
328 + <span style="display: flex; gap: 3px 7px; flex-wrap: wrap; margin-top: 10px;"> <?php Fns::print_html( 'View Product Pages: ' . $default_items_link ); ?> </span>
329 + <?php
330 + }
331 + ?>
231 332 </p>
232 333 </div>
233 334
335 + <div class="rtsb-product-page-preview-field rtsb-tb-field-wraper" style="display:none;">
336 + <?php
337 + $default_items = '';
338 + $product_id = get_post_meta( $post_id, BuilderFns::$product_template_meta, true );
339 + if ( $product_id && get_post_status( $product_id ) ) {
340 + $default_items = '<option selected="selected" value="' . $product_id . '">' . get_the_title( $product_id ) . ' - ( ID ' . $product_id . ' )</option>';
341 + }
342 + if ( $product_id && ! get_post_status( $product_id ) ) {
343 + delete_post_meta( $post_id, BuilderFns::$product_template_meta );
344 + }
345 + ?>
346 + <label for="rtsb_product_page_preview"><?php esc_html_e( 'Select Preview Product', 'shopbuilder' ); ?></label>
347 + <select class="rtsb-field" id="rtsb_product_page_preview" name="rtsb_product_page_preview">
348 + <?php Fns::print_html( $default_items, true ); ?>
349 + </select>
350 + <p style="margin:0;">Select a Product for preview and Elementor editing purposes only.</p>
351 + </div>
352 +
353 +
234 354 <div class="rtsb-template-edit-with rtsb-tb-field-wraper">
235 355 <label for="rtsb_tb_template_edit_with"><?php esc_html_e( 'Select Editor Type', 'shopbuilder' ); ?></label>
236 356 <select class="rtsb-field" id="rtsb_tb_template_edit_with" name="rtsb_tb_template_edit_with"
237 357 required>
@@ -243,15 +363,27 @@
243 363 <div class="rtsb-template-setdefaults rtsb-tb-field-wraper">
244 364 <label for="default_template"> <?php esc_html_e( 'Set as Active Template', 'shopbuilder' ); ?></label>
245 365 <?php
246 366 if ( $post_id && 'product' === $template_type ) {
247 - $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id );
248 - $set_default = BuilderFns::get_specific_product_as_default( $post_id );
249 - if ( ! empty( $product_ids ) && $set_default ) {
250 - $template_default = $post_id;
367 + if ( 'specific_products' === $product_page_for ) {
368 + $set_default = BuilderFns::get_specific_product_as_default( $post_id );
369 + if ( $set_default ) {
370 + $template_default = $post_id;
371 + }
372 + } else {
373 + $set_default_option_name = '';
374 + if ( 'product_cats' === $product_page_for ) {
375 + $set_default_option_name = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id );
376 + } elseif ( 'product_tags' === $product_page_for ) {
377 + $set_default_option_name = BuilderFns::option_name_product_page_specific_tag_set_default( $post_id );
378 + }
379 + $default_id = ! empty( $set_default_option_name ) && TemplateSettings::instance()->get_option( $set_default_option_name );
380 + if ( $default_id ) {
381 + $template_default = $post_id;
382 + }
251 383 }
252 384 } elseif ( $post_id && 'archive' === $template_type ) {
253 - $categories_name = apply_filters( 'rtsb/archive/page/builder/selected/categories', [], $post_id );
385 + $categories_name = apply_filters( 'rtsb/template/builder/selected/categories', [], $post_id, $template_type );
254 386 $set_default = BuilderFns::get_specific_category_as_default( $post_id );
255 387 if ( ! empty( $categories_name ) && $set_default ) {
256 388 $template_default = $post_id;
257 389 }
@@ -258,17 +390,16 @@
258 390 }
259 391
260 392 ?>
261 393 <span class="rtsb-switch-wrapper"
262 - title="<?php esc_html_e( 'Only publish post can set default ', 'shopbuilder' ); ?>">
394 + title="<?php esc_html_e( 'Switch on to set as active template', 'shopbuilder' ); ?>">
263 395 <label class="rtsb-switch">
264 396 <input class="rtsb_set_default rtsb-field"
265 397 type="checkbox"
266 398 id="default_template"
267 - class="rtsb-field"
268 399 name="default_template"
269 400 value="default_template"
270 - <?php echo esc_attr( ( $post_id && absint( $post_id ) === absint( $template_default ) ) ? 'checked' : '' ); ?>
401 + <?php echo esc_attr( ( $post_id && ( absint( $post_id ) === absint( $template_default ) ) ) ? 'checked' : '' ); ?>
271 402 >
272 403 <span class="rtsb-slider rtsb-round ">
273 404 <span class="rtsb-loader"></span>
274 405 </span>
@@ -488,9 +619,9 @@
488 619 'content' => esc_html__( 'Empty string Not allowed...', 'shopbuilder' ),
489 620 ];
490 621 wp_send_json( $return );
491 622 }
492 - $query = $wpdb->prepare(
623 + $query = $wpdb->prepare(
493 624 "SELECT ID, post_title
494 625 FROM $wpdb->posts
495 626 WHERE post_type = 'product'
496 627 AND post_status = 'publish'
@@ -498,20 +629,20 @@
498 629 LIMIT %d",
499 630 '%' . $search . '%',
500 631 10
501 632 );
502 -
503 - $_product = wp_cache_get( md5( $query ), 'rtsb-product-query' );
633 + $cache_key = md5( $query );
634 + $_product = wp_cache_get( $cache_key, 'shopbuilder' );
504 635 if ( false === $_product ) {
505 636 $_product = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared
506 - wp_cache_set( md5( $query ), $_product, 'rtsb-product-query' );
637 + wp_cache_set( $cache_key, $_product, 'shopbuilder' );
638 + Cache::set_data_cache_key( $cache_key );
507 639 }
508 -
509 640 $product_list = [];
510 641 foreach ( $_product as $product ) {
511 642 $product_list['items'][] = [
512 643 'id' => $product->ID,
513 - 'text' => $product->post_title . ' - ( ID ' . $product->ID . ' )',
644 + 'text' => html_entity_decode( $product->post_title, ENT_QUOTES | ENT_HTML5 ) . ' - (ID#' . $product->ID . ')',
514 645 ];
515 646 }
516 647
517 648 wp_send_json_success( $product_list );
@@ -522,9 +653,9 @@
522 653 * Popups For Create Template
523 654 *
524 655 * @return void
525 656 */
526 - public function category_search() {
657 + public function term_search() {
527 658
528 659 if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
529 660 $return = [
530 661 'success' => false,
@@ -540,17 +671,24 @@
540 671 ];
541 672 wp_send_json( $return );
542 673 }
543 674
544 - $search = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
545 - $args = [
546 - 'taxonomy' => [ 'product_cat' ], // taxonomy name
675 + $search = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
676 + $taxonomy = isset( $_REQUEST['taxonomy'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['taxonomy'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
677 + if ( ! $taxonomy ) {
678 + $return = [
679 + 'success' => false,
680 + 'content' => esc_html__( 'Invalid taxonomy', 'shopbuilder' ),
681 + ];
682 + wp_send_json( $return );
683 + }
684 + $args = [
685 + 'taxonomy' => [ $taxonomy ], // taxonomy name.
547 686 'orderby' => 'name',
548 687 'order' => 'ASC',
549 688 'hide_empty' => false,
550 689 'name__like' => $search,
551 690 ];
552 -
553 691 $terms = get_terms( $args );
554 692 $count = count( $terms );
555 693 $term_list = [];
556 694 if ( $count > 0 ) {
@@ -556,9 +694,9 @@
556 694 if ( $count > 0 ) {
557 695 foreach ( $terms as $term ) {
558 696 $term_list['items'][] = [
559 697 'id' => $term->slug,
560 - 'text' => $term->name,
698 + 'text' => html_entity_decode( $term->name, ENT_QUOTES | ENT_HTML5 ),
561 699 ];
562 700 }
563 701 }
564 702 wp_send_json_success( $term_list );