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 +279 -145 2.1.53.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,11 +37,11 @@
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 - if ( ! Fns::verify_nonce() ) {
43 + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
42 44 $return = [
43 45 'success' => false,
44 46 'title' => $title,
45 47 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
@@ -46,8 +48,26 @@
46 48 ];
47 49 wp_send_json( $return );
48 50 }
49 51
52 + if ( ! current_user_can( 'manage_options' ) ) {
53 + $return = [
54 + 'success' => false,
55 + 'title' => $title,
56 + 'content' => esc_html__( 'Permission Denied...', 'shopbuilder' ),
57 + ];
58 + wp_send_json( $return );
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 + ];
66 +
67 + wp_send_json( $return );
68 + }
69 +
50 70 add_filter( 'option_' . Uploads_Manager::UNFILTERED_FILE_UPLOADS_KEY, '__return_true' );
51 71 Plugin::$instance->files_manager->clear_cache();
52 72
53 73 // user capability check.
@@ -53,21 +73,23 @@
53 73 // user capability check.
54 74 $user = wp_get_current_user();
55 75 $allowed_roles = [ 'editor', 'administrator', 'author' ];
56 76
57 - if ( ! array_intersect( $allowed_roles, $user->roles ) ) {
58 - wp_die( __( 'You don\'t have permission to perform this action', 'shopbuilder' ) );
77 + if ( ! array_intersect( $allowed_roles, Fns::get_current_user_roles() ) ) {
78 + wp_die( esc_html__( 'You don\'t have permission to perform this action', 'shopbuilder' ) );
59 79 }
60 80
61 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
62 83 if ( ! is_user_logged_in() && $user->ID !== sanitize_text_field( $_REQUEST['user_id'] ) ) {
63 - wp_die( __( 'You don\'t have proper authorization to perform this action', 'shopbuilder' ) );
84 + wp_die( esc_html__( 'You don\'t have proper authorization to perform this action', 'shopbuilder' ) );
64 85 }
65 86
66 - $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : null;
67 - $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;
68 89
69 90 $template_type = null;
91 + $product_page_for = 'all_products';
70 92 $template_default = null;
71 93 $url = '';
72 94 $tmp_title = '';
73 95 $_rtsb_import_id = '';
@@ -73,15 +95,18 @@
73 95 $_rtsb_import_id = '';
74 96 $edit_by = did_action( 'elementor/loaded' ) ? 'elementor' : 'elementor';
75 97 if ( $post_id ) {
76 98 $tmp_title = get_the_title( $post_id );
77 - $type = get_post_meta( $post_id, BuilderFns::template_type_meta_key() );
78 - $template_type = isset( $type[0] ) ? $type[0] : '';
79 - $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 );
80 102 $edit_by = Fns::page_edit_with( $post_id );
81 103 $action = 'edit';
104 + if ( rtsb()->has_pro() ) {
105 + $product_page_for = get_post_meta( $post_id, '_is_product_page_template_for', true );
106 + }
82 107
83 - // TODO:: This Condition Will remove after release Gutenberg Addons.
108 + /* This Condition Will remove after release Gutenberg Addons. */
84 109 if ( 'gutenberg' == $edit_by ) {
85 110 $action = 'elementor';
86 111 $edit_by = 'elementor';
87 112 }
@@ -99,20 +124,8 @@
99 124 );
100 125
101 126 $_rtsb_import_id = get_post_meta( $post_id, '_rtsb_import_id', true );
102 127 }
103 -
104 - $status = $_REQUEST['status'] ?? '';
105 - $post_args = [ 'timeout' => 120 ];
106 - $post_args['body'] = [
107 - 'status' => $status,
108 - ];
109 - $layoutRequest = wp_remote_post( rtsb()->BASE_API, $post_args );
110 - $layoutData = [];
111 - if ( ! is_wp_error( $layoutRequest ) && ! empty( $layoutRequest['body'] ) ) {
112 - $layoutData = json_decode( $layoutRequest['body'], true );
113 - }
114 -
115 128 ob_start();
116 129
117 130 ?>
118 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 ); ?>">
@@ -128,10 +141,9 @@
128 141 placeholder="<?php esc_attr_e( 'Enter Template Name', 'shopbuilder' ); ?>"
129 142 value="<?php echo esc_attr( $tmp_title ); ?>"
130 143 autocomplete="off"
131 144 >
132 - <span class="message"
133 - 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>
134 146 </div>
135 147 <div class="rtsb-template-type rtsb-tb-field-wraper">
136 148 <label for="rtsb_tb_template_type"><?php esc_html_e( 'Select Template Type', 'shopbuilder' ); ?></label>
137 149 <select class="rtsb-field" id="rtsb_tb_template_type" name="rtsb_tb_template_type">
@@ -143,37 +155,111 @@
143 155 <?php } ?>
144 156 </select>
145 157 </div>
146 158
147 - <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;">
148 195 <?php
149 - $default_items = '';
150 - $product_id = get_post_meta( $post_id, BuilderFns::$product_template_meta, true );
151 - if ( $product_id ) {
152 - $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 + }
153 209 }
154 210 ?>
155 - <label for="rtsb_product_page_preview"><?php esc_html_e( 'Select Product For Preview', 'shopbuilder' ); ?></label>
156 - <select class="rtsb-field" id="rtsb_product_page_preview" name="rtsb_product_page_preview">
157 - <?php echo Fns::print_html( $default_items, true ); ?>
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">
222 + <?php Fns::print_html( $default_items, true ); ?>
158 223 </select>
159 - <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>
160 233 </div>
161 234
162 - <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;">
163 244 <?php
164 245 $default_items_link = '';
165 246 $default_items = '';
166 - $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id );
167 - if ( ! empty( $product_ids ) && is_array( $product_ids ) ) {
168 - foreach ( $product_ids as $p_id ) {
169 - $title = get_the_title( $p_id );
170 - $default_items_link .= '<a target="_blank" href="' . get_the_permalink( $p_id ) . '">' . $title . '</a>';
171 - $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>';
172 257 }
173 258 }
174 259 ?>
175 - <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' ); ?>
176 262 <?php if ( ! rtsb()->has_pro() ) { ?>
177 263 <div class="card-label">
178 264 <span class="rtsb-btn-import pro-btn">
179 265 <?php echo esc_html( 'PRO' ); ?>
@@ -180,34 +266,38 @@
180 266 </span>
181 267 </div>
182 268 <?php } ?>
183 269 </label>
184 - <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">
185 271 <?php Fns::print_html( $default_items, true ); ?>
186 272 </select>
187 - <p style="margin:0;"> The Products Display in this layout. <span style="display:inline-flex; gap :10px"> <?php echo ! 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 + ?>
188 281 </p>
189 282 </div>
190 283
191 - <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;">
192 287 <?php
193 288 $default_items_link = '';
194 289 $default_items = '';
195 - $categories_name = apply_filters( 'rtsb/archive/page/builder/selected/categories', [], $post_id );
196 - if ( ! empty( $categories_name ) && is_array( $categories_name ) ) {
197 - foreach ( $categories_name as $c_name ) {
198 - $cat = get_term_by( 'slug', $c_name, 'product_cat' );
199 - $title = $cat->name;
200 - $link = get_term_link( $cat );
201 - if ( ! is_wp_error( $link ) ) {
202 - $default_items_link .= '<a target="_blank" href="' . get_term_link( $cat ) . '">' . $title . '</a>';
203 - }
204 - $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>';
205 296 }
206 297 }
207 298 ?>
208 - <label for="rtsb_page_for_the_products">
209 - <?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' ); ?>
210 300 <?php if ( ! rtsb()->has_pro() ) { ?>
211 301 <div class="card-label">
212 302 <span class="rtsb-btn-import pro-btn">
213 303 <?php echo esc_html( 'PRO' ); ?>
@@ -214,15 +304,41 @@
214 304 </span>
215 305 </div>
216 306 <?php } ?>
217 307 </label>
218 - <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">
219 309 <?php Fns::print_html( $default_items, true ); ?>
220 310 </select>
221 - <p style="margin:0;"> The Product Categories Display in this layout. <span style="display:inline-flex; gap :10px"> <?php echo ! 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 + ?>
222 319 </p>
223 320 </div>
224 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 +
225 341 <div class="rtsb-template-edit-with rtsb-tb-field-wraper">
226 342 <label for="rtsb_tb_template_edit_with"><?php esc_html_e( 'Select Editor Type', 'shopbuilder' ); ?></label>
227 343 <select class="rtsb-field" id="rtsb_tb_template_edit_with" name="rtsb_tb_template_edit_with"
228 344 required>
@@ -234,32 +350,53 @@
234 350 <div class="rtsb-template-setdefaults rtsb-tb-field-wraper">
235 351 <label for="default_template"> <?php esc_html_e( 'Set as Active Template', 'shopbuilder' ); ?></label>
236 352 <?php
237 353 if ( $post_id && 'product' === $template_type ) {
238 - $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id );
239 - $set_default = BuilderFns::get_specific_product_as_default( $post_id );
240 - if ( ! empty( $product_ids ) && $set_default ) {
241 - $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 + }
242 373 }
243 374 } elseif ( $post_id && 'archive' === $template_type ) {
244 - $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 );
245 376 $set_default = BuilderFns::get_specific_category_as_default( $post_id );
246 377 if ( ! empty( $categories_name ) && $set_default ) {
247 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;
248 383 }
384 + if ( ! $set_default && $template_default === $post_id ) {
385 + $template_default = '';
386 + }
249 387 }
250 388
251 389 ?>
252 390 <span class="rtsb-switch-wrapper"
253 - 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' ); ?>">
254 392 <label class="rtsb-switch">
255 393 <input class="rtsb_set_default rtsb-field"
256 394 type="checkbox"
257 395 id="default_template"
258 - class="rtsb-field"
259 396 name="default_template"
260 397 value="default_template"
261 - <?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' : '' ); ?>
262 399 >
263 400 <span class="rtsb-slider rtsb-round ">
264 401 <span class="rtsb-loader"></span>
265 402 </span>
@@ -266,32 +403,29 @@
266 403 </label>
267 404 </span>
268 405 </div>
269 406 <!-- TODO: Moday Layout -->
270 - <?php if ( ! $post_id ) { ?>
271 - <div class="set-default-layout-wrapper rtsb-tb-field-wraper">
272 - <label>
273 - <?php esc_html_e( 'Pre-built Templates ', 'shopbuilder' ); ?>
274 - <span id="modallabelPrefix"></span>
275 - </label>
276 - <div class="set-default-layout">
277 - <?php
278 - $default_item = [
279 - 'template_type' => 'default',
280 - 'image_url' => \Elementor\Utils::get_placeholder_image_src(),
281 - 'preview_link' => '',
282 - 'title' => __( 'Blank Template', 'shopbuilder' ),
283 - ];
284 -
285 - $this->get_modal_card_html( $default_item );
286 -
287 - if ( ! empty( $layoutData['layouts'] ) ) {
288 - foreach ( $layoutData['layouts'] as $item ) {
289 - $this->get_modal_card_html( $item );
290 - }
291 - }
292 - ?>
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>
293 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>
294 428 </div>
295 429 <?php } ?>
296 430 <input type="hidden" id="page_id" name="page_id" value="<?php echo esc_attr( $post_id ); ?>">
297 431 </div>
@@ -306,9 +440,17 @@
306 440 <?php esc_html_e( 'Save', 'shopbuilder' ); ?>
307 441 </button>
308 442 </div>
309 443 <div class="rtsb-tb-button-wrapper rtsb-tb-edit-button-wrapper">
310 - <a href="<?php echo esc_url( $url ); ?>" class="btn"> <?php esc_html_e( sprintf( 'Edit with %s', $edit_by ), 'shopbuilder' ); ?> </a>
444 + <a href="<?php echo esc_url( $url ); ?>" class="btn">
445 + <?php
446 + printf(
447 + /* translators: %s: Edit */
448 + esc_html__( 'Edit with %s', 'shopbuilder' ),
449 + esc_html( $edit_by )
450 + );
451 + ?>
452 + </a>
311 453 </div>
312 454 </div>
313 455 <?php
314 456 $footer = ob_get_clean();
@@ -321,55 +463,20 @@
321 463 wp_send_json( $return );
322 464 wp_die();
323 465 }
324 466
325 - public function default_layout_template_html( $key, $is_checked, $builder, $value = [] ) {
326 - $layout_type = $key . ( $builder ? '_' . $builder : null );
327 - ?>
328 - <!-- Elementor -->
329 - <label class="layout-container type-<?php echo esc_attr( $key ); ?>"
330 - data-layout-type='<?php echo esc_attr( $layout_type ); ?>'>
331 - <input <?php echo esc_attr( $is_checked ); ?>
332 - class="rtsb-field" type="radio"
333 - value="<?php echo ! empty( $value['import_file'] ) ? esc_attr( $value['import_file'] ) : ''; ?>"
334 - name="import_default_layout"/>
335 -
336 - <span class="checkmark dashicons"></span>
337 - <div class="image-wrapper">
338 - <?php if ( ! empty( $value['image'] ) ) { ?>
339 - <img src="<?php echo esc_url( $value['image'] ); ?>" alt="">
340 - <?php } ?>
341 - </div>
342 - <?php if ( ! empty( $value['text_label'] ) ) { ?>
343 - <div class="image-label">
344 - <span class="label-text"><?php echo esc_html( $value['text_label'] ); ?></span>
345 - <?php if ( ! empty( $value['live_preview'] ) ) { ?>
346 - <a target="_blank" class="btn-live-preview" href="<?php echo esc_url( $value['live_preview'] ); ?>">
347 - <span class="dashicons dashicons-visibility"></span>
348 - <?php esc_html_e( 'Live Preview', 'shopbuilder' ); ?>
349 - </a>
350 - <?php } ?>
351 - </div>
352 - <?php } ?>
353 - </label>
354 - <?php
355 - }
356 -
357 467 /**
358 468 * Get Modal Card Markup.
359 469 *
360 - * @param $item
361 - * @param $checked
470 + * @param array $item Item.
362 471 *
363 472 * @return void
364 473 */
365 474 public function get_modal_card_html( $item ) {
366 -
367 475 ?>
368 476 <div class="layout-container rtsb-template-item type-<?php echo esc_attr( $item['template_type'] ); ?>"
369 477 data-layout-type='<?php echo esc_attr( $item['template_type'] ); ?>'>
370 478 <input class="rtsb-field" type="hidden" value="<?php echo esc_attr( $item['id'] ?? '' ); ?>" name="import_default_layout"/>
371 -
372 479 <div class="image-wrapper">
373 480 <?php if ( $item['image_url'] ) : ?>
374 481 <img src="<?php echo esc_url( $item['image_url'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>">
375 482 <?php endif; ?>
@@ -374,9 +481,10 @@
374 481 <img src="<?php echo esc_url( $item['image_url'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>">
375 482 <?php endif; ?>
376 483
377 484 <?php if ( 'default' != $item['template_type'] && ( ! rtsb()->has_pro() ) ) : ?>
378 - <div class="card-label">
485 + <div class="card-label lllllll">
486 + label
379 487 <span class="rtsb-btn-import <?php echo esc_attr( $item['status'] ?? 'free' ); ?>-btn">
380 488 <?php echo esc_html( $item['status'] ?? 'Free' ); ?>
381 489 </span>
382 490 </div>
@@ -394,9 +502,12 @@
394 502 <?php echo esc_html__( 'Preview', 'shopbuilder' ); ?>
395 503 </a>
396 504
397 505
398 - <?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 + ?>
399 510 <a class="rtsb-btn-import import-btn rtsb-import-layout">
400 511 <svg width="22" height="20" viewBox="0 0 22 20" fill="none" xmlns="http://www.w3.org/2000/svg">
401 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"
402 513 fill="white"></path>
@@ -448,9 +559,9 @@
448 559 *
449 560 * @return void
450 561 */
451 562 public function product_search() {
452 - if ( ! Fns::verify_nonce() ) {
563 + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
453 564 $return = [
454 565 'success' => false,
455 566 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
456 567 ];
@@ -455,8 +566,15 @@
455 566 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
456 567 ];
457 568 wp_send_json( $return );
458 569 }
570 + if ( ! current_user_can( 'manage_options' ) ) {
571 + $return = [
572 + 'success' => false,
573 + 'content' => esc_html__( 'Permission Denied...', 'shopbuilder' ),
574 + ];
575 + wp_send_json( $return );
576 + }
459 577 global $wpdb;
460 578 $search = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
461 579 if ( empty( $search ) ) {
462 580 $return = [
@@ -464,9 +582,9 @@
464 582 'content' => esc_html__( 'Empty string Not allowed...', 'shopbuilder' ),
465 583 ];
466 584 wp_send_json( $return );
467 585 }
468 - $query = $wpdb->prepare(
586 + $query = $wpdb->prepare(
469 587 "SELECT ID, post_title
470 588 FROM $wpdb->posts
471 589 WHERE post_type = 'product'
472 590 AND post_status = 'publish'
@@ -474,20 +592,20 @@
474 592 LIMIT %d",
475 593 '%' . $search . '%',
476 594 10
477 595 );
478 -
479 - $_product = wp_cache_get( md5( $query ), 'rtsb-product-query' );
596 + $cache_key = md5( $query );
597 + $_product = wp_cache_get( $cache_key, 'shopbuilder' );
480 598 if ( false === $_product ) {
481 - $_product = $wpdb->get_results( $query );
482 - wp_cache_set( md5( $query ), $_product, 'rtsb-product-query' );
599 + $_product = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared
600 + wp_cache_set( $cache_key, $_product, 'shopbuilder' );
601 + Cache::set_data_cache_key( $cache_key );
483 602 }
484 -
485 603 $product_list = [];
486 604 foreach ( $_product as $product ) {
487 605 $product_list['items'][] = [
488 606 'id' => $product->ID,
489 - 'text' => $product->post_title . ' - ( ID ' . $product->ID . ' )',
607 + 'text' => html_entity_decode( $product->post_title, ENT_QUOTES | ENT_HTML5 ) . ' - (ID#' . $product->ID . ')',
490 608 ];
491 609 }
492 610
493 611 wp_send_json_success( $product_list );
@@ -498,11 +616,11 @@
498 616 * Popups For Create Template
499 617 *
500 618 * @return void
501 619 */
502 - public function category_search() {
620 + public function term_search() {
503 621
504 - if ( ! Fns::verify_nonce() ) {
622 + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
505 623 $return = [
506 624 'success' => false,
507 625 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
508 626 ];
@@ -507,17 +625,33 @@
507 625 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
508 626 ];
509 627 wp_send_json( $return );
510 628 }
511 - $search = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
512 - $args = [
513 - 'taxonomy' => [ 'product_cat' ], // taxonomy name
629 +
630 + if ( ! current_user_can( 'manage_options' ) ) {
631 + $return = [
632 + 'success' => false,
633 + 'content' => esc_html__( 'Permission Denied...', 'shopbuilder' ),
634 + ];
635 + wp_send_json( $return );
636 + }
637 +
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.
514 649 'orderby' => 'name',
515 650 'order' => 'ASC',
516 651 'hide_empty' => false,
517 652 'name__like' => $search,
518 653 ];
519 -
520 654 $terms = get_terms( $args );
521 655 $count = count( $terms );
522 656 $term_list = [];
523 657 if ( $count > 0 ) {
@@ -523,9 +657,9 @@
523 657 if ( $count > 0 ) {
524 658 foreach ( $terms as $term ) {
525 659 $term_list['items'][] = [
526 660 'id' => $term->slug,
527 - 'text' => $term->name,
661 + 'text' => html_entity_decode( $term->name, ENT_QUOTES | ENT_HTML5 ),
528 662 ];
529 663 }
530 664 }
531 665 wp_send_json_success( $term_list );