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 +72 -81 2.2.03.2.6 View file →
@@ -37,9 +37,9 @@
37 37 * Popups For Create Template
38 38 *
39 39 * @return void
40 40 */
41 - public function response() {
41 + public function response() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
42 42 $title = '<h2>' . esc_html__( 'Template Settings', 'shopbuilder' ) . '</h2>';
43 43 if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
44 44 $return = [
45 45 'success' => false,
@@ -56,9 +56,18 @@
56 56 'content' => esc_html__( 'Permission Denied...', 'shopbuilder' ),
57 57 ];
58 58 wp_send_json( $return );
59 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 + ];
60 66
67 + wp_send_json( $return );
68 + }
69 +
61 70 add_filter( 'option_' . Uploads_Manager::UNFILTERED_FILE_UPLOADS_KEY, '__return_true' );
62 71 Plugin::$instance->files_manager->clear_cache();
63 72
64 73 // user capability check.
@@ -64,19 +73,20 @@
64 73 // user capability check.
65 74 $user = wp_get_current_user();
66 75 $allowed_roles = [ 'editor', 'administrator', 'author' ];
67 76
68 - if ( ! array_intersect( $allowed_roles, $user->roles ) ) {
77 + if ( ! array_intersect( $allowed_roles, Fns::get_current_user_roles() ) ) {
69 78 wp_die( esc_html__( 'You don\'t have permission to perform this action', 'shopbuilder' ) );
70 79 }
71 80
72 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
73 83 if ( ! is_user_logged_in() && $user->ID !== sanitize_text_field( $_REQUEST['user_id'] ) ) {
74 84 wp_die( esc_html__( 'You don\'t have proper authorization to perform this action', 'shopbuilder' ) );
75 85 }
76 86
77 - $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : null;
78 - $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;
79 89
80 90 $template_type = null;
81 91 $product_page_for = 'all_products';
82 92 $template_default = null;
@@ -94,9 +104,9 @@
94 104 if ( rtsb()->has_pro() ) {
95 105 $product_page_for = get_post_meta( $post_id, '_is_product_page_template_for', true );
96 106 }
97 107
98 - // TODO:: This Condition Will remove after release Gutenberg Addons.
108 + /* This Condition Will remove after release Gutenberg Addons. */
99 109 if ( 'gutenberg' == $edit_by ) {
100 110 $action = 'elementor';
101 111 $edit_by = 'elementor';
102 112 }
@@ -114,20 +124,8 @@
114 124 );
115 125
116 126 $_rtsb_import_id = get_post_meta( $post_id, '_rtsb_import_id', true );
117 127 }
118 -
119 - $status = $_REQUEST['status'] ?? '';
120 - $post_args = [ 'timeout' => 120 ];
121 - $post_args['body'] = [
122 - 'status' => $status,
123 - ];
124 - $layoutRequest = wp_remote_post( rtsb()->BASE_API, $post_args );
125 - $layoutData = [];
126 - if ( ! is_wp_error( $layoutRequest ) && ! empty( $layoutRequest['body'] ) ) {
127 - $layoutData = json_decode( $layoutRequest['body'], true );
128 - }
129 -
130 128 ob_start();
131 129
132 130 ?>
133 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 ); ?>">
@@ -184,8 +182,15 @@
184 182 <?php } ?>
185 183 </select>
186 184 </div>
187 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 +
188 193 <!-- Product Page For Categories -->
189 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;">
190 195 <?php
191 196 $default_items_link = '';
@@ -226,8 +231,15 @@
226 231 ?>
227 232 </p>
228 233 </div>
229 234
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 +
230 242 <!-- Product Page for Selected Product Tags-->
231 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;">
232 244 <?php
233 245 $default_items_link = '';
@@ -310,11 +322,14 @@
310 322 <div class="rtsb-product-page-preview-field rtsb-tb-field-wraper" style="display:none;">
311 323 <?php
312 324 $default_items = '';
313 325 $product_id = get_post_meta( $post_id, BuilderFns::$product_template_meta, true );
314 - if ( $product_id ) {
326 + if ( $product_id && get_post_status( $product_id ) ) {
315 327 $default_items = '<option selected="selected" value="' . $product_id . '">' . get_the_title( $product_id ) . ' - ( ID ' . $product_id . ' )</option>';
316 328 }
329 + if ( $product_id && ! get_post_status( $product_id ) ) {
330 + delete_post_meta( $post_id, BuilderFns::$product_template_meta );
331 + }
317 332 ?>
318 333 <label for="rtsb_product_page_preview"><?php esc_html_e( 'Select Preview Product', 'shopbuilder' ); ?></label>
319 334 <select class="rtsb-field" id="rtsb_product_page_preview" name="rtsb_product_page_preview">
320 335 <?php Fns::print_html( $default_items, true ); ?>
@@ -340,8 +355,11 @@
340 355 $set_default = BuilderFns::get_specific_product_as_default( $post_id );
341 356 if ( $set_default ) {
342 357 $template_default = $post_id;
343 358 }
359 + if ( ! $set_default && $template_default === $post_id ) {
360 + $template_default = '';
361 + }
344 362 } else {
345 363 $set_default_option_name = '';
346 364 if ( 'product_cats' === $product_page_for ) {
347 365 $set_default_option_name = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id );
@@ -347,9 +365,9 @@
347 365 $set_default_option_name = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id );
348 366 } elseif ( 'product_tags' === $product_page_for ) {
349 367 $set_default_option_name = BuilderFns::option_name_product_page_specific_tag_set_default( $post_id );
350 368 }
351 - $default_id = TemplateSettings::instance()->get_option( $set_default_option_name );
369 + $default_id = ! empty( $set_default_option_name ) && TemplateSettings::instance()->get_option( $set_default_option_name );
352 370 if ( $default_id ) {
353 371 $template_default = $post_id;
354 372 }
355 373 }
@@ -357,9 +375,16 @@
357 375 $categories_name = apply_filters( 'rtsb/template/builder/selected/categories', [], $post_id, $template_type );
358 376 $set_default = BuilderFns::get_specific_category_as_default( $post_id );
359 377 if ( ! empty( $categories_name ) && $set_default ) {
360 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;
361 383 }
384 + if ( ! $set_default && $template_default === $post_id ) {
385 + $template_default = '';
386 + }
362 387 }
363 388
364 389 ?>
365 390 <span class="rtsb-switch-wrapper"
@@ -369,9 +394,9 @@
369 394 type="checkbox"
370 395 id="default_template"
371 396 name="default_template"
372 397 value="default_template"
373 - <?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' : '' ); ?>
374 399 >
375 400 <span class="rtsb-slider rtsb-round ">
376 401 <span class="rtsb-loader"></span>
377 402 </span>
@@ -378,32 +403,29 @@
378 403 </label>
379 404 </span>
380 405 </div>
381 406 <!-- TODO: Moday Layout -->
382 - <?php if ( ! $post_id ) { ?>
383 - <div class="set-default-layout-wrapper rtsb-tb-field-wraper">
384 - <label>
385 - <?php esc_html_e( 'Pre-built Templates ', 'shopbuilder' ); ?>
386 - <span id="modallabelPrefix"></span>
387 - </label>
388 - <div class="set-default-layout">
389 - <?php
390 - $default_item = [
391 - 'template_type' => 'default',
392 - 'image_url' => \Elementor\Utils::get_placeholder_image_src(),
393 - 'preview_link' => '',
394 - 'title' => __( 'Blank Template', 'shopbuilder' ),
395 - ];
396 -
397 - $this->get_modal_card_html( $default_item );
398 -
399 - if ( ! empty( $layoutData['layouts'] ) ) {
400 - foreach ( $layoutData['layouts'] as $item ) {
401 - $this->get_modal_card_html( $item );
402 - }
403 - }
404 - ?>
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>
405 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>
406 428 </div>
407 429 <?php } ?>
408 430 <input type="hidden" id="page_id" name="page_id" value="<?php echo esc_attr( $post_id ); ?>">
409 431 </div>
@@ -441,55 +463,20 @@
441 463 wp_send_json( $return );
442 464 wp_die();
443 465 }
444 466
445 - public function default_layout_template_html( $key, $is_checked, $builder, $value = [] ) {
446 - $layout_type = $key . ( $builder ? '_' . $builder : null );
447 - ?>
448 - <!-- Elementor -->
449 - <label class="layout-container type-<?php echo esc_attr( $key ); ?>"
450 - data-layout-type='<?php echo esc_attr( $layout_type ); ?>'>
451 - <input <?php echo esc_attr( $is_checked ); ?>
452 - class="rtsb-field" type="radio"
453 - value="<?php echo ! empty( $value['import_file'] ) ? esc_attr( $value['import_file'] ) : ''; ?>"
454 - name="import_default_layout"/>
455 -
456 - <span class="checkmark dashicons"></span>
457 - <div class="image-wrapper">
458 - <?php if ( ! empty( $value['image'] ) ) { ?>
459 - <img src="<?php echo esc_url( $value['image'] ); ?>" alt="">
460 - <?php } ?>
461 - </div>
462 - <?php if ( ! empty( $value['text_label'] ) ) { ?>
463 - <div class="image-label">
464 - <span class="label-text"><?php echo esc_html( $value['text_label'] ); ?></span>
465 - <?php if ( ! empty( $value['live_preview'] ) ) { ?>
466 - <a target="_blank" class="btn-live-preview" href="<?php echo esc_url( $value['live_preview'] ); ?>">
467 - <span class="dashicons dashicons-visibility"></span>
468 - <?php esc_html_e( 'Live Preview', 'shopbuilder' ); ?>
469 - </a>
470 - <?php } ?>
471 - </div>
472 - <?php } ?>
473 - </label>
474 - <?php
475 - }
476 -
477 467 /**
478 468 * Get Modal Card Markup.
479 469 *
480 - * @param $item
481 - * @param $checked
470 + * @param array $item Item.
482 471 *
483 472 * @return void
484 473 */
485 474 public function get_modal_card_html( $item ) {
486 -
487 475 ?>
488 476 <div class="layout-container rtsb-template-item type-<?php echo esc_attr( $item['template_type'] ); ?>"
489 477 data-layout-type='<?php echo esc_attr( $item['template_type'] ); ?>'>
490 478 <input class="rtsb-field" type="hidden" value="<?php echo esc_attr( $item['id'] ?? '' ); ?>" name="import_default_layout"/>
491 -
492 479 <div class="image-wrapper">
493 480 <?php if ( $item['image_url'] ) : ?>
494 481 <img src="<?php echo esc_url( $item['image_url'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>">
495 482 <?php endif; ?>
@@ -494,9 +481,10 @@
494 481 <img src="<?php echo esc_url( $item['image_url'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>">
495 482 <?php endif; ?>
496 483
497 484 <?php if ( 'default' != $item['template_type'] && ( ! rtsb()->has_pro() ) ) : ?>
498 - <div class="card-label">
485 + <div class="card-label lllllll">
486 + label
499 487 <span class="rtsb-btn-import <?php echo esc_attr( $item['status'] ?? 'free' ); ?>-btn">
500 488 <?php echo esc_html( $item['status'] ?? 'Free' ); ?>
501 489 </span>
502 490 </div>
@@ -514,9 +502,12 @@
514 502 <?php echo esc_html__( 'Preview', 'shopbuilder' ); ?>
515 503 </a>
516 504
517 505
518 - <?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 + ?>
519 510 <a class="rtsb-btn-import import-btn rtsb-import-layout">
520 511 <svg width="22" height="20" viewBox="0 0 22 20" fill="none" xmlns="http://www.w3.org/2000/svg">
521 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"
522 513 fill="white"></path>