PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.2
ShopBuilder – WooCommerce Builder For Elementor v3.2.2
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/BuilderController.php +160 -71 2.0.23.2.2 View file →
@@ -6,17 +6,16 @@
6 6 */
7 7
8 8 namespace RadiusTheme\SB\Controllers;
9 9
10 -use Elementor\Plugin;
11 10 use RadiusTheme\SB\Helpers\Fns;
12 11 use RadiusTheme\SB\Helpers\BuilderFns;
12 +use RadiusTheme\SB\Models\ElementList;
13 13 use RadiusTheme\SB\Traits\SingletonTrait;
14 14 use RadiusTheme\SB\Controllers\Builder\BuilderCpt;
15 15 use RadiusTheme\SB\Controllers\Hooks\BuilderHooks;
16 16 use RadiusTheme\SB\Elementor\Controls\ImageSelectorControl;
17 17 use RadiusTheme\SB\Elementor\Controls\Select2AjaxControl;
18 -use RadiusTheme\SB\Models\ElementList;
19 18
20 19 // Do not allow directly accessing this file.
21 20 if ( ! defined( 'ABSPATH' ) ) {
22 21 exit( 'This script cannot be accessed directly.' );
@@ -26,8 +25,13 @@
26 25 * Builder Controller
27 26 */
28 27 class BuilderController {
29 28 /**
29 + * @var array
30 + */
31 + private static $cache = [];
32 +
33 + /**
30 34 * Builder page id.
31 35 *
32 36 * @var integer
33 37 */
@@ -56,19 +60,19 @@
56 60 BuilderHooks::instance();
57 61 }
58 62
59 63 BuilderCpt::instance();
60 -
61 - add_action( 'elementor/init', [ $this, 'elementor_init' ] );
62 - add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'editor_scripts' ] );
63 - add_action( 'template_redirect', [ $this, 'both_builder_frontend' ], 99 );
64 -
64 + if ( defined( 'ELEMENTOR_VERSION' ) ) {
65 + $this->elementor_init();
66 + $this->both_builder_frontend();
67 + add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'editor_scripts' ] );
68 + }
65 69 // RT Select2 Ajax.
66 - add_action( 'wp_ajax_rt_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] );
67 - add_action( 'wp_ajax_nopriv_rt_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] );
70 + add_action( 'wp_ajax_rtsb_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] );
71 + add_action( 'wp_ajax_nopriv_rtsb_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] );
68 72 // Select2 ajax save data.
69 - add_action( 'wp_ajax_rt_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] );
70 - add_action( 'wp_ajax_nopriv_rt_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] );
73 + add_action( 'wp_ajax_rtsb_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] );
74 + add_action( 'wp_ajax_nopriv_rtsb_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] );
71 75 }
72 76
73 77 /**
74 78 * Apply for frontend.
@@ -85,13 +89,20 @@
85 89 *
86 90 * @return void
87 91 */
88 92 public function elementor_init() {
89 - add_action( 'elementor/elements/categories_registered', [ $this, 'add_elementor_widget_categories' ] );
90 - add_action( 'elementor/widgets/register', [ $this, 'init_widgets' ] );
91 - add_action( 'elementor/controls/register', [ $this, 'init_controls' ] );
92 - add_filter( 'elementor/editor/localize_settings', [ $this, 'promotePremiumWidgets' ] );
93 - add_action( 'elementor/icons_manager/additional_tabs', [ $this, 'rtsb_icons' ] );
93 + add_action(
94 + 'init',
95 + function () {
96 + if ( Fns::should_load_elementor_scripts() ) {
97 + add_action( 'elementor/elements/categories_registered', [ $this, 'add_elementor_widget_categories' ] );
98 + add_action( 'elementor/widgets/register', [ $this, 'init_widgets' ] );
99 + add_action( 'elementor/controls/register', [ $this, 'init_controls' ] );
100 + add_filter( 'elementor/editor/localize_settings', [ $this, 'promotePremiumWidgets' ] );
101 + add_action( 'elementor/icons_manager/additional_tabs', [ $this, 'rtsb_icons' ] );
102 + }
103 + }
104 + );
94 105 }
95 106
96 107 /**
97 108 * Register Category
@@ -100,21 +111,29 @@
100 111 *
101 112 * @return void
102 113 */
103 114 public function add_elementor_widget_categories( $elements_manager ) {
104 - $type = BuilderFns::builder_type( get_the_ID() );
105 - $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : '';
106 - $builder_type = str_replace( 'My Account - ', '', $builder_type );
107 - $categories['rtsb-shopbuilder'] = [
108 - 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ),
109 - 'icon' => 'fa fa-plug',
110 - ];
111 - $categories['rtsb-shopbuilder-general'] = [
112 - 'title' => esc_html__( 'Shopbuilder - General', 'shopbuilder' ),
113 - 'icon' => 'fa fa-plug',
114 - ];
115 + $categories = [];
116 + $builder_id = get_queried_object_id();
117 + $id = Fns::wpml_object_id( $builder_id, BuilderFns::$post_type_tb, 'default' );
118 + $type = BuilderFns::builder_type( $id );
115 119
116 - $categories = apply_filters( 'rtsb_elementor_widgets_category_lists', $categories );
120 + if ( $type && 'popup-builder' !== $type ) {
121 + $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : '';
122 + $builder_type = str_replace( [ 'My Account - ', 'Endpoint: ' ], '', $builder_type );
123 + $categories['rtsb-shopbuilder'] = [
124 + 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ),
125 + 'icon' => 'fa fa-plug',
126 + ];
127 + }
128 + if ( 'quick-view' !== $type ) {
129 + $categories['rtsb-shopbuilder-general'] = [
130 + 'title' => esc_html__( 'Shopbuilder - General', 'shopbuilder' ),
131 + 'icon' => 'fa fa-plug',
132 + ];
133 + }
134 + $categories = apply_filters( 'rtsb_elementor_widgets_category_lists', $categories );
135 +
117 136 $other_categories = $elements_manager->get_categories();
118 137 $categories = array_merge(
119 138 array_slice( $other_categories, 0, 1 ),
120 139 $categories,
@@ -120,10 +139,10 @@
120 139 $categories,
121 140 array_slice( $other_categories, 1 )
122 141 );
123 142
124 - $set_categories = function ( $categories ) {
125 - $this->categories = $categories;
143 + $set_categories = function ( $categories ) use ( $elements_manager ) {
144 + $elements_manager->categories = $categories;
126 145 };
127 146
128 147 $set_categories->call( $elements_manager, $categories );
129 148 }
@@ -144,21 +163,20 @@
144 163
145 164 /**
146 165 * Init Widgets
147 166 *
148 - * Include widgets files and register them
167 + * Include widget files and register them
149 168 *
169 + * @param object $widgets_manager Widgets Manager.
170 + *
171 + * @return void
172 + *
150 173 * @since 1.0.0
151 174 */
152 175 public function init_widgets( $widgets_manager ) {
153 - $product = Fns::get_product();
154 176
155 - // TODO: Need to remove below condition and make compitability in each widgets.
156 - if ( ! $product ) {
157 - return;
158 - }
159 -
160 - foreach ( ElementList::instance()->get_list( true, 'active' ) as $element ) {
177 + $get_list = ElementList::instance()->get_list( true, 'active' );
178 + foreach ( $get_list as $element ) {
161 179 if ( isset( $element['active'] ) && 'on' !== $element['active'] ) {
162 180 continue;
163 181 }
164 182
@@ -220,23 +238,10 @@
220 238 *
221 239 * @return array
222 240 */
223 241 public function rtsb_icons( $tabs = [] ) {
224 - $fonts = rtsb()->get_assets_uri( 'fonts/rtsb-icons.json' );
242 + $custom_icons = Fns::get_custom_icon_names();
225 243
226 - $response = wp_remote_get( $fonts );
227 -
228 - if ( is_wp_error( $response ) ) {
229 - return $tabs;
230 - }
231 -
232 - $icons_json = wp_remote_retrieve_body( $response );
233 - $custom_icons = json_decode( $icons_json, true );
234 -
235 - if ( null === $custom_icons ) {
236 - return $tabs;
237 - }
238 -
239 244 $tabs['shopbuilder-icons'] = [
240 245 'name' => 'rtsb-fonts',
241 246 'label' => esc_html__( 'ShopBuilder Icons', 'shopbuilder' ),
242 247 'labelIcon' => 'fab fa-elementor',
@@ -292,9 +297,9 @@
292 297 *
293 298 * @since 2.0.0
294 299 */
295 300 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
296 - do_action( 'elementor/page_templates/header-footer/before_content' );
301 + do_action( 'elementor/page_templates/header-footer/before_content' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
297 302 }
298 303
299 304 $parent_class = apply_filters( 'rtsb/builder/content/parent_class', [] );
300 305
@@ -300,8 +305,18 @@
300 305
301 306 if ( BuilderFns::is_product() ) {
302 307 $product_id = Fns::get_prepared_product_id();
303 308 $parent_class = wc_get_product_class( $parent_class, $product_id );
309 + if ( function_exists( 'rtwpvs' ) ) {
310 + $_product = Fns::get_product();
311 + if ( $_product->is_type( 'variable' ) ) {
312 + $parent_class[] = 'rtwpvs-product';
313 + $beside_label = function_exists( 'rtwpvsp' ) && rtwpvs()->get_option( 'attribute_on_click_behavior' );
314 + if ( $beside_label ) {
315 + $parent_class[] = 'rtwpvs-selected-term-beside-label';
316 + }
317 + }
318 + }
304 319 }
305 320
306 321 if ( BuilderFns::is_shop() ) {
307 322 $parent_class[] = 'shop';
@@ -317,10 +332,18 @@
317 332
318 333 ?>
319 334 <!-- Before Content start -->
320 335 <div class="<?php echo esc_attr( implode( ' ', $parent_class ) ); ?>">
321 - <?php if ( BuilderFns::is_checkout() ) { ?>
322 - <form name="checkout" method="post" class="rtsb-woocommerce-checkout checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data">
336 + <?php
337 + if ( BuilderFns::is_checkout() ) {
338 + if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) {
339 + return;
340 + }
341 + ?>
342 + <!--
343 + woocommerce-checkout added for fix issue with payment method ( Revolut Pay )
344 + -->
345 + <form name="checkout" method="post" class="rtsb-woocommerce-checkout woocommerce-checkout checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data">
323 346 <?php
324 347 }
325 348 }
326 349
@@ -337,12 +360,15 @@
337 360 *
338 361 * @since 2.0.0
339 362 */
340 363 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
341 - do_action( 'elementor/page_templates/header-footer/after_content' );
364 + do_action( 'elementor/page_templates/header-footer/after_content' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
342 365 }
343 366
344 367 if ( BuilderFns::is_checkout() ) {
368 + if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) {
369 + return;
370 + }
345 371 ?>
346 372 </form>
347 373 <?php
348 374 }
@@ -357,24 +383,28 @@
357 383 *
358 384 * @return void
359 385 */
360 386 public function select2_ajax_posts_filter_autocomplete() {
361 -
387 + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
388 + wp_send_json_error( [] );
389 + }
362 390 $query_per_page = 15;
363 391 $post_type = 'post';
364 392 $source_name = 'post_type';
365 - $paged = $_POST['page'] ?? 1;
366 -
393 + $paged = absint( $_POST['page'] ?? 1 );
367 394 if ( ! empty( $_POST['post_type'] ) ) {
395 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
368 396 $post_type = sanitize_text_field( $_POST['post_type'] );
369 397 }
370 398
371 399 if ( ! empty( $_POST['source_name'] ) ) {
400 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
372 401 $source_name = sanitize_text_field( $_POST['source_name'] );
373 402 }
374 403
404 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
375 405 $search = ! empty( $_POST['search'] ) ? sanitize_text_field( $_POST['search'] ) : '';
376 - $results = $post_list = [];
406 + $results = $post_list = []; // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
377 407 switch ( $source_name ) {
378 408 case 'taxonomy':
379 409 $args = [
380 410 'hide_empty' => false,
@@ -383,9 +413,9 @@
383 413 'search' => $search,
384 414 'number' => '5',
385 415 ];
386 416
387 - if ( $post_type !== 'all' ) {
417 + if ( 'all' !== $post_type ) {
388 418 $args['taxonomy'] = $post_type;
389 419 }
390 420
391 421 $post_list = wp_list_pluck( get_terms( $args ), 'name', 'term_id' );
@@ -432,17 +462,22 @@
432 462 * @return void
433 463 */
434 464 public function select2_ajax_get_posts_value_titles() {
435 465
466 + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
467 + wp_send_json_error( [] );
468 + }
469 +
436 470 if ( empty( $_POST['id'] ) ) {
437 471 wp_send_json_error( [] );
438 472 }
439 473
474 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
440 475 if ( empty( array_filter( $_POST['id'] ) ) ) {
441 476 wp_send_json_error( [] );
442 477 }
443 478 $ids = array_map( 'intval', $_POST['id'] );
444 - $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : '';
479 + $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
445 480
446 481 switch ( $source_name ) {
447 482 case 'taxonomy':
448 483 $args = [
@@ -451,9 +486,11 @@
451 486 'order' => 'ASC',
452 487 'include' => implode( ',', $ids ),
453 488 ];
454 489
455 - if ( $_POST['post_type'] !== 'all' ) {
490 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
491 + if ( 'all' !== $_POST['post_type'] ) {
492 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
456 493 $args['taxonomy'] = sanitize_text_field( $_POST['post_type'] );
457 494 }
458 495
459 496 $response = wp_list_pluck( get_terms( $args ), 'name', 'term_id' );
@@ -471,9 +508,9 @@
471 508 break;
472 509 default:
473 510 $post_info = get_posts(
474 511 [
475 - 'post_type' => sanitize_text_field( $_POST['post_type'] ),
512 + 'post_type' => sanitize_text_field( $_POST['post_type'] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
476 513 'include' => implode( ',', $ids ),
477 514 ]
478 515 );
479 516 $response = wp_list_pluck( $post_info, 'post_title', 'ID' );
@@ -489,12 +526,12 @@
489 526
490 527 /**
491 528 * Ajax callback for rt-select2
492 529 *
493 - * @param $post_type
494 - * @param $limit
495 - * @param $search
496 - * @param $paged
530 + * @param string $post_type Post type.
531 + * @param int $limit Limit.
532 + * @param string $search Search.
533 + * @param int $paged Paged.
497 534 *
498 535 * @return array
499 536 */
500 537 public function get_query_data( $post_type = 'any', $limit = 10, $search = '', $paged = 1 ) {
@@ -531,10 +568,19 @@
531 568 if ( ! empty( $search ) ) {
532 569 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title LIKE %s", '%' . esc_sql( $search ) . '%' );
533 570 }
534 571
572 + // Add a query for shop_coupon post-type to check 'show on frontend' meta.
573 + if ( 'shop_coupon' === $post_type ) {
574 + $where .= " AND {$wpdb->posts}.ID IN (
575 + SELECT post_id FROM {$wpdb->postmeta}
576 + WHERE meta_key = 'rtsb_show_on_frontend'
577 + AND meta_value = 'on'
578 + )";
579 + }
580 +
535 581 $query = "select post_title,ID from $wpdb->posts where post_status = 'publish' {$where} {$limit}";
536 - $results = $wpdb->get_results( $query );
582 + $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching
537 583
538 584 if ( ! empty( $results ) ) {
539 585 foreach ( $results as $row ) {
540 586 $data[ $row->ID ] = $row->post_title . ' [#' . $row->ID . ']';
@@ -565,10 +611,10 @@
565 611
566 612 $pro_widgets = [
567 613 [
568 614 'name' => 'rtsb-ajax-product-filters',
569 - 'title' => esc_html__( 'Ajax Product Filters', 'testimonial-slider-showcase' ),
570 - 'description' => esc_html__( 'Ajax Product Filters', 'testimonial-slider-showcase' ),
615 + 'title' => esc_html__( 'Ajax Product Filters', 'shopbuilder' ),
616 + 'description' => esc_html__( 'Ajax Product Filters', 'shopbuilder' ),
571 617 'icon' => 'rtsb-el-custom rtsb-element icon-rtsb-ajax-product-filters rtsb-promotional-element',
572 618 'categories' => '[ "rtsb-shopbuilder" ]',
573 619 ],
574 620 ];
@@ -579,6 +625,49 @@
579 625 }
580 626 }
581 627
582 628 return $config;
629 + }
630 +
631 + /**
632 + * Get Icons.
633 + *
634 + * @return array
635 + */
636 + public function get_icons() {
637 + return [
638 + 'heart-empty',
639 + 'heart',
640 + 'eye',
641 + 'exchange',
642 + 'plus',
643 + 'minus',
644 + 'avatar',
645 + 'pay',
646 + 'share',
647 + 'clock',
648 + 'check-alt',
649 + 'check',
650 + 'delete',
651 + 'marker',
652 + 'list',
653 + 'list-2',
654 + 'power',
655 + 'cart',
656 + 'cart-2',
657 + 'cart-3',
658 + 'downloads',
659 + 'zoom',
660 + 'user-edit',
661 + 'grid',
662 + 'filter',
663 + 'billing',
664 + 'login',
665 + 'payment',
666 + 'search',
667 + 'edit',
668 + 'coupon',
669 + 'arrows-cw',
670 + 'trash-empty',
671 + ];
583 672 }
584 673 }