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