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 +232 -132 2.1.153.2.6 View file →
@@ -5,8 +5,9 @@
5 5 use Elementor\Plugin;
6 6 use RadiusTheme\SB\Helpers\BuilderFns;
7 7 use RadiusTheme\SB\Helpers\Cache;
8 8 use RadiusTheme\SB\Helpers\Fns;
9 +use RadiusTheme\SB\Models\TemplateSettings;
9 10 use RadiusTheme\SB\Traits\SingletonTrait;
10 11 use Elementor\Core\Files\Uploads_Manager;
11 12
12 13 // Do not allow directly accessing this file.
@@ -28,9 +29,9 @@
28 29 */
29 30 private function __construct() {
30 31 add_action( 'wp_ajax_rtsb_builder_modal_template', [ $this, 'response' ] );
31 32 add_action( 'wp_ajax_rtsb_modal_product_search', [ $this, 'product_search' ] );
32 - add_action( 'wp_ajax_rtsb_modal_category_search', [ $this, 'category_search' ] );
33 + add_action( 'wp_ajax_rtsb_modal_term_search', [ $this, 'term_search' ] );
33 34 }
34 35
35 36 /**
36 37 * Popups For Create Template
@@ -36,9 +37,9 @@
36 37 * Popups For Create Template
37 38 *
38 39 * @return void
39 40 */
40 - public function response() {
41 + public function response() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
41 42 $title = '<h2>' . esc_html__( 'Template Settings', 'shopbuilder' ) . '</h2>';
42 43 if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
43 44 $return = [
44 45 'success' => false,
@@ -55,9 +56,18 @@
55 56 'content' => esc_html__( 'Permission Denied...', 'shopbuilder' ),
56 57 ];
57 58 wp_send_json( $return );
58 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 + ];
59 66
67 + wp_send_json( $return );
68 + }
69 +
60 70 add_filter( 'option_' . Uploads_Manager::UNFILTERED_FILE_UPLOADS_KEY, '__return_true' );
61 71 Plugin::$instance->files_manager->clear_cache();
62 72
63 73 // user capability check.
@@ -63,21 +73,23 @@
63 73 // user capability check.
64 74 $user = wp_get_current_user();
65 75 $allowed_roles = [ 'editor', 'administrator', 'author' ];
66 76
67 - if ( ! array_intersect( $allowed_roles, $user->roles ) ) {
77 + if ( ! array_intersect( $allowed_roles, Fns::get_current_user_roles() ) ) {
68 78 wp_die( esc_html__( 'You don\'t have permission to perform this action', 'shopbuilder' ) );
69 79 }
70 80
71 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
72 83 if ( ! is_user_logged_in() && $user->ID !== sanitize_text_field( $_REQUEST['user_id'] ) ) {
73 84 wp_die( esc_html__( 'You don\'t have proper authorization to perform this action', 'shopbuilder' ) );
74 85 }
75 86
76 - $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : null;
77 - $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;
78 89
79 90 $template_type = null;
91 + $product_page_for = 'all_products';
80 92 $template_default = null;
81 93 $url = '';
82 94 $tmp_title = '';
83 95 $_rtsb_import_id = '';
@@ -83,15 +95,18 @@
83 95 $_rtsb_import_id = '';
84 96 $edit_by = did_action( 'elementor/loaded' ) ? 'elementor' : 'elementor';
85 97 if ( $post_id ) {
86 98 $tmp_title = get_the_title( $post_id );
87 - $type = get_post_meta( $post_id, BuilderFns::template_type_meta_key() );
88 - $template_type = isset( $type[0] ) ? $type[0] : '';
89 - $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 );
90 102 $edit_by = Fns::page_edit_with( $post_id );
91 103 $action = 'edit';
104 + if ( rtsb()->has_pro() ) {
105 + $product_page_for = get_post_meta( $post_id, '_is_product_page_template_for', true );
106 + }
92 107
93 - // TODO:: This Condition Will remove after release Gutenberg Addons.
108 + /* This Condition Will remove after release Gutenberg Addons. */
94 109 if ( 'gutenberg' == $edit_by ) {
95 110 $action = 'elementor';
96 111 $edit_by = 'elementor';
97 112 }
@@ -109,20 +124,8 @@
109 124 );
110 125
111 126 $_rtsb_import_id = get_post_meta( $post_id, '_rtsb_import_id', true );
112 127 }
113 -
114 - $status = $_REQUEST['status'] ?? '';
115 - $post_args = [ 'timeout' => 120 ];
116 - $post_args['body'] = [
117 - 'status' => $status,
118 - ];
119 - $layoutRequest = wp_remote_post( rtsb()->BASE_API, $post_args );
120 - $layoutData = [];
121 - if ( ! is_wp_error( $layoutRequest ) && ! empty( $layoutRequest['body'] ) ) {
122 - $layoutData = json_decode( $layoutRequest['body'], true );
123 - }
124 -
125 128 ob_start();
126 129
127 130 ?>
128 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 ); ?>">
@@ -138,10 +141,9 @@
138 141 placeholder="<?php esc_attr_e( 'Enter Template Name', 'shopbuilder' ); ?>"
139 142 value="<?php echo esc_attr( $tmp_title ); ?>"
140 143 autocomplete="off"
141 144 >
142 - <span class="message"
143 - 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>
144 146 </div>
145 147 <div class="rtsb-template-type rtsb-tb-field-wraper">
146 148 <label for="rtsb_tb_template_type"><?php esc_html_e( 'Select Template Type', 'shopbuilder' ); ?></label>
147 149 <select class="rtsb-field" id="rtsb_tb_template_type" name="rtsb_tb_template_type">
@@ -153,37 +155,111 @@
153 155 <?php } ?>
154 156 </select>
155 157 </div>
156 158
157 - <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;">
158 195 <?php
159 - $default_items = '';
160 - $product_id = get_post_meta( $post_id, BuilderFns::$product_template_meta, true );
161 - if ( $product_id ) {
162 - $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 + }
163 209 }
164 210 ?>
165 - <label for="rtsb_product_page_preview"><?php esc_html_e( 'Select Product For Preview', 'shopbuilder' ); ?></label>
166 - <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">
167 222 <?php Fns::print_html( $default_items, true ); ?>
168 223 </select>
169 - <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>
170 233 </div>
171 234
172 - <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;">
173 244 <?php
174 245 $default_items_link = '';
175 246 $default_items = '';
176 - $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id );
177 - if ( ! empty( $product_ids ) && is_array( $product_ids ) ) {
178 - foreach ( $product_ids as $p_id ) {
179 - $title = get_the_title( $p_id );
180 - $default_items_link .= '<a target="_blank" href="' . get_the_permalink( $p_id ) . '">' . $title . '</a>';
181 - $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>';
182 257 }
183 258 }
184 259 ?>
185 - <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' ); ?>
186 262 <?php if ( ! rtsb()->has_pro() ) { ?>
187 263 <div class="card-label">
188 264 <span class="rtsb-btn-import pro-btn">
189 265 <?php echo esc_html( 'PRO' ); ?>
@@ -190,34 +266,38 @@
190 266 </span>
191 267 </div>
192 268 <?php } ?>
193 269 </label>
194 - <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">
195 271 <?php Fns::print_html( $default_items, true ); ?>
196 272 </select>
197 - <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 + ?>
198 281 </p>
199 282 </div>
200 283
201 - <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;">
202 287 <?php
203 288 $default_items_link = '';
204 289 $default_items = '';
205 - $categories_name = apply_filters( 'rtsb/archive/page/builder/selected/categories', [], $post_id );
206 - if ( ! empty( $categories_name ) && is_array( $categories_name ) ) {
207 - foreach ( $categories_name as $c_name ) {
208 - $cat = get_term_by( 'slug', $c_name, 'product_cat' );
209 - $title = $cat->name;
210 - $link = get_term_link( $cat );
211 - if ( ! is_wp_error( $link ) ) {
212 - $default_items_link .= '<a target="_blank" href="' . get_term_link( $cat ) . '">' . $title . '</a>';
213 - }
214 - $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>';
215 296 }
216 297 }
217 298 ?>
218 - <label for="rtsb_page_for_the_products">
219 - <?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' ); ?>
220 300 <?php if ( ! rtsb()->has_pro() ) { ?>
221 301 <div class="card-label">
222 302 <span class="rtsb-btn-import pro-btn">
223 303 <?php echo esc_html( 'PRO' ); ?>
@@ -224,15 +304,41 @@
224 304 </span>
225 305 </div>
226 306 <?php } ?>
227 307 </label>
228 - <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">
229 309 <?php Fns::print_html( $default_items, true ); ?>
230 310 </select>
231 - <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 + ?>
232 319 </p>
233 320 </div>
234 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 +
235 341 <div class="rtsb-template-edit-with rtsb-tb-field-wraper">
236 342 <label for="rtsb_tb_template_edit_with"><?php esc_html_e( 'Select Editor Type', 'shopbuilder' ); ?></label>
237 343 <select class="rtsb-field" id="rtsb_tb_template_edit_with" name="rtsb_tb_template_edit_with"
238 344 required>
@@ -244,32 +350,53 @@
244 350 <div class="rtsb-template-setdefaults rtsb-tb-field-wraper">
245 351 <label for="default_template"> <?php esc_html_e( 'Set as Active Template', 'shopbuilder' ); ?></label>
246 352 <?php
247 353 if ( $post_id && 'product' === $template_type ) {
248 - $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id );
249 - $set_default = BuilderFns::get_specific_product_as_default( $post_id );
250 - if ( ! empty( $product_ids ) && $set_default ) {
251 - $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 + }
252 373 }
253 374 } elseif ( $post_id && 'archive' === $template_type ) {
254 - $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 );
255 376 $set_default = BuilderFns::get_specific_category_as_default( $post_id );
256 377 if ( ! empty( $categories_name ) && $set_default ) {
257 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;
258 383 }
384 + if ( ! $set_default && $template_default === $post_id ) {
385 + $template_default = '';
386 + }
259 387 }
260 388
261 389 ?>
262 390 <span class="rtsb-switch-wrapper"
263 - 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' ); ?>">
264 392 <label class="rtsb-switch">
265 393 <input class="rtsb_set_default rtsb-field"
266 394 type="checkbox"
267 395 id="default_template"
268 - class="rtsb-field"
269 396 name="default_template"
270 397 value="default_template"
271 - <?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' : '' ); ?>
272 399 >
273 400 <span class="rtsb-slider rtsb-round ">
274 401 <span class="rtsb-loader"></span>
275 402 </span>
@@ -276,32 +403,29 @@
276 403 </label>
277 404 </span>
278 405 </div>
279 406 <!-- TODO: Moday Layout -->
280 - <?php if ( ! $post_id ) { ?>
281 - <div class="set-default-layout-wrapper rtsb-tb-field-wraper">
282 - <label>
283 - <?php esc_html_e( 'Pre-built Templates ', 'shopbuilder' ); ?>
284 - <span id="modallabelPrefix"></span>
285 - </label>
286 - <div class="set-default-layout">
287 - <?php
288 - $default_item = [
289 - 'template_type' => 'default',
290 - 'image_url' => \Elementor\Utils::get_placeholder_image_src(),
291 - 'preview_link' => '',
292 - 'title' => __( 'Blank Template', 'shopbuilder' ),
293 - ];
294 -
295 - $this->get_modal_card_html( $default_item );
296 -
297 - if ( ! empty( $layoutData['layouts'] ) ) {
298 - foreach ( $layoutData['layouts'] as $item ) {
299 - $this->get_modal_card_html( $item );
300 - }
301 - }
302 - ?>
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>
303 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>
304 428 </div>
305 429 <?php } ?>
306 430 <input type="hidden" id="page_id" name="page_id" value="<?php echo esc_attr( $post_id ); ?>">
307 431 </div>
@@ -339,55 +463,20 @@
339 463 wp_send_json( $return );
340 464 wp_die();
341 465 }
342 466
343 - public function default_layout_template_html( $key, $is_checked, $builder, $value = [] ) {
344 - $layout_type = $key . ( $builder ? '_' . $builder : null );
345 - ?>
346 - <!-- Elementor -->
347 - <label class="layout-container type-<?php echo esc_attr( $key ); ?>"
348 - data-layout-type='<?php echo esc_attr( $layout_type ); ?>'>
349 - <input <?php echo esc_attr( $is_checked ); ?>
350 - class="rtsb-field" type="radio"
351 - value="<?php echo ! empty( $value['import_file'] ) ? esc_attr( $value['import_file'] ) : ''; ?>"
352 - name="import_default_layout"/>
353 -
354 - <span class="checkmark dashicons"></span>
355 - <div class="image-wrapper">
356 - <?php if ( ! empty( $value['image'] ) ) { ?>
357 - <img src="<?php echo esc_url( $value['image'] ); ?>" alt="">
358 - <?php } ?>
359 - </div>
360 - <?php if ( ! empty( $value['text_label'] ) ) { ?>
361 - <div class="image-label">
362 - <span class="label-text"><?php echo esc_html( $value['text_label'] ); ?></span>
363 - <?php if ( ! empty( $value['live_preview'] ) ) { ?>
364 - <a target="_blank" class="btn-live-preview" href="<?php echo esc_url( $value['live_preview'] ); ?>">
365 - <span class="dashicons dashicons-visibility"></span>
366 - <?php esc_html_e( 'Live Preview', 'shopbuilder' ); ?>
367 - </a>
368 - <?php } ?>
369 - </div>
370 - <?php } ?>
371 - </label>
372 - <?php
373 - }
374 -
375 467 /**
376 468 * Get Modal Card Markup.
377 469 *
378 - * @param $item
379 - * @param $checked
470 + * @param array $item Item.
380 471 *
381 472 * @return void
382 473 */
383 474 public function get_modal_card_html( $item ) {
384 -
385 475 ?>
386 476 <div class="layout-container rtsb-template-item type-<?php echo esc_attr( $item['template_type'] ); ?>"
387 477 data-layout-type='<?php echo esc_attr( $item['template_type'] ); ?>'>
388 478 <input class="rtsb-field" type="hidden" value="<?php echo esc_attr( $item['id'] ?? '' ); ?>" name="import_default_layout"/>
389 -
390 479 <div class="image-wrapper">
391 480 <?php if ( $item['image_url'] ) : ?>
392 481 <img src="<?php echo esc_url( $item['image_url'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>">
393 482 <?php endif; ?>
@@ -392,9 +481,10 @@
392 481 <img src="<?php echo esc_url( $item['image_url'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>">
393 482 <?php endif; ?>
394 483
395 484 <?php if ( 'default' != $item['template_type'] && ( ! rtsb()->has_pro() ) ) : ?>
396 - <div class="card-label">
485 + <div class="card-label lllllll">
486 + label
397 487 <span class="rtsb-btn-import <?php echo esc_attr( $item['status'] ?? 'free' ); ?>-btn">
398 488 <?php echo esc_html( $item['status'] ?? 'Free' ); ?>
399 489 </span>
400 490 </div>
@@ -412,9 +502,12 @@
412 502 <?php echo esc_html__( 'Preview', 'shopbuilder' ); ?>
413 503 </a>
414 504
415 505
416 - <?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 + ?>
417 510 <a class="rtsb-btn-import import-btn rtsb-import-layout">
418 511 <svg width="22" height="20" viewBox="0 0 22 20" fill="none" xmlns="http://www.w3.org/2000/svg">
419 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"
420 513 fill="white"></path>
@@ -510,9 +603,9 @@
510 603 $product_list = [];
511 604 foreach ( $_product as $product ) {
512 605 $product_list['items'][] = [
513 606 'id' => $product->ID,
514 - 'text' => $product->post_title . ' - ( ID ' . $product->ID . ' )',
607 + 'text' => html_entity_decode( $product->post_title, ENT_QUOTES | ENT_HTML5 ) . ' - (ID#' . $product->ID . ')',
515 608 ];
516 609 }
517 610
518 611 wp_send_json_success( $product_list );
@@ -523,9 +616,9 @@
523 616 * Popups For Create Template
524 617 *
525 618 * @return void
526 619 */
527 - public function category_search() {
620 + public function term_search() {
528 621
529 622 if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
530 623 $return = [
531 624 'success' => false,
@@ -541,17 +634,24 @@
541 634 ];
542 635 wp_send_json( $return );
543 636 }
544 637
545 - $search = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
546 - $args = [
547 - '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.
548 649 'orderby' => 'name',
549 650 'order' => 'ASC',
550 651 'hide_empty' => false,
551 652 'name__like' => $search,
552 653 ];
553 -
554 654 $terms = get_terms( $args );
555 655 $count = count( $terms );
556 656 $term_list = [];
557 657 if ( $count > 0 ) {
@@ -557,9 +657,9 @@
557 657 if ( $count > 0 ) {
558 658 foreach ( $terms as $term ) {
559 659 $term_list['items'][] = [
560 660 'id' => $term->slug,
561 - 'text' => $term->name,
661 + 'text' => html_entity_decode( $term->name, ENT_QUOTES | ENT_HTML5 ),
562 662 ];
563 663 }
564 664 }
565 665 wp_send_json_success( $term_list );