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 -146 2.1.43.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,21 +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 -
111 - if ( is_wp_error( $layoutRequest ) ) {
112 - wp_send_json_error( [ 'messages' => $layoutRequest->get_error_messages() ] );
113 - }
114 - $layoutData = json_decode( $layoutRequest['body'], true );
115 -
116 128 ob_start();
117 129
118 130 ?>
119 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 ); ?>">
@@ -129,10 +141,9 @@
129 141 placeholder="<?php esc_attr_e( 'Enter Template Name', 'shopbuilder' ); ?>"
130 142 value="<?php echo esc_attr( $tmp_title ); ?>"
131 143 autocomplete="off"
132 144 >
133 - <span class="message"
134 - 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>
135 146 </div>
136 147 <div class="rtsb-template-type rtsb-tb-field-wraper">
137 148 <label for="rtsb_tb_template_type"><?php esc_html_e( 'Select Template Type', 'shopbuilder' ); ?></label>
138 149 <select class="rtsb-field" id="rtsb_tb_template_type" name="rtsb_tb_template_type">
@@ -144,37 +155,111 @@
144 155 <?php } ?>
145 156 </select>
146 157 </div>
147 158
148 - <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;">
149 195 <?php
150 - $default_items = '';
151 - $product_id = get_post_meta( $post_id, BuilderFns::$product_template_meta, true );
152 - if ( $product_id ) {
153 - $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 + }
154 209 }
155 210 ?>
156 - <label for="rtsb_product_page_preview"><?php esc_html_e( 'Select Product For Preview', 'shopbuilder' ); ?></label>
157 - <select class="rtsb-field" id="rtsb_product_page_preview" name="rtsb_product_page_preview">
158 - <?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 ); ?>
159 223 </select>
160 - <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>
161 233 </div>
162 234
163 - <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;">
164 244 <?php
165 245 $default_items_link = '';
166 246 $default_items = '';
167 - $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id );
168 - if ( ! empty( $product_ids ) && is_array( $product_ids ) ) {
169 - foreach ( $product_ids as $p_id ) {
170 - $title = get_the_title( $p_id );
171 - $default_items_link .= '<a target="_blank" href="' . get_the_permalink( $p_id ) . '">' . $title . '</a>';
172 - $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>';
173 257 }
174 258 }
175 259 ?>
176 - <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' ); ?>
177 262 <?php if ( ! rtsb()->has_pro() ) { ?>
178 263 <div class="card-label">
179 264 <span class="rtsb-btn-import pro-btn">
180 265 <?php echo esc_html( 'PRO' ); ?>
@@ -181,34 +266,38 @@
181 266 </span>
182 267 </div>
183 268 <?php } ?>
184 269 </label>
185 - <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">
186 271 <?php Fns::print_html( $default_items, true ); ?>
187 272 </select>
188 - <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 + ?>
189 281 </p>
190 282 </div>
191 283
192 - <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;">
193 287 <?php
194 288 $default_items_link = '';
195 289 $default_items = '';
196 - $categories_name = apply_filters( 'rtsb/archive/page/builder/selected/categories', [], $post_id );
197 - if ( ! empty( $categories_name ) && is_array( $categories_name ) ) {
198 - foreach ( $categories_name as $c_name ) {
199 - $cat = get_term_by( 'slug', $c_name, 'product_cat' );
200 - $title = $cat->name;
201 - $link = get_term_link( $cat );
202 - if ( ! is_wp_error( $link ) ) {
203 - $default_items_link .= '<a target="_blank" href="' . get_term_link( $cat ) . '">' . $title . '</a>';
204 - }
205 - $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>';
206 296 }
207 297 }
208 298 ?>
209 - <label for="rtsb_page_for_the_products">
210 - <?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' ); ?>
211 300 <?php if ( ! rtsb()->has_pro() ) { ?>
212 301 <div class="card-label">
213 302 <span class="rtsb-btn-import pro-btn">
214 303 <?php echo esc_html( 'PRO' ); ?>
@@ -215,15 +304,41 @@
215 304 </span>
216 305 </div>
217 306 <?php } ?>
218 307 </label>
219 - <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">
220 309 <?php Fns::print_html( $default_items, true ); ?>
221 310 </select>
222 - <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 + ?>
223 319 </p>
224 320 </div>
225 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 +
226 341 <div class="rtsb-template-edit-with rtsb-tb-field-wraper">
227 342 <label for="rtsb_tb_template_edit_with"><?php esc_html_e( 'Select Editor Type', 'shopbuilder' ); ?></label>
228 343 <select class="rtsb-field" id="rtsb_tb_template_edit_with" name="rtsb_tb_template_edit_with"
229 344 required>
@@ -235,32 +350,53 @@
235 350 <div class="rtsb-template-setdefaults rtsb-tb-field-wraper">
236 351 <label for="default_template"> <?php esc_html_e( 'Set as Active Template', 'shopbuilder' ); ?></label>
237 352 <?php
238 353 if ( $post_id && 'product' === $template_type ) {
239 - $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id );
240 - $set_default = BuilderFns::get_specific_product_as_default( $post_id );
241 - if ( ! empty( $product_ids ) && $set_default ) {
242 - $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 + }
243 373 }
244 374 } elseif ( $post_id && 'archive' === $template_type ) {
245 - $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 );
246 376 $set_default = BuilderFns::get_specific_category_as_default( $post_id );
247 377 if ( ! empty( $categories_name ) && $set_default ) {
248 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;
249 383 }
384 + if ( ! $set_default && $template_default === $post_id ) {
385 + $template_default = '';
386 + }
250 387 }
251 388
252 389 ?>
253 390 <span class="rtsb-switch-wrapper"
254 - 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' ); ?>">
255 392 <label class="rtsb-switch">
256 393 <input class="rtsb_set_default rtsb-field"
257 394 type="checkbox"
258 395 id="default_template"
259 - class="rtsb-field"
260 396 name="default_template"
261 397 value="default_template"
262 - <?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' : '' ); ?>
263 399 >
264 400 <span class="rtsb-slider rtsb-round ">
265 401 <span class="rtsb-loader"></span>
266 402 </span>
@@ -267,32 +403,29 @@
267 403 </label>
268 404 </span>
269 405 </div>
270 406 <!-- TODO: Moday Layout -->
271 - <?php if ( ! $post_id ) { ?>
272 - <div class="set-default-layout-wrapper rtsb-tb-field-wraper">
273 - <label>
274 - <?php esc_html_e( 'Pre-built Templates ', 'shopbuilder' ); ?>
275 - <span id="modallabelPrefix"></span>
276 - </label>
277 - <div class="set-default-layout">
278 - <?php
279 - $default_item = [
280 - 'template_type' => 'default',
281 - 'image_url' => \Elementor\Utils::get_placeholder_image_src(),
282 - 'preview_link' => '',
283 - 'title' => __( 'Blank Template', 'shopbuilder' ),
284 - ];
285 -
286 - $this->get_modal_card_html( $default_item );
287 -
288 - if ( ! empty( $layoutData['layouts'] ) ) {
289 - foreach ( $layoutData['layouts'] as $item ) {
290 - $this->get_modal_card_html( $item );
291 - }
292 - }
293 - ?>
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>
294 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>
295 428 </div>
296 429 <?php } ?>
297 430 <input type="hidden" id="page_id" name="page_id" value="<?php echo esc_attr( $post_id ); ?>">
298 431 </div>
@@ -307,9 +440,17 @@
307 440 <?php esc_html_e( 'Save', 'shopbuilder' ); ?>
308 441 </button>
309 442 </div>
310 443 <div class="rtsb-tb-button-wrapper rtsb-tb-edit-button-wrapper">
311 - <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>
312 453 </div>
313 454 </div>
314 455 <?php
315 456 $footer = ob_get_clean();
@@ -322,55 +463,20 @@
322 463 wp_send_json( $return );
323 464 wp_die();
324 465 }
325 466
326 - public function default_layout_template_html( $key, $is_checked, $builder, $value = [] ) {
327 - $layout_type = $key . ( $builder ? '_' . $builder : null );
328 - ?>
329 - <!-- Elementor -->
330 - <label class="layout-container type-<?php echo esc_attr( $key ); ?>"
331 - data-layout-type='<?php echo esc_attr( $layout_type ); ?>'>
332 - <input <?php echo esc_attr( $is_checked ); ?>
333 - class="rtsb-field" type="radio"
334 - value="<?php echo ! empty( $value['import_file'] ) ? esc_attr( $value['import_file'] ) : ''; ?>"
335 - name="import_default_layout"/>
336 -
337 - <span class="checkmark dashicons"></span>
338 - <div class="image-wrapper">
339 - <?php if ( ! empty( $value['image'] ) ) { ?>
340 - <img src="<?php echo esc_url( $value['image'] ); ?>" alt="">
341 - <?php } ?>
342 - </div>
343 - <?php if ( ! empty( $value['text_label'] ) ) { ?>
344 - <div class="image-label">
345 - <span class="label-text"><?php echo esc_html( $value['text_label'] ); ?></span>
346 - <?php if ( ! empty( $value['live_preview'] ) ) { ?>
347 - <a target="_blank" class="btn-live-preview" href="<?php echo esc_url( $value['live_preview'] ); ?>">
348 - <span class="dashicons dashicons-visibility"></span>
349 - <?php esc_html_e( 'Live Preview', 'shopbuilder' ); ?>
350 - </a>
351 - <?php } ?>
352 - </div>
353 - <?php } ?>
354 - </label>
355 - <?php
356 - }
357 -
358 467 /**
359 468 * Get Modal Card Markup.
360 469 *
361 - * @param $item
362 - * @param $checked
470 + * @param array $item Item.
363 471 *
364 472 * @return void
365 473 */
366 474 public function get_modal_card_html( $item ) {
367 -
368 475 ?>
369 476 <div class="layout-container rtsb-template-item type-<?php echo esc_attr( $item['template_type'] ); ?>"
370 477 data-layout-type='<?php echo esc_attr( $item['template_type'] ); ?>'>
371 478 <input class="rtsb-field" type="hidden" value="<?php echo esc_attr( $item['id'] ?? '' ); ?>" name="import_default_layout"/>
372 -
373 479 <div class="image-wrapper">
374 480 <?php if ( $item['image_url'] ) : ?>
375 481 <img src="<?php echo esc_url( $item['image_url'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>">
376 482 <?php endif; ?>
@@ -375,9 +481,10 @@
375 481 <img src="<?php echo esc_url( $item['image_url'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>">
376 482 <?php endif; ?>
377 483
378 484 <?php if ( 'default' != $item['template_type'] && ( ! rtsb()->has_pro() ) ) : ?>
379 - <div class="card-label">
485 + <div class="card-label lllllll">
486 + label
380 487 <span class="rtsb-btn-import <?php echo esc_attr( $item['status'] ?? 'free' ); ?>-btn">
381 488 <?php echo esc_html( $item['status'] ?? 'Free' ); ?>
382 489 </span>
383 490 </div>
@@ -395,9 +502,12 @@
395 502 <?php echo esc_html__( 'Preview', 'shopbuilder' ); ?>
396 503 </a>
397 504
398 505
399 - <?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 + ?>
400 510 <a class="rtsb-btn-import import-btn rtsb-import-layout">
401 511 <svg width="22" height="20" viewBox="0 0 22 20" fill="none" xmlns="http://www.w3.org/2000/svg">
402 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"
403 513 fill="white"></path>
@@ -449,9 +559,9 @@
449 559 *
450 560 * @return void
451 561 */
452 562 public function product_search() {
453 - if ( ! Fns::verify_nonce() ) {
563 + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
454 564 $return = [
455 565 'success' => false,
456 566 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
457 567 ];
@@ -456,8 +566,15 @@
456 566 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
457 567 ];
458 568 wp_send_json( $return );
459 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 + }
460 577 global $wpdb;
461 578 $search = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
462 579 if ( empty( $search ) ) {
463 580 $return = [
@@ -465,9 +582,9 @@
465 582 'content' => esc_html__( 'Empty string Not allowed...', 'shopbuilder' ),
466 583 ];
467 584 wp_send_json( $return );
468 585 }
469 - $query = $wpdb->prepare(
586 + $query = $wpdb->prepare(
470 587 "SELECT ID, post_title
471 588 FROM $wpdb->posts
472 589 WHERE post_type = 'product'
473 590 AND post_status = 'publish'
@@ -475,20 +592,20 @@
475 592 LIMIT %d",
476 593 '%' . $search . '%',
477 594 10
478 595 );
479 -
480 - $_product = wp_cache_get( md5( $query ), 'rtsb-product-query' );
596 + $cache_key = md5( $query );
597 + $_product = wp_cache_get( $cache_key, 'shopbuilder' );
481 598 if ( false === $_product ) {
482 - $_product = $wpdb->get_results( $query );
483 - 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 );
484 602 }
485 -
486 603 $product_list = [];
487 604 foreach ( $_product as $product ) {
488 605 $product_list['items'][] = [
489 606 'id' => $product->ID,
490 - 'text' => $product->post_title . ' - ( ID ' . $product->ID . ' )',
607 + 'text' => html_entity_decode( $product->post_title, ENT_QUOTES | ENT_HTML5 ) . ' - (ID#' . $product->ID . ')',
491 608 ];
492 609 }
493 610
494 611 wp_send_json_success( $product_list );
@@ -499,11 +616,11 @@
499 616 * Popups For Create Template
500 617 *
501 618 * @return void
502 619 */
503 - public function category_search() {
620 + public function term_search() {
504 621
505 - if ( ! Fns::verify_nonce() ) {
622 + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
506 623 $return = [
507 624 'success' => false,
508 625 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
509 626 ];
@@ -508,17 +625,33 @@
508 625 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
509 626 ];
510 627 wp_send_json( $return );
511 628 }
512 - $search = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
513 - $args = [
514 - '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.
515 649 'orderby' => 'name',
516 650 'order' => 'ASC',
517 651 'hide_empty' => false,
518 652 'name__like' => $search,
519 653 ];
520 -
521 654 $terms = get_terms( $args );
522 655 $count = count( $terms );
523 656 $term_list = [];
524 657 if ( $count > 0 ) {
@@ -524,9 +657,9 @@
524 657 if ( $count > 0 ) {
525 658 foreach ( $terms as $term ) {
526 659 $term_list['items'][] = [
527 660 'id' => $term->slug,
528 - 'text' => $term->name,
661 + 'text' => html_entity_decode( $term->name, ENT_QUOTES | ENT_HTML5 ),
529 662 ];
530 663 }
531 664 }
532 665 wp_send_json_success( $term_list );