PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.6.3
ShopBuilder – WooCommerce Builder For Elementor v2.6.3
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 +86 -126 3.4.22.6.3 View file →
@@ -37,9 +37,9 @@
37 37 * Popups For Create Template
38 38 *
39 39 * @return void
40 40 */
41 - public function response() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
41 + public function response() {
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,
@@ -78,15 +78,15 @@
78 78 wp_die( esc_html__( 'You don\'t have permission to perform this action', 'shopbuilder' ) );
79 79 }
80 80
81 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
82 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
83 83 if ( ! is_user_logged_in() && $user->ID !== sanitize_text_field( $_REQUEST['user_id'] ) ) {
84 84 wp_die( esc_html__( 'You don\'t have proper authorization to perform this action', 'shopbuilder' ) );
85 85 }
86 86
87 - $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : null;
88 - $layout_id = isset( $_REQUEST['layout_id'] ) ? absint( $_REQUEST['layout_id'] ) : null;
87 + $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : null;
88 + $layout_id = isset( $_POST['layout_id'] ) ? absint( $_POST['layout_id'] ) : null;
89 89
90 90 $template_type = null;
91 91 $product_page_for = 'all_products';
92 92 $template_default = null;
@@ -104,9 +104,9 @@
104 104 if ( rtsb()->has_pro() ) {
105 105 $product_page_for = get_post_meta( $post_id, '_is_product_page_template_for', true );
106 106 }
107 107
108 - /* This Condition Will remove after release Gutenberg Addons. */
108 + // TODO:: This Condition Will remove after release Gutenberg Addons.
109 109 if ( 'gutenberg' == $edit_by ) {
110 110 $action = 'elementor';
111 111 $edit_by = 'elementor';
112 112 }
@@ -124,8 +124,21 @@
124 124 );
125 125
126 126 $_rtsb_import_id = get_post_meta( $post_id, '_rtsb_import_id', true );
127 127 }
128 +
129 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
130 + $status = $_REQUEST['status'] ?? '';
131 + $post_args = [ 'timeout' => 120 ];
132 + $post_args['body'] = [
133 + 'status' => $status,
134 + ];
135 + $layoutRequest = wp_remote_post( rtsb()->BASE_API, $post_args );
136 + $layoutData = [];
137 + if ( ! is_wp_error( $layoutRequest ) && ! empty( $layoutRequest['body'] ) ) {
138 + $layoutData = json_decode( $layoutRequest['body'], true );
139 + }
140 +
128 141 ob_start();
129 142
130 143 ?>
131 144 <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 ); ?>">
@@ -172,18 +185,11 @@
172 185 <?php
173 186 $builder_page_types = [
174 187 'all_products' => esc_html__( 'All Products', 'shopbuilder' ),
175 188 'product_cats' => esc_html__( 'Product Categories', 'shopbuilder' ),
176 - 'product_brands' => esc_html__( 'Product Brands', 'shopbuilder' ),
177 189 'product_tags' => esc_html__( 'Product Tags', 'shopbuilder' ),
178 190 'specific_products' => esc_html__( 'Selected Products', 'shopbuilder' ),
179 191 ];
180 - // Only expose the brand option when the `product_brand` taxonomy is
181 - // registered (WC 9.4+ native, or a brand plugin). Hides gracefully
182 - // on sites without brand support.
183 - if ( ! taxonomy_exists( 'product_brand' ) ) {
184 - unset( $builder_page_types['product_brands'] );
185 - }
186 192 foreach ( $builder_page_types as $key => $value ) {
187 193 ?>
188 194 <option <?php echo esc_attr( $key === $product_page_for ? 'selected="selected"' : '' ); ?> value="<?php echo esc_attr( $key ); ?>"> <?php echo esc_html( $value ); ?> </option>
189 195 <?php } ?>
@@ -288,64 +294,8 @@
288 294 </p>
289 295 </div>
290 296
291 297
292 - <!-- Product Page for Selected Product Brands -->
293 - <?php if ( taxonomy_exists( 'product_brand' ) ) : ?>
294 - <div class="rtsb-product-brands-page-field rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;">
295 - <?php
296 - $default_items_link = '';
297 - $default_items = '';
298 - $brands_name = apply_filters( 'rtsb/template/builder/selected/brands', [], $post_id, $template_type );
299 - if ( ! empty( $brands_name ) && is_array( $brands_name ) ) {
300 - foreach ( $brands_name as $b_name ) {
301 - $brand = get_term_by( 'slug', $b_name, 'product_brand' );
302 - if ( empty( $brand ) || is_wp_error( $brand ) ) {
303 - continue;
304 - }
305 - $title_brand = $brand->name;
306 - $link = get_term_link( $brand );
307 - if ( ! is_wp_error( $link ) ) {
308 - $default_items_link .= '<a target="_blank" href="' . esc_url( $link ) . '">' . esc_html( $title_brand ) . '</a>';
309 - }
310 - $default_items .= '<option selected="selected" value="' . esc_attr( $b_name ) . '">' . esc_html( $title_brand ) . '</option>';
311 - }
312 - }
313 - ?>
314 - <label for="rtsb_page_for_the_product_brands">
315 - <?php esc_html_e( 'Select Product Brands', 'shopbuilder' ); ?>
316 - <?php if ( ! rtsb()->has_pro() ) { ?>
317 - <div class="card-label">
318 - <span class="rtsb-btn-import pro-btn">
319 - <?php echo esc_html( 'PRO' ); ?>
320 - </span>
321 - </div>
322 - <?php } ?>
323 - </label>
324 - <select class="rtsb-field" id="rtsb_page_for_the_product_brands" name="rtsb_page_for_the_product_brands" multiple="multiple">
325 - <?php Fns::print_html( $default_items, true ); ?>
326 - </select>
327 - <p style="margin:0;">Select a Product Brand to apply this template. You can select multiple Brands. Keep it blank to apply to all.
328 - <?php
329 - if ( ! empty( $default_items_link ) ) {
330 - ?>
331 - <span style="display: flex; gap: 3px 7px; flex-wrap: wrap; margin-top: 10px;"> <?php Fns::print_html( 'View Brand Archive Pages: ' . $default_items_link ); ?> </span>
332 - <?php
333 - }
334 - ?>
335 - </p>
336 - </div>
337 -
338 - <?php if ( ! rtsb()->has_pro() ) { ?>
339 - <div class="rtsb-product-brands-page-field rtsb-tb-field-wraper" style="display:none;">
340 - <label for="product_page_for"> </label>
341 - <span class="elementor-pro-notice"><a target="_blank" href="<?php echo esc_url( rtsb()->pro_version_link() ); ?>">Upgrade to PRO</a> to unlock Brand Base Product Page.</span>
342 - </div>
343 - <?php } ?>
344 - <?php endif; ?>
345 -
346 - <?php do_action( 'rtsb/builder/modal/extra_fields', $post_id, $template_type, $product_page_for ); ?>
347 -
348 298 <!-- Product Page for Selected Product -->
349 299 <div class="rtsb-page-for-the-products rtsb-tb-field-wraper <?php echo esc_attr( ! rtsb()->has_pro() ? 'pro-disable' : '' ); ?>" style="display:none;">
350 300 <?php
351 301 $default_items_link = '';
@@ -412,16 +362,8 @@
412 362 </div>
413 363 <div class="rtsb-template-setdefaults rtsb-tb-field-wraper">
414 364 <label for="default_template"> <?php esc_html_e( 'Set as Active Template', 'shopbuilder' ); ?></label>
415 365 <?php
416 - $singleton_types = apply_filters(
417 - 'rtsb/builder/singleton_types',
418 - array_keys( BuilderFns::builder_page_types() )
419 - );
420 - $is_pool_type = $template_type && ! in_array( $template_type, $singleton_types, true );
421 - if ( $post_id && $is_pool_type ) {
422 - $template_default = 'on' === get_post_meta( $post_id, '_rtsb_tb_enabled_in_pool', true ) ? $post_id : 0;
423 - }
424 366 if ( $post_id && 'product' === $template_type ) {
425 367 if ( 'specific_products' === $product_page_for ) {
426 368 $set_default = BuilderFns::get_specific_product_as_default( $post_id );
427 369 if ( $set_default ) {
@@ -426,11 +368,8 @@
426 368 $set_default = BuilderFns::get_specific_product_as_default( $post_id );
427 369 if ( $set_default ) {
428 370 $template_default = $post_id;
429 371 }
430 - if ( ! $set_default && $template_default === $post_id ) {
431 - $template_default = '';
432 - }
433 372 } else {
434 373 $set_default_option_name = '';
435 374 if ( 'product_cats' === $product_page_for ) {
436 375 $set_default_option_name = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id );
@@ -435,10 +374,8 @@
435 374 if ( 'product_cats' === $product_page_for ) {
436 375 $set_default_option_name = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id );
437 376 } elseif ( 'product_tags' === $product_page_for ) {
438 377 $set_default_option_name = BuilderFns::option_name_product_page_specific_tag_set_default( $post_id );
439 - } elseif ( 'product_brands' === $product_page_for ) {
440 - $set_default_option_name = BuilderFns::option_name_product_page_specific_brand_set_default( $post_id );
441 378 }
442 379 $default_id = ! empty( $set_default_option_name ) && TemplateSettings::instance()->get_option( $set_default_option_name );
443 380 if ( $default_id ) {
444 381 $template_default = $post_id;
@@ -448,19 +385,11 @@
448 385 $categories_name = apply_filters( 'rtsb/template/builder/selected/categories', [], $post_id, $template_type );
449 386 $set_default = BuilderFns::get_specific_category_as_default( $post_id );
450 387 if ( ! empty( $categories_name ) && $set_default ) {
451 388 $template_default = $post_id;
452 - } else {
453 - $option_name = BuilderFns::option_name( $template_type );
454 - $is_set_default = TemplateSettings::instance()->get_option( $option_name );
455 - $set_default = $is_set_default;
456 389 }
457 - if ( ! $set_default && $template_default === $post_id ) {
458 - $template_default = '';
459 - }
460 390 }
461 391
462 - $template_default = apply_filters( 'rtsb/builder/modal/template_default', $template_default, $post_id, $template_type );
463 392 ?>
464 393 <span class="rtsb-switch-wrapper"
465 394 title="<?php esc_html_e( 'Switch on to set as active template', 'shopbuilder' ); ?>">
466 395 <label class="rtsb-switch">
@@ -477,29 +406,32 @@
477 406 </label>
478 407 </span>
479 408 </div>
480 409 <!-- TODO: Moday Layout -->
481 - <?php
482 - if ( ! $post_id ) {
483 - if ( defined( 'ELEMENTOR_PATH' ) && class_exists( '\Elementor\Utils' ) ) {
484 - $placeholderImageSrc = \Elementor\Utils::get_placeholder_image_src();
485 - } else {
486 - $placeholderImageSrc = '#';
487 - }
488 - ?>
489 - <div class="set-default-layout-wrapper rtsb-tb-field-wraper" style="opacity: 0" >
490 - <div style="display: flex; justify-content: space-between;">
491 - <label>
492 - <?php esc_html_e( 'Pre-built Templates ', 'shopbuilder' ); ?>
493 - <span id="modallabelPrefix"></span>
494 - </label>
495 - <div class="rtsb-tb-button-wrapper">
496 - <a class="btn" href="https://shopbuilderwp.com/themes/" target="_blank" style="opacity: 1; visibility: visible;">View Out Themes</a>
497 - </div>
410 + <?php if ( ! $post_id ) { ?>
411 + <div class="set-default-layout-wrapper rtsb-tb-field-wraper">
412 + <label>
413 + <?php esc_html_e( 'Pre-built Templates ', 'shopbuilder' ); ?>
414 + <span id="modallabelPrefix"></span>
415 + </label>
416 + <div class="set-default-layout">
417 + <?php
418 + $default_item = [
419 + 'template_type' => 'default',
420 + 'image_url' => \Elementor\Utils::get_placeholder_image_src(),
421 + 'preview_link' => '',
422 + 'title' => __( 'Blank Template', 'shopbuilder' ),
423 + ];
424 +
425 + $this->get_modal_card_html( $default_item );
426 +
427 + if ( ! empty( $layoutData['layouts'] ) ) {
428 + foreach ( $layoutData['layouts'] as $item ) {
429 + $this->get_modal_card_html( $item );
430 + }
431 + }
432 + ?>
498 433 </div>
499 - <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 ); ?>">
500 - <!-- Layout Will Add Via Ajax-->
501 - </div>
502 434 </div>
503 435 <?php } ?>
504 436 <input type="hidden" id="page_id" name="page_id" value="<?php echo esc_attr( $post_id ); ?>">
505 437 </div>
@@ -537,20 +469,55 @@
537 469 wp_send_json( $return );
538 470 wp_die();
539 471 }
540 472
473 + public function default_layout_template_html( $key, $is_checked, $builder, $value = [] ) {
474 + $layout_type = $key . ( $builder ? '_' . $builder : null );
475 + ?>
476 + <!-- Elementor -->
477 + <label class="layout-container type-<?php echo esc_attr( $key ); ?>"
478 + data-layout-type='<?php echo esc_attr( $layout_type ); ?>'>
479 + <input <?php echo esc_attr( $is_checked ); ?>
480 + class="rtsb-field" type="radio"
481 + value="<?php echo ! empty( $value['import_file'] ) ? esc_attr( $value['import_file'] ) : ''; ?>"
482 + name="import_default_layout"/>
483 +
484 + <span class="checkmark dashicons"></span>
485 + <div class="image-wrapper">
486 + <?php if ( ! empty( $value['image'] ) ) { ?>
487 + <img src="<?php echo esc_url( $value['image'] ); ?>" alt="">
488 + <?php } ?>
489 + </div>
490 + <?php if ( ! empty( $value['text_label'] ) ) { ?>
491 + <div class="image-label">
492 + <span class="label-text"><?php echo esc_html( $value['text_label'] ); ?></span>
493 + <?php if ( ! empty( $value['live_preview'] ) ) { ?>
494 + <a target="_blank" class="btn-live-preview" href="<?php echo esc_url( $value['live_preview'] ); ?>">
495 + <span class="dashicons dashicons-visibility"></span>
496 + <?php esc_html_e( 'Live Preview', 'shopbuilder' ); ?>
497 + </a>
498 + <?php } ?>
499 + </div>
500 + <?php } ?>
501 + </label>
502 + <?php
503 + }
504 +
541 505 /**
542 506 * Get Modal Card Markup.
543 507 *
544 - * @param array $item Item.
508 + * @param $item
509 + * @param $checked
545 510 *
546 511 * @return void
547 512 */
548 513 public function get_modal_card_html( $item ) {
514 +
549 515 ?>
550 516 <div class="layout-container rtsb-template-item type-<?php echo esc_attr( $item['template_type'] ); ?>"
551 517 data-layout-type='<?php echo esc_attr( $item['template_type'] ); ?>'>
552 518 <input class="rtsb-field" type="hidden" value="<?php echo esc_attr( $item['id'] ?? '' ); ?>" name="import_default_layout"/>
519 +
553 520 <div class="image-wrapper">
554 521 <?php if ( $item['image_url'] ) : ?>
555 522 <img src="<?php echo esc_url( $item['image_url'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>">
556 523 <?php endif; ?>
@@ -555,10 +522,9 @@
555 522 <img src="<?php echo esc_url( $item['image_url'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>">
556 523 <?php endif; ?>
557 524
558 525 <?php if ( 'default' != $item['template_type'] && ( ! rtsb()->has_pro() ) ) : ?>
559 - <div class="card-label lllllll">
560 - label
526 + <div class="card-label">
561 527 <span class="rtsb-btn-import <?php echo esc_attr( $item['status'] ?? 'free' ); ?>-btn">
562 528 <?php echo esc_html( $item['status'] ?? 'Free' ); ?>
563 529 </span>
564 530 </div>
@@ -576,12 +542,9 @@
576 542 <?php echo esc_html__( 'Preview', 'shopbuilder' ); ?>
577 543 </a>
578 544
579 545
580 - <?php
581 - // phpcs:ignore WordPress.PHP.YodaConditions.NotYoda
582 - if ( rtsb()->has_pro() || $item['status'] == 'free' ) :
583 - ?>
546 + <?php if ( rtsb()->has_pro() || $item['status'] == 'free' ) : ?>
584 547 <a class="rtsb-btn-import import-btn rtsb-import-layout">
585 548 <svg width="22" height="20" viewBox="0 0 22 20" fill="none" xmlns="http://www.w3.org/2000/svg">
586 549 <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"
587 550 fill="white"></path>
@@ -656,26 +619,23 @@
656 619 'content' => esc_html__( 'Empty string Not allowed...', 'shopbuilder' ),
657 620 ];
658 621 wp_send_json( $return );
659 622 }
660 - /** @noinspection SqlNoDataSourceInspection */
661 - /** @noinspection SqlResolve */
662 - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
663 623 $query = $wpdb->prepare(
664 - "SELECT ID, post_title
665 - FROM $wpdb->posts
666 - WHERE post_type = 'product'
667 - AND post_status = 'publish'
668 - AND post_title LIKE %s
624 + "SELECT ID, post_title
625 + FROM $wpdb->posts
626 + WHERE post_type = 'product'
627 + AND post_status = 'publish'
628 + AND post_title LIKE %s
669 629 LIMIT %d",
670 630 '%' . $search . '%',
671 631 10
672 632 );
673 633 $cache_key = md5( $query );
674 - $_product = wp_cache_get( $cache_key, Cache::group() );
634 + $_product = wp_cache_get( $cache_key, 'shopbuilder' );
675 635 if ( false === $_product ) {
676 636 $_product = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared
677 - wp_cache_set( $cache_key, $_product, Cache::group(), 12 * HOUR_IN_SECONDS );
637 + wp_cache_set( $cache_key, $_product, 'shopbuilder' );
678 638 Cache::set_data_cache_key( $cache_key );
679 639 }
680 640 $product_list = [];
681 641 foreach ( $_product as $product ) {