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