PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.1.3
ShopBuilder – WooCommerce Builder For Elementor v3.1.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/BuilderController.php +111 -53 2.1.03.1.3 View file →
@@ -8,14 +8,15 @@
8 8 namespace RadiusTheme\SB\Controllers;
9 9
10 10 use RadiusTheme\SB\Helpers\Fns;
11 11 use RadiusTheme\SB\Helpers\BuilderFns;
12 +use RadiusTheme\SB\Models\GeneralList;
13 +use RadiusTheme\SB\Models\ElementList;
12 14 use RadiusTheme\SB\Traits\SingletonTrait;
13 15 use RadiusTheme\SB\Controllers\Builder\BuilderCpt;
14 16 use RadiusTheme\SB\Controllers\Hooks\BuilderHooks;
15 17 use RadiusTheme\SB\Elementor\Controls\ImageSelectorControl;
16 18 use RadiusTheme\SB\Elementor\Controls\Select2AjaxControl;
17 -use RadiusTheme\SB\Models\ElementList;
18 19
19 20 // Do not allow directly accessing this file.
20 21 if ( ! defined( 'ABSPATH' ) ) {
21 22 exit( 'This script cannot be accessed directly.' );
@@ -60,22 +61,19 @@
60 61 BuilderHooks::instance();
61 62 }
62 63
63 64 BuilderCpt::instance();
64 -
65 - $this->elementor_init();
66 - $this->both_builder_frontend();
67 -
68 - // add_action( 'elementor/init', [ $this, 'elementor_init' ] );
69 - add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'editor_scripts' ] );
70 - // add_action( 'template_redirect', [ $this, 'both_builder_frontend' ], 99 );
71 -
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 + }
72 70 // RT Select2 Ajax.
73 - add_action( 'wp_ajax_rt_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] );
74 - 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' ] );
75 73 // Select2 ajax save data.
76 - add_action( 'wp_ajax_rt_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] );
77 - 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' ] );
78 76 }
79 77
80 78 /**
81 79 * Apply for frontend.
@@ -92,13 +90,20 @@
92 90 *
93 91 * @return void
94 92 */
95 93 public function elementor_init() {
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' ] );
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 + );
101 106 }
102 107
103 108 /**
104 109 * Register Category
@@ -107,21 +112,29 @@
107 112 *
108 113 * @return void
109 114 */
110 115 public function add_elementor_widget_categories( $elements_manager ) {
111 - $type = BuilderFns::builder_type( get_the_ID() );
112 - $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : '';
113 - $builder_type = str_replace( 'My Account - ', '', $builder_type );
114 - $categories['rtsb-shopbuilder'] = [
115 - 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ),
116 - 'icon' => 'fa fa-plug',
117 - ];
118 - $categories['rtsb-shopbuilder-general'] = [
119 - 'title' => esc_html__( 'Shopbuilder - General', 'shopbuilder' ),
120 - 'icon' => 'fa fa-plug',
121 - ];
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 );
122 120
123 - $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 +
124 137 $other_categories = $elements_manager->get_categories();
125 138 $categories = array_merge(
126 139 array_slice( $other_categories, 0, 1 ),
127 140 $categories,
@@ -127,10 +140,10 @@
127 140 $categories,
128 141 array_slice( $other_categories, 1 )
129 142 );
130 143
131 - $set_categories = function ( $categories ) {
132 - $this->categories = $categories;
144 + $set_categories = function ( $categories ) use ( $elements_manager ) {
145 + $elements_manager->categories = $categories;
133 146 };
134 147
135 148 $set_categories->call( $elements_manager, $categories );
136 149 }
@@ -151,10 +164,14 @@
151 164
152 165 /**
153 166 * Init Widgets
154 167 *
155 - * Include widgets files and register them
168 + * Include widget files and register them
156 169 *
170 + * @param object $widgets_manager Widgets Manager.
171 + *
172 + * @return void
173 + *
157 174 * @since 1.0.0
158 175 */
159 176 public function init_widgets( $widgets_manager ) {
160 177
@@ -222,9 +239,9 @@
222 239 *
223 240 * @return array
224 241 */
225 242 public function rtsb_icons( $tabs = [] ) {
226 - $custom_icons = $this->get_icons();
243 + $custom_icons = Fns::get_custom_icon_names();
227 244
228 245 $tabs['shopbuilder-icons'] = [
229 246 'name' => 'rtsb-fonts',
230 247 'label' => esc_html__( 'ShopBuilder Icons', 'shopbuilder' ),
@@ -281,9 +298,9 @@
281 298 *
282 299 * @since 2.0.0
283 300 */
284 301 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
285 - 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
286 303 }
287 304
288 305 $parent_class = apply_filters( 'rtsb/builder/content/parent_class', [] );
289 306
@@ -289,8 +306,18 @@
289 306
290 307 if ( BuilderFns::is_product() ) {
291 308 $product_id = Fns::get_prepared_product_id();
292 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 + }
293 320 }
294 321
295 322 if ( BuilderFns::is_shop() ) {
296 323 $parent_class[] = 'shop';
@@ -306,10 +333,18 @@
306 333
307 334 ?>
308 335 <!-- Before Content start -->
309 336 <div class="<?php echo esc_attr( implode( ' ', $parent_class ) ); ?>">
310 - <?php if ( BuilderFns::is_checkout() ) { ?>
311 - <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">
312 347 <?php
313 348 }
314 349 }
315 350
@@ -326,12 +361,15 @@
326 361 *
327 362 * @since 2.0.0
328 363 */
329 364 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
330 - 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
331 366 }
332 367
333 368 if ( BuilderFns::is_checkout() ) {
369 + if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) {
370 + return;
371 + }
334 372 ?>
335 373 </form>
336 374 <?php
337 375 }
@@ -346,24 +384,28 @@
346 384 *
347 385 * @return void
348 386 */
349 387 public function select2_ajax_posts_filter_autocomplete() {
350 -
388 + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
389 + wp_send_json_error( [] );
390 + }
351 391 $query_per_page = 15;
352 392 $post_type = 'post';
353 393 $source_name = 'post_type';
354 - $paged = $_POST['page'] ?? 1;
355 -
394 + $paged = absint( $_POST['page'] ?? 1 );
356 395 if ( ! empty( $_POST['post_type'] ) ) {
396 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
357 397 $post_type = sanitize_text_field( $_POST['post_type'] );
358 398 }
359 399
360 400 if ( ! empty( $_POST['source_name'] ) ) {
401 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
361 402 $source_name = sanitize_text_field( $_POST['source_name'] );
362 403 }
363 404
405 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
364 406 $search = ! empty( $_POST['search'] ) ? sanitize_text_field( $_POST['search'] ) : '';
365 - $results = $post_list = [];
407 + $results = $post_list = []; // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
366 408 switch ( $source_name ) {
367 409 case 'taxonomy':
368 410 $args = [
369 411 'hide_empty' => false,
@@ -372,9 +414,9 @@
372 414 'search' => $search,
373 415 'number' => '5',
374 416 ];
375 417
376 - if ( $post_type !== 'all' ) {
418 + if ( 'all' !== $post_type ) {
377 419 $args['taxonomy'] = $post_type;
378 420 }
379 421
380 422 $post_list = wp_list_pluck( get_terms( $args ), 'name', 'term_id' );
@@ -421,17 +463,22 @@
421 463 * @return void
422 464 */
423 465 public function select2_ajax_get_posts_value_titles() {
424 466
467 + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
468 + wp_send_json_error( [] );
469 + }
470 +
425 471 if ( empty( $_POST['id'] ) ) {
426 472 wp_send_json_error( [] );
427 473 }
428 474
475 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
429 476 if ( empty( array_filter( $_POST['id'] ) ) ) {
430 477 wp_send_json_error( [] );
431 478 }
432 479 $ids = array_map( 'intval', $_POST['id'] );
433 - $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
434 481
435 482 switch ( $source_name ) {
436 483 case 'taxonomy':
437 484 $args = [
@@ -440,9 +487,11 @@
440 487 'order' => 'ASC',
441 488 'include' => implode( ',', $ids ),
442 489 ];
443 490
444 - 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
445 494 $args['taxonomy'] = sanitize_text_field( $_POST['post_type'] );
446 495 }
447 496
448 497 $response = wp_list_pluck( get_terms( $args ), 'name', 'term_id' );
@@ -460,9 +509,9 @@
460 509 break;
461 510 default:
462 511 $post_info = get_posts(
463 512 [
464 - '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
465 514 'include' => implode( ',', $ids ),
466 515 ]
467 516 );
468 517 $response = wp_list_pluck( $post_info, 'post_title', 'ID' );
@@ -478,12 +527,12 @@
478 527
479 528 /**
480 529 * Ajax callback for rt-select2
481 530 *
482 - * @param $post_type
483 - * @param $limit
484 - * @param $search
485 - * @param $paged
531 + * @param string $post_type Post type.
532 + * @param int $limit Limit.
533 + * @param string $search Search.
534 + * @param int $paged Paged.
486 535 *
487 536 * @return array
488 537 */
489 538 public function get_query_data( $post_type = 'any', $limit = 10, $search = '', $paged = 1 ) {
@@ -520,10 +569,19 @@
520 569 if ( ! empty( $search ) ) {
521 570 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title LIKE %s", '%' . esc_sql( $search ) . '%' );
522 571 }
523 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 +
524 582 $query = "select post_title,ID from $wpdb->posts where post_status = 'publish' {$where} {$limit}";
525 - $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
526 584
527 585 if ( ! empty( $results ) ) {
528 586 foreach ( $results as $row ) {
529 587 $data[ $row->ID ] = $row->post_title . ' [#' . $row->ID . ']';
@@ -554,10 +612,10 @@
554 612
555 613 $pro_widgets = [
556 614 [
557 615 'name' => 'rtsb-ajax-product-filters',
558 - 'title' => esc_html__( 'Ajax Product Filters', 'testimonial-slider-showcase' ),
559 - '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' ),
560 618 'icon' => 'rtsb-el-custom rtsb-element icon-rtsb-ajax-product-filters rtsb-promotional-element',
561 619 'categories' => '[ "rtsb-shopbuilder" ]',
562 620 ],
563 621 ];