PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.6
ShopBuilder – WooCommerce Builder For Elementor v3.2.6
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 +238 -137 2.1.123.2.6 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
@@ -35,9 +37,9 @@
35 37 * Popups For Create Template
36 38 *
37 39 * @return void
38 40 */
39 - public function response() {
41 + public function response() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
40 42 $title = '<h2>' . esc_html__( 'Template Settings', 'shopbuilder' ) . '</h2>';
41 43 if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
42 44 $return = [
43 45 'success' => false,
@@ -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,21 +73,23 @@
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, WordPress.PHP.YodaConditions.NotYoda
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 - $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : null;
76 - $layout_id = isset( $_POST['layout_id'] ) ? absint( $_POST['layout_id'] ) : null;
87 + $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : null;
88 + $layout_id = isset( $_REQUEST['layout_id'] ) ? absint( $_REQUEST['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,15 +95,18 @@
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 - // TODO:: This Condition Will remove after release Gutenberg Addons.
108 + /* This Condition Will remove after release Gutenberg Addons. */
93 109 if ( 'gutenberg' == $edit_by ) {
94 110 $action = 'elementor';
95 111 $edit_by = 'elementor';
96 112 }
@@ -108,20 +124,8 @@
108 124 );
109 125
110 126 $_rtsb_import_id = get_post_meta( $post_id, '_rtsb_import_id', true );
111 127 }
112 -
113 - $status = $_REQUEST['status'] ?? '';
114 - $post_args = [ 'timeout' => 120 ];
115 - $post_args['body'] = [
116 - 'status' => $status,
117 - ];
118 - $layoutRequest = wp_remote_post( rtsb()->BASE_API, $post_args );
119 - $layoutData = [];
120 - if ( ! is_wp_error( $layoutRequest ) && ! empty( $layoutRequest['body'] ) ) {
121 - $layoutData = json_decode( $layoutRequest['body'], true );
122 - }
123 -
124 128 ob_start();
125 129
126 130 ?>
127 131 <form action="<?php echo esc_url( admin_url( 'edit.php?post_type=rtsb_builder' ) ); ?>" autocomplete="off" data-imported-id="<?php echo esc_attr( $_rtsb_import_id ); ?>">
@@ -137,10 +141,9 @@
137 141 placeholder="<?php esc_attr_e( 'Enter Template Name', 'shopbuilder' ); ?>"
138 142 value="<?php echo esc_attr( $tmp_title ); ?>"
139 143 autocomplete="off"
140 144 >
141 - <span class="message"
142 - style="display: none; color:red"><?php esc_html_e( 'This field is required', 'shopbuilder' ); ?></span>
145 + <span class="message" style="display: none; color:red"><?php esc_html_e( 'This field is required', 'shopbuilder' ); ?></span>
143 146 </div>
144 147 <div class="rtsb-template-type rtsb-tb-field-wraper">
145 148 <label for="rtsb_tb_template_type"><?php esc_html_e( 'Select Template Type', 'shopbuilder' ); ?></label>
146 149 <select class="rtsb-field" id="rtsb_tb_template_type" name="rtsb_tb_template_type">
@@ -152,37 +155,111 @@
152 155 <?php } ?>
153 156 </select>
154 157 </div>
155 158
156 - <div class="rtsb-product-page-field rtsb-tb-field-wraper" style="display:none;">
159 + <div class="rtsb-product-page-for rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;" >
160 + <label for="product_page_for">
161 + <?php esc_html_e( 'Product Template For', 'shopbuilder' ); ?>
162 + <?php if ( ! rtsb()->has_pro() ) { ?>
163 + <div class="card-label">
164 + <span class="rtsb-btn-import pro-btn">
165 + <?php echo esc_html( 'PRO' ); ?>
166 + </span>
167 + </div>
168 + <?php } ?>
169 + </label>
170 +
171 + <select class="rtsb-field" id="product_page_for" name="product_page_for">
172 + <?php
173 + $builder_page_types = [
174 + 'all_products' => esc_html__( 'All Products', 'shopbuilder' ),
175 + 'product_cats' => esc_html__( 'Product Categories', 'shopbuilder' ),
176 + 'product_tags' => esc_html__( 'Product Tags', 'shopbuilder' ),
177 + 'specific_products' => esc_html__( 'Selected Products', 'shopbuilder' ),
178 + ];
179 + foreach ( $builder_page_types as $key => $value ) {
180 + ?>
181 + <option <?php echo esc_attr( $key === $product_page_for ? 'selected="selected"' : '' ); ?> value="<?php echo esc_attr( $key ); ?>"> <?php echo esc_html( $value ); ?> </option>
182 + <?php } ?>
183 + </select>
184 + </div>
185 +
186 + <?php if ( ! rtsb()->has_pro() ) { ?>
187 + <div class="rtsb-product-page-for rtsb-tb-field-wraper" style="display:none;" >
188 + <label for="product_page_for"> </label>
189 + <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>
190 + </div>
191 + <?php } ?>
192 +
193 + <!-- Product Page For Categories -->
194 + <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 195 <?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>';
196 + $default_items_link = '';
197 + $default_items = '';
198 + $categories_name = apply_filters( 'rtsb/template/builder/selected/categories', [], $post_id, $template_type );
199 + if ( ! empty( $categories_name ) && is_array( $categories_name ) ) {
200 + foreach ( $categories_name as $c_name ) {
201 + $cat = get_term_by( 'slug', $c_name, 'product_cat' );
202 + $title_cat = $cat->name;
203 + $link = get_term_link( $cat );
204 + if ( ! is_wp_error( $link ) ) {
205 + $default_items_link .= '<a target="_blank" href="' . get_term_link( $cat ) . '">' . $title_cat . '</a>';
206 + }
207 + $default_items .= '<option selected="selected" value="' . $c_name . '">' . $title_cat . '</option>';
208 + }
162 209 }
163 210 ?>
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">
211 + <label for="rtsb_page_for_the_products">
212 + <?php esc_html_e( 'Select Product Categories', 'shopbuilder' ); ?>
213 + <?php if ( ! rtsb()->has_pro() ) { ?>
214 + <div class="card-label">
215 + <span class="rtsb-btn-import pro-btn">
216 + <?php echo esc_html( 'PRO' ); ?>
217 + </span>
218 + </div>
219 + <?php } ?>
220 + </label>
221 + <select class="rtsb-field" id="rtsb_page_for_the_categories" name="rtsb_page_for_the_categories" multiple="multiple">
166 222 <?php Fns::print_html( $default_items, true ); ?>
167 223 </select>
168 - <p style="margin:0;"> This Product is only used for preview And Elementor edit page. </p>
224 + <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.
225 + <?php
226 + if ( ! empty( $default_items_link ) ) {
227 + ?>
228 + <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>
229 + <?php
230 + }
231 + ?>
232 + </p>
169 233 </div>
170 234
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;">
235 + <?php if ( ! rtsb()->has_pro() ) { ?>
236 + <div class="rtsb-categories-page-field rtsb-product-page-for-the-categories rtsb-tb-field-wraper" style="display:none;">
237 + <label for="product_page_for"> </label>
238 + <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>
239 + </div>
240 + <?php } ?>
241 +
242 + <!-- Product Page for Selected Product Tags-->
243 + <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 244 <?php
173 245 $default_items_link = '';
174 246 $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>';
247 + $tags_name = apply_filters( 'rtsb/template/builder/selected/tags', [], $post_id, $template_type );
248 + if ( ! empty( $tags_name ) && is_array( $tags_name ) ) {
249 + foreach ( $tags_name as $tg_name ) {
250 + $tag = get_term_by( 'slug', $tg_name, 'product_tag' );
251 + $title_tag = $tag->name;
252 + $link = get_term_link( $tag );
253 + if ( ! is_wp_error( $link ) ) {
254 + $default_items_link .= '<a target="_blank" href="' . get_term_link( $tag ) . '">' . $title_tag . '</a>';
255 + }
256 + $default_items .= '<option selected="selected" value="' . $tg_name . '">' . $title_tag . '</option>';
181 257 }
182 258 }
183 259 ?>
184 - <label for="rtsb_page_for_the_products "><?php esc_html_e( 'Layout For the Products ', 'shopbuilder' ); ?>
260 + <label for="rtsb_page_for_the_products_tags">
261 + <?php esc_html_e( 'Select Product Tags', 'shopbuilder' ); ?>
185 262 <?php if ( ! rtsb()->has_pro() ) { ?>
186 263 <div class="card-label">
187 264 <span class="rtsb-btn-import pro-btn">
188 265 <?php echo esc_html( 'PRO' ); ?>
@@ -189,34 +266,38 @@
189 266 </span>
190 267 </div>
191 268 <?php } ?>
192 269 </label>
193 - <select class="rtsb-field" id="rtsb_page_for_the_products" name="rtsb_page_for_the_products" multiple="multiple">
270 + <select class="rtsb-field" id="rtsb_page_for_the_products_tags" name="rtsb_page_for_the_products_tags" multiple="multiple">
194 271 <?php Fns::print_html( $default_items, true ); ?>
195 272 </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>
273 + <p style="margin:0;">Select a Product Tags to apply this template. You can select multiple Tags. Keep it blank to apply to All.
274 + <?php
275 + if ( ! empty( $default_items_link ) ) {
276 + ?>
277 + <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>
278 + <?php
279 + }
280 + ?>
197 281 </p>
198 282 </div>
199 283
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;">
284 +
285 + <!-- Product Page for Selected Product -->
286 + <div class="rtsb-page-for-the-products rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;">
201 287 <?php
202 288 $default_items_link = '';
203 289 $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>';
290 + $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id );
291 + if ( ! empty( $product_ids ) && is_array( $product_ids ) ) {
292 + foreach ( $product_ids as $p_id ) {
293 + $p_title = get_the_title( $p_id );
294 + $default_items_link .= '<a target="_blank" href="' . get_the_permalink( $p_id ) . '">' . $p_title . '</a>';
295 + $default_items .= '<option selected="selected" value="' . $p_id . '">' . $p_title . ' - ( ID ' . $p_id . ' )</option>';
214 296 }
215 297 }
216 298 ?>
217 - <label for="rtsb_page_for_the_products">
218 - <?php esc_html_e( 'Layout For the Products categories', 'shopbuilder' ); ?>
299 + <label for="rtsb_page_for_the_products "><?php esc_html_e( 'Select Products ', 'shopbuilder' ); ?>
219 300 <?php if ( ! rtsb()->has_pro() ) { ?>
220 301 <div class="card-label">
221 302 <span class="rtsb-btn-import pro-btn">
222 303 <?php echo esc_html( 'PRO' ); ?>
@@ -223,15 +304,41 @@
223 304 </span>
224 305 </div>
225 306 <?php } ?>
226 307 </label>
227 - <select class="rtsb-field" id="rtsb_page_for_the_categories" name="rtsb_page_for_the_categories" multiple="multiple">
308 + <select class="rtsb-field" id="rtsb_page_for_the_products" name="rtsb_page_for_the_products" multiple="multiple">
228 309 <?php Fns::print_html( $default_items, true ); ?>
229 310 </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>
311 + <p style="margin:0;">Select a Product to apply this template. You can select multiple Products. Keep it blank to apply to all Products.
312 + <?php
313 + if ( ! empty( $default_items_link ) ) {
314 + ?>
315 + <span style="display: flex; gap: 3px 7px; flex-wrap: wrap; margin-top: 10px;"> <?php Fns::print_html( 'View Product Pages: ' . $default_items_link ); ?> </span>
316 + <?php
317 + }
318 + ?>
231 319 </p>
232 320 </div>
233 321
322 + <div class="rtsb-product-page-preview-field rtsb-tb-field-wraper" style="display:none;">
323 + <?php
324 + $default_items = '';
325 + $product_id = get_post_meta( $post_id, BuilderFns::$product_template_meta, true );
326 + if ( $product_id && get_post_status( $product_id ) ) {
327 + $default_items = '<option selected="selected" value="' . $product_id . '">' . get_the_title( $product_id ) . ' - ( ID ' . $product_id . ' )</option>';
328 + }
329 + if ( $product_id && ! get_post_status( $product_id ) ) {
330 + delete_post_meta( $post_id, BuilderFns::$product_template_meta );
331 + }
332 + ?>
333 + <label for="rtsb_product_page_preview"><?php esc_html_e( 'Select Preview Product', 'shopbuilder' ); ?></label>
334 + <select class="rtsb-field" id="rtsb_product_page_preview" name="rtsb_product_page_preview">
335 + <?php Fns::print_html( $default_items, true ); ?>
336 + </select>
337 + <p style="margin:0;">Select a Product for preview and Elementor editing purposes only.</p>
338 + </div>
339 +
340 +
234 341 <div class="rtsb-template-edit-with rtsb-tb-field-wraper">
235 342 <label for="rtsb_tb_template_edit_with"><?php esc_html_e( 'Select Editor Type', 'shopbuilder' ); ?></label>
236 343 <select class="rtsb-field" id="rtsb_tb_template_edit_with" name="rtsb_tb_template_edit_with"
237 344 required>
@@ -243,32 +350,53 @@
243 350 <div class="rtsb-template-setdefaults rtsb-tb-field-wraper">
244 351 <label for="default_template"> <?php esc_html_e( 'Set as Active Template', 'shopbuilder' ); ?></label>
245 352 <?php
246 353 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;
354 + if ( 'specific_products' === $product_page_for ) {
355 + $set_default = BuilderFns::get_specific_product_as_default( $post_id );
356 + if ( $set_default ) {
357 + $template_default = $post_id;
358 + }
359 + if ( ! $set_default && $template_default === $post_id ) {
360 + $template_default = '';
361 + }
362 + } else {
363 + $set_default_option_name = '';
364 + if ( 'product_cats' === $product_page_for ) {
365 + $set_default_option_name = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id );
366 + } elseif ( 'product_tags' === $product_page_for ) {
367 + $set_default_option_name = BuilderFns::option_name_product_page_specific_tag_set_default( $post_id );
368 + }
369 + $default_id = ! empty( $set_default_option_name ) && TemplateSettings::instance()->get_option( $set_default_option_name );
370 + if ( $default_id ) {
371 + $template_default = $post_id;
372 + }
251 373 }
252 374 } elseif ( $post_id && 'archive' === $template_type ) {
253 - $categories_name = apply_filters( 'rtsb/archive/page/builder/selected/categories', [], $post_id );
375 + $categories_name = apply_filters( 'rtsb/template/builder/selected/categories', [], $post_id, $template_type );
254 376 $set_default = BuilderFns::get_specific_category_as_default( $post_id );
255 377 if ( ! empty( $categories_name ) && $set_default ) {
256 378 $template_default = $post_id;
379 + } else {
380 + $option_name = BuilderFns::option_name( $template_type );
381 + $is_set_default = TemplateSettings::instance()->get_option( $option_name );
382 + $set_default = $is_set_default;
257 383 }
384 + if ( ! $set_default && $template_default === $post_id ) {
385 + $template_default = '';
386 + }
258 387 }
259 388
260 389 ?>
261 390 <span class="rtsb-switch-wrapper"
262 - title="<?php esc_html_e( 'Only publish post can set default ', 'shopbuilder' ); ?>">
391 + title="<?php esc_html_e( 'Switch on to set as active template', 'shopbuilder' ); ?>">
263 392 <label class="rtsb-switch">
264 393 <input class="rtsb_set_default rtsb-field"
265 394 type="checkbox"
266 395 id="default_template"
267 - class="rtsb-field"
268 396 name="default_template"
269 397 value="default_template"
270 - <?php echo esc_attr( ( $post_id && absint( $post_id ) === absint( $template_default ) ) ? 'checked' : '' ); ?>
398 + <?php echo esc_attr( ( $post_id && ( absint( $post_id ) === absint( $template_default ) ) ) ? 'checked' : '' ); ?>
271 399 >
272 400 <span class="rtsb-slider rtsb-round ">
273 401 <span class="rtsb-loader"></span>
274 402 </span>
@@ -275,32 +403,29 @@
275 403 </label>
276 404 </span>
277 405 </div>
278 406 <!-- TODO: Moday Layout -->
279 - <?php if ( ! $post_id ) { ?>
280 - <div class="set-default-layout-wrapper rtsb-tb-field-wraper">
281 - <label>
282 - <?php esc_html_e( 'Pre-built Templates ', 'shopbuilder' ); ?>
283 - <span id="modallabelPrefix"></span>
284 - </label>
285 - <div class="set-default-layout">
286 - <?php
287 - $default_item = [
288 - 'template_type' => 'default',
289 - 'image_url' => \Elementor\Utils::get_placeholder_image_src(),
290 - 'preview_link' => '',
291 - 'title' => __( 'Blank Template', 'shopbuilder' ),
292 - ];
293 -
294 - $this->get_modal_card_html( $default_item );
295 -
296 - if ( ! empty( $layoutData['layouts'] ) ) {
297 - foreach ( $layoutData['layouts'] as $item ) {
298 - $this->get_modal_card_html( $item );
299 - }
300 - }
301 - ?>
407 + <?php
408 + if ( ! $post_id ) {
409 + if ( defined( 'ELEMENTOR_PATH' ) && class_exists( '\Elementor\Utils' ) ) {
410 + $placeholderImageSrc = \Elementor\Utils::get_placeholder_image_src();
411 + } else {
412 + $placeholderImageSrc = '#';
413 + }
414 + ?>
415 + <div class="set-default-layout-wrapper rtsb-tb-field-wraper" style="opacity: 0" >
416 + <div style="display: flex; justify-content: space-between;">
417 + <label>
418 + <?php esc_html_e( 'Pre-built Templates ', 'shopbuilder' ); ?>
419 + <span id="modallabelPrefix"></span>
420 + </label>
421 + <div class="rtsb-tb-button-wrapper">
422 + <a class="btn" href="https://shopbuilderwp.com/themes/" target="_blank" style="opacity: 1; visibility: visible;">View Out Themes</a>
423 + </div>
302 424 </div>
425 + <div class="set-default-layout" data-has-pro="<?php echo esc_attr( rtsb()->has_pro() ); ?>" data-rest-url="<?php echo esc_url( rtsb()->BASE_API ); ?>" data-placeholder-image-src="<?php echo esc_url( $placeholderImageSrc ); ?>">
426 + <!-- Layout Will Add Via Ajax-->
427 + </div>
303 428 </div>
304 429 <?php } ?>
305 430 <input type="hidden" id="page_id" name="page_id" value="<?php echo esc_attr( $post_id ); ?>">
306 431 </div>
@@ -338,55 +463,20 @@
338 463 wp_send_json( $return );
339 464 wp_die();
340 465 }
341 466
342 - public function default_layout_template_html( $key, $is_checked, $builder, $value = [] ) {
343 - $layout_type = $key . ( $builder ? '_' . $builder : null );
344 - ?>
345 - <!-- Elementor -->
346 - <label class="layout-container type-<?php echo esc_attr( $key ); ?>"
347 - data-layout-type='<?php echo esc_attr( $layout_type ); ?>'>
348 - <input <?php echo esc_attr( $is_checked ); ?>
349 - class="rtsb-field" type="radio"
350 - value="<?php echo ! empty( $value['import_file'] ) ? esc_attr( $value['import_file'] ) : ''; ?>"
351 - name="import_default_layout"/>
352 -
353 - <span class="checkmark dashicons"></span>
354 - <div class="image-wrapper">
355 - <?php if ( ! empty( $value['image'] ) ) { ?>
356 - <img src="<?php echo esc_url( $value['image'] ); ?>" alt="">
357 - <?php } ?>
358 - </div>
359 - <?php if ( ! empty( $value['text_label'] ) ) { ?>
360 - <div class="image-label">
361 - <span class="label-text"><?php echo esc_html( $value['text_label'] ); ?></span>
362 - <?php if ( ! empty( $value['live_preview'] ) ) { ?>
363 - <a target="_blank" class="btn-live-preview" href="<?php echo esc_url( $value['live_preview'] ); ?>">
364 - <span class="dashicons dashicons-visibility"></span>
365 - <?php esc_html_e( 'Live Preview', 'shopbuilder' ); ?>
366 - </a>
367 - <?php } ?>
368 - </div>
369 - <?php } ?>
370 - </label>
371 - <?php
372 - }
373 -
374 467 /**
375 468 * Get Modal Card Markup.
376 469 *
377 - * @param $item
378 - * @param $checked
470 + * @param array $item Item.
379 471 *
380 472 * @return void
381 473 */
382 474 public function get_modal_card_html( $item ) {
383 -
384 475 ?>
385 476 <div class="layout-container rtsb-template-item type-<?php echo esc_attr( $item['template_type'] ); ?>"
386 477 data-layout-type='<?php echo esc_attr( $item['template_type'] ); ?>'>
387 478 <input class="rtsb-field" type="hidden" value="<?php echo esc_attr( $item['id'] ?? '' ); ?>" name="import_default_layout"/>
388 -
389 479 <div class="image-wrapper">
390 480 <?php if ( $item['image_url'] ) : ?>
391 481 <img src="<?php echo esc_url( $item['image_url'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>">
392 482 <?php endif; ?>
@@ -391,9 +481,10 @@
391 481 <img src="<?php echo esc_url( $item['image_url'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>">
392 482 <?php endif; ?>
393 483
394 484 <?php if ( 'default' != $item['template_type'] && ( ! rtsb()->has_pro() ) ) : ?>
395 - <div class="card-label">
485 + <div class="card-label lllllll">
486 + label
396 487 <span class="rtsb-btn-import <?php echo esc_attr( $item['status'] ?? 'free' ); ?>-btn">
397 488 <?php echo esc_html( $item['status'] ?? 'Free' ); ?>
398 489 </span>
399 490 </div>
@@ -411,9 +502,12 @@
411 502 <?php echo esc_html__( 'Preview', 'shopbuilder' ); ?>
412 503 </a>
413 504
414 505
415 - <?php if ( rtsb()->has_pro() || $item['status'] == 'free' ) : ?>
506 + <?php
507 + // phpcs:ignore WordPress.PHP.YodaConditions.NotYoda
508 + if ( rtsb()->has_pro() || $item['status'] == 'free' ) :
509 + ?>
416 510 <a class="rtsb-btn-import import-btn rtsb-import-layout">
417 511 <svg width="22" height="20" viewBox="0 0 22 20" fill="none" xmlns="http://www.w3.org/2000/svg">
418 512 <path d="M11 12.2295C10.9048 12.2296 10.8106 12.2113 10.7226 12.1757C10.6347 12.14 10.5547 12.0878 10.4874 12.0219C10.4201 11.956 10.3668 11.8778 10.3304 11.7917C10.294 11.7056 10.2753 11.6134 10.2754 11.5202L10.2754 0.912773C10.2754 0.72466 10.3517 0.544251 10.4876 0.411235C10.6235 0.278219 10.8078 0.203491 11 0.203491C11.1922 0.203491 11.3765 0.278219 11.5124 0.411235C11.6483 0.544251 11.7246 0.72466 11.7246 0.912773L11.7246 11.5202C11.7246 11.7083 11.6483 11.8887 11.5124 12.0218C11.3765 12.1548 11.1922 12.2295 11 12.2295Z"
419 513 fill="white"></path>
@@ -488,9 +582,9 @@
488 582 'content' => esc_html__( 'Empty string Not allowed...', 'shopbuilder' ),
489 583 ];
490 584 wp_send_json( $return );
491 585 }
492 - $query = $wpdb->prepare(
586 + $query = $wpdb->prepare(
493 587 "SELECT ID, post_title
494 588 FROM $wpdb->posts
495 589 WHERE post_type = 'product'
496 590 AND post_status = 'publish'
@@ -498,20 +592,20 @@
498 592 LIMIT %d",
499 593 '%' . $search . '%',
500 594 10
501 595 );
502 -
503 - $_product = wp_cache_get( md5( $query ), 'rtsb-product-query' );
596 + $cache_key = md5( $query );
597 + $_product = wp_cache_get( $cache_key, 'shopbuilder' );
504 598 if ( false === $_product ) {
505 599 $_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' );
600 + wp_cache_set( $cache_key, $_product, 'shopbuilder' );
601 + Cache::set_data_cache_key( $cache_key );
507 602 }
508 -
509 603 $product_list = [];
510 604 foreach ( $_product as $product ) {
511 605 $product_list['items'][] = [
512 606 'id' => $product->ID,
513 - 'text' => $product->post_title . ' - ( ID ' . $product->ID . ' )',
607 + 'text' => html_entity_decode( $product->post_title, ENT_QUOTES | ENT_HTML5 ) . ' - (ID#' . $product->ID . ')',
514 608 ];
515 609 }
516 610
517 611 wp_send_json_success( $product_list );
@@ -522,9 +616,9 @@
522 616 * Popups For Create Template
523 617 *
524 618 * @return void
525 619 */
526 - public function category_search() {
620 + public function term_search() {
527 621
528 622 if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
529 623 $return = [
530 624 'success' => false,
@@ -540,17 +634,24 @@
540 634 ];
541 635 wp_send_json( $return );
542 636 }
543 637
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
638 + $search = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
639 + $taxonomy = isset( $_REQUEST['taxonomy'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['taxonomy'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
640 + if ( ! $taxonomy ) {
641 + $return = [
642 + 'success' => false,
643 + 'content' => esc_html__( 'Invalid taxonomy', 'shopbuilder' ),
644 + ];
645 + wp_send_json( $return );
646 + }
647 + $args = [
648 + 'taxonomy' => [ $taxonomy ], // taxonomy name.
547 649 'orderby' => 'name',
548 650 'order' => 'ASC',
549 651 'hide_empty' => false,
550 652 'name__like' => $search,
551 653 ];
552 -
553 654 $terms = get_terms( $args );
554 655 $count = count( $terms );
555 656 $term_list = [];
556 657 if ( $count > 0 ) {
@@ -556,9 +657,9 @@
556 657 if ( $count > 0 ) {
557 658 foreach ( $terms as $term ) {
558 659 $term_list['items'][] = [
559 660 'id' => $term->slug,
560 - 'text' => $term->name,
661 + 'text' => html_entity_decode( $term->name, ENT_QUOTES | ENT_HTML5 ),
561 662 ];
562 663 }
563 664 }
564 665 wp_send_json_success( $term_list );