PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.6.2
ShopBuilder – WooCommerce Builder For Elementor v2.6.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 +129 -54 2.0.32.6.2 View file →
@@ -6,9 +6,8 @@
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;
13 12 use RadiusTheme\SB\Traits\SingletonTrait;
14 13 use RadiusTheme\SB\Controllers\Builder\BuilderCpt;
@@ -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.
@@ -100,21 +104,29 @@
100 104 *
101 105 * @return void
102 106 */
103 107 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 - ];
108 + $categories = [];
109 + $builder_id = get_queried_object_id();
110 + $id = Fns::wpml_object_id( $builder_id, BuilderFns::$post_type_tb, 'default' );
111 + $type = BuilderFns::builder_type( $id );
115 112
116 - $categories = apply_filters( 'rtsb_elementor_widgets_category_lists', $categories );
113 + if ( $type ) {
114 + $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : '';
115 + $builder_type = str_replace( [ 'My Account - ', 'Endpoint: ' ], '', $builder_type );
116 + $categories['rtsb-shopbuilder'] = [
117 + 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ),
118 + 'icon' => 'fa fa-plug',
119 + ];
120 + }
121 + if ( 'quick-view' !== $type ) {
122 + $categories['rtsb-shopbuilder-general'] = [
123 + 'title' => esc_html__( 'Shopbuilder - General', 'shopbuilder' ),
124 + 'icon' => 'fa fa-plug',
125 + ];
126 + }
127 + $categories = apply_filters( 'rtsb_elementor_widgets_category_lists', $categories );
128 +
117 129 $other_categories = $elements_manager->get_categories();
118 130 $categories = array_merge(
119 131 array_slice( $other_categories, 0, 1 ),
120 132 $categories,
@@ -120,10 +132,10 @@
120 132 $categories,
121 133 array_slice( $other_categories, 1 )
122 134 );
123 135
124 - $set_categories = function ( $categories ) {
125 - $this->categories = $categories;
136 + $set_categories = function ( $categories ) use ( $elements_manager ) {
137 + $elements_manager->categories = $categories;
126 138 };
127 139
128 140 $set_categories->call( $elements_manager, $categories );
129 141 }
@@ -149,16 +161,11 @@
149 161 *
150 162 * @since 1.0.0
151 163 */
152 164 public function init_widgets( $widgets_manager ) {
153 - $product = Fns::get_product();
154 165
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 ) {
166 + $get_list = ElementList::instance()->get_list( true, 'active' );
167 + foreach ( $get_list as $element ) {
161 168 if ( isset( $element['active'] ) && 'on' !== $element['active'] ) {
162 169 continue;
163 170 }
164 171
@@ -220,23 +227,10 @@
220 227 *
221 228 * @return array
222 229 */
223 230 public function rtsb_icons( $tabs = [] ) {
224 - $fonts = rtsb()->get_assets_uri( 'fonts/rtsb-icons.json' );
231 + $custom_icons = Fns::get_custom_icon_names();
225 232
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 233 $tabs['shopbuilder-icons'] = [
240 234 'name' => 'rtsb-fonts',
241 235 'label' => esc_html__( 'ShopBuilder Icons', 'shopbuilder' ),
242 236 'labelIcon' => 'fab fa-elementor',
@@ -300,8 +294,18 @@
300 294
301 295 if ( BuilderFns::is_product() ) {
302 296 $product_id = Fns::get_prepared_product_id();
303 297 $parent_class = wc_get_product_class( $parent_class, $product_id );
298 + if ( function_exists( 'rtwpvs' ) ) {
299 + $_product = Fns::get_product();
300 + if ( $_product->is_type( 'variable' ) ) {
301 + $parent_class[] = 'rtwpvs-product';
302 + $beside_label = function_exists( 'rtwpvsp' ) && rtwpvs()->get_option( 'attribute_on_click_behavior' );
303 + if ( $beside_label ) {
304 + $parent_class[] = 'rtwpvs-selected-term-beside-label';
305 + }
306 + }
307 + }
304 308 }
305 309
306 310 if ( BuilderFns::is_shop() ) {
307 311 $parent_class[] = 'shop';
@@ -317,9 +321,14 @@
317 321
318 322 ?>
319 323 <!-- Before Content start -->
320 324 <div class="<?php echo esc_attr( implode( ' ', $parent_class ) ); ?>">
321 - <?php if ( BuilderFns::is_checkout() ) { ?>
325 + <?php
326 + if ( BuilderFns::is_checkout() ) {
327 + if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) {
328 + return;
329 + }
330 + ?>
322 331 <form name="checkout" method="post" class="rtsb-woocommerce-checkout checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data">
323 332 <?php
324 333 }
325 334 }
@@ -341,8 +350,11 @@
341 350 do_action( 'elementor/page_templates/header-footer/after_content' );
342 351 }
343 352
344 353 if ( BuilderFns::is_checkout() ) {
354 + if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) {
355 + return;
356 + }
345 357 ?>
346 358 </form>
347 359 <?php
348 360 }
@@ -357,22 +369,26 @@
357 369 *
358 370 * @return void
359 371 */
360 372 public function select2_ajax_posts_filter_autocomplete() {
361 -
373 + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
374 + wp_send_json_error( [] );
375 + }
362 376 $query_per_page = 15;
363 377 $post_type = 'post';
364 378 $source_name = 'post_type';
365 - $paged = $_POST['page'] ?? 1;
366 -
379 + $paged = absint( $_POST['page'] ?? 1 );
367 380 if ( ! empty( $_POST['post_type'] ) ) {
381 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
368 382 $post_type = sanitize_text_field( $_POST['post_type'] );
369 383 }
370 384
371 385 if ( ! empty( $_POST['source_name'] ) ) {
386 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
372 387 $source_name = sanitize_text_field( $_POST['source_name'] );
373 388 }
374 389
390 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
375 391 $search = ! empty( $_POST['search'] ) ? sanitize_text_field( $_POST['search'] ) : '';
376 392 $results = $post_list = [];
377 393 switch ( $source_name ) {
378 394 case 'taxonomy':
@@ -432,17 +448,22 @@
432 448 * @return void
433 449 */
434 450 public function select2_ajax_get_posts_value_titles() {
435 451
452 + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
453 + wp_send_json_error( [] );
454 + }
455 +
436 456 if ( empty( $_POST['id'] ) ) {
437 457 wp_send_json_error( [] );
438 458 }
439 459
460 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
440 461 if ( empty( array_filter( $_POST['id'] ) ) ) {
441 462 wp_send_json_error( [] );
442 463 }
443 464 $ids = array_map( 'intval', $_POST['id'] );
444 - $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : '';
465 + $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
445 466
446 467 switch ( $source_name ) {
447 468 case 'taxonomy':
448 469 $args = [
@@ -451,9 +472,11 @@
451 472 'order' => 'ASC',
452 473 'include' => implode( ',', $ids ),
453 474 ];
454 475
476 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
455 477 if ( $_POST['post_type'] !== 'all' ) {
478 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
456 479 $args['taxonomy'] = sanitize_text_field( $_POST['post_type'] );
457 480 }
458 481
459 482 $response = wp_list_pluck( get_terms( $args ), 'name', 'term_id' );
@@ -471,9 +494,9 @@
471 494 break;
472 495 default:
473 496 $post_info = get_posts(
474 497 [
475 - 'post_type' => sanitize_text_field( $_POST['post_type'] ),
498 + 'post_type' => sanitize_text_field( $_POST['post_type'] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
476 499 'include' => implode( ',', $ids ),
477 500 ]
478 501 );
479 502 $response = wp_list_pluck( $post_info, 'post_title', 'ID' );
@@ -531,10 +554,19 @@
531 554 if ( ! empty( $search ) ) {
532 555 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title LIKE %s", '%' . esc_sql( $search ) . '%' );
533 556 }
534 557
558 + // Add a query for shop_coupon post-type to check 'show on frontend' meta.
559 + if ( 'shop_coupon' === $post_type ) {
560 + $where .= " AND {$wpdb->posts}.ID IN (
561 + SELECT post_id FROM {$wpdb->postmeta}
562 + WHERE meta_key = 'rtsb_show_on_frontend'
563 + AND meta_value = 'on'
564 + )";
565 + }
566 +
535 567 $query = "select post_title,ID from $wpdb->posts where post_status = 'publish' {$where} {$limit}";
536 - $results = $wpdb->get_results( $query );
568 + $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching
537 569
538 570 if ( ! empty( $results ) ) {
539 571 foreach ( $results as $row ) {
540 572 $data[ $row->ID ] = $row->post_title . ' [#' . $row->ID . ']';
@@ -565,10 +597,10 @@
565 597
566 598 $pro_widgets = [
567 599 [
568 600 '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' ),
601 + 'title' => esc_html__( 'Ajax Product Filters', 'shopbuilder' ),
602 + 'description' => esc_html__( 'Ajax Product Filters', 'shopbuilder' ),
571 603 'icon' => 'rtsb-el-custom rtsb-element icon-rtsb-ajax-product-filters rtsb-promotional-element',
572 604 'categories' => '[ "rtsb-shopbuilder" ]',
573 605 ],
574 606 ];
@@ -579,6 +611,49 @@
579 611 }
580 612 }
581 613
582 614 return $config;
615 + }
616 +
617 + /**
618 + * Get Icons.
619 + *
620 + * @return array
621 + */
622 + public function get_icons() {
623 + return [
624 + 'heart-empty',
625 + 'heart',
626 + 'eye',
627 + 'exchange',
628 + 'plus',
629 + 'minus',
630 + 'avatar',
631 + 'pay',
632 + 'share',
633 + 'clock',
634 + 'check-alt',
635 + 'check',
636 + 'delete',
637 + 'marker',
638 + 'list',
639 + 'list-2',
640 + 'power',
641 + 'cart',
642 + 'cart-2',
643 + 'cart-3',
644 + 'downloads',
645 + 'zoom',
646 + 'user-edit',
647 + 'grid',
648 + 'filter',
649 + 'billing',
650 + 'login',
651 + 'payment',
652 + 'search',
653 + 'edit',
654 + 'coupon',
655 + 'arrows-cw',
656 + 'trash-empty',
657 + ];
583 658 }
584 659 }