PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.1.0
ShopBuilder – WooCommerce Builder For Elementor v3.1.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 +98 -52 2.1.23.1.0 View file →
@@ -8,15 +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 -use RadiusTheme\SBPRO\Helpers\FnsPro;
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.' );
@@ -61,22 +61,19 @@
61 61 BuilderHooks::instance();
62 62 }
63 63
64 64 BuilderCpt::instance();
65 -
66 - $this->elementor_init();
67 - $this->both_builder_frontend();
68 -
69 - // add_action( 'elementor/init', [ $this, 'elementor_init' ] );
70 - add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'editor_scripts' ] );
71 - // add_action( 'template_redirect', [ $this, 'both_builder_frontend' ], 99 );
72 -
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 + }
73 70 // RT Select2 Ajax.
74 - add_action( 'wp_ajax_rt_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] );
75 - 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' ] );
76 73 // Select2 ajax save data.
77 - add_action( 'wp_ajax_rt_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] );
78 - 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' ] );
79 76 }
80 77
81 78 /**
82 79 * Apply for frontend.
@@ -93,13 +90,20 @@
93 90 *
94 91 * @return void
95 92 */
96 93 public function elementor_init() {
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' ] );
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 + );
102 106 }
103 107
104 108 /**
105 109 * Register Category
@@ -108,21 +112,29 @@
108 112 *
109 113 * @return void
110 114 */
111 115 public function add_elementor_widget_categories( $elements_manager ) {
112 - $type = BuilderFns::builder_type( get_the_ID() );
113 - $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : '';
114 - $builder_type = str_replace( 'My Account - ', '', $builder_type );
115 - $categories['rtsb-shopbuilder'] = [
116 - 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ),
117 - 'icon' => 'fa fa-plug',
118 - ];
119 - $categories['rtsb-shopbuilder-general'] = [
120 - 'title' => esc_html__( 'Shopbuilder - General', 'shopbuilder' ),
121 - 'icon' => 'fa fa-plug',
122 - ];
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 );
123 120
124 - $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 +
125 137 $other_categories = $elements_manager->get_categories();
126 138 $categories = array_merge(
127 139 array_slice( $other_categories, 0, 1 ),
128 140 $categories,
@@ -128,10 +140,10 @@
128 140 $categories,
129 141 array_slice( $other_categories, 1 )
130 142 );
131 143
132 - $set_categories = function ( $categories ) {
133 - $this->categories = $categories;
144 + $set_categories = function ( $categories ) use ( $elements_manager ) {
145 + $elements_manager->categories = $categories;
134 146 };
135 147
136 148 $set_categories->call( $elements_manager, $categories );
137 149 }
@@ -152,10 +164,14 @@
152 164
153 165 /**
154 166 * Init Widgets
155 167 *
156 - * Include widgets files and register them
168 + * Include widget files and register them
157 169 *
170 + * @param object $widgets_manager Widgets Manager.
171 + *
172 + * @return void
173 + *
158 174 * @since 1.0.0
159 175 */
160 176 public function init_widgets( $widgets_manager ) {
161 177
@@ -223,9 +239,9 @@
223 239 *
224 240 * @return array
225 241 */
226 242 public function rtsb_icons( $tabs = [] ) {
227 - $custom_icons = $this->get_icons();
243 + $custom_icons = Fns::get_custom_icon_names();
228 244
229 245 $tabs['shopbuilder-icons'] = [
230 246 'name' => 'rtsb-fonts',
231 247 'label' => esc_html__( 'ShopBuilder Icons', 'shopbuilder' ),
@@ -282,9 +298,9 @@
282 298 *
283 299 * @since 2.0.0
284 300 */
285 301 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
286 - 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
287 303 }
288 304
289 305 $parent_class = apply_filters( 'rtsb/builder/content/parent_class', [] );
290 306
@@ -290,8 +306,18 @@
290 306
291 307 if ( BuilderFns::is_product() ) {
292 308 $product_id = Fns::get_prepared_product_id();
293 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 + }
294 320 }
295 321
296 322 if ( BuilderFns::is_shop() ) {
297 323 $parent_class[] = 'shop';
@@ -332,9 +358,9 @@
332 358 *
333 359 * @since 2.0.0
334 360 */
335 361 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
336 - do_action( 'elementor/page_templates/header-footer/after_content' );
362 + do_action( 'elementor/page_templates/header-footer/after_content' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
337 363 }
338 364
339 365 if ( BuilderFns::is_checkout() ) {
340 366 if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) {
@@ -355,24 +381,28 @@
355 381 *
356 382 * @return void
357 383 */
358 384 public function select2_ajax_posts_filter_autocomplete() {
359 -
385 + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
386 + wp_send_json_error( [] );
387 + }
360 388 $query_per_page = 15;
361 389 $post_type = 'post';
362 390 $source_name = 'post_type';
363 - $paged = $_POST['page'] ?? 1;
364 -
391 + $paged = absint( $_POST['page'] ?? 1 );
365 392 if ( ! empty( $_POST['post_type'] ) ) {
393 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
366 394 $post_type = sanitize_text_field( $_POST['post_type'] );
367 395 }
368 396
369 397 if ( ! empty( $_POST['source_name'] ) ) {
398 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
370 399 $source_name = sanitize_text_field( $_POST['source_name'] );
371 400 }
372 401
402 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
373 403 $search = ! empty( $_POST['search'] ) ? sanitize_text_field( $_POST['search'] ) : '';
374 - $results = $post_list = [];
404 + $results = $post_list = []; // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
375 405 switch ( $source_name ) {
376 406 case 'taxonomy':
377 407 $args = [
378 408 'hide_empty' => false,
@@ -381,9 +411,9 @@
381 411 'search' => $search,
382 412 'number' => '5',
383 413 ];
384 414
385 - if ( $post_type !== 'all' ) {
415 + if ( 'all' !== $post_type ) {
386 416 $args['taxonomy'] = $post_type;
387 417 }
388 418
389 419 $post_list = wp_list_pluck( get_terms( $args ), 'name', 'term_id' );
@@ -430,17 +460,22 @@
430 460 * @return void
431 461 */
432 462 public function select2_ajax_get_posts_value_titles() {
433 463
464 + if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) {
465 + wp_send_json_error( [] );
466 + }
467 +
434 468 if ( empty( $_POST['id'] ) ) {
435 469 wp_send_json_error( [] );
436 470 }
437 471
472 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
438 473 if ( empty( array_filter( $_POST['id'] ) ) ) {
439 474 wp_send_json_error( [] );
440 475 }
441 476 $ids = array_map( 'intval', $_POST['id'] );
442 - $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : '';
477 + $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
443 478
444 479 switch ( $source_name ) {
445 480 case 'taxonomy':
446 481 $args = [
@@ -449,9 +484,11 @@
449 484 'order' => 'ASC',
450 485 'include' => implode( ',', $ids ),
451 486 ];
452 487
453 - if ( $_POST['post_type'] !== 'all' ) {
488 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
489 + if ( 'all' !== $_POST['post_type'] ) {
490 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
454 491 $args['taxonomy'] = sanitize_text_field( $_POST['post_type'] );
455 492 }
456 493
457 494 $response = wp_list_pluck( get_terms( $args ), 'name', 'term_id' );
@@ -469,9 +506,9 @@
469 506 break;
470 507 default:
471 508 $post_info = get_posts(
472 509 [
473 - 'post_type' => sanitize_text_field( $_POST['post_type'] ),
510 + 'post_type' => sanitize_text_field( $_POST['post_type'] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
474 511 'include' => implode( ',', $ids ),
475 512 ]
476 513 );
477 514 $response = wp_list_pluck( $post_info, 'post_title', 'ID' );
@@ -487,12 +524,12 @@
487 524
488 525 /**
489 526 * Ajax callback for rt-select2
490 527 *
491 - * @param $post_type
492 - * @param $limit
493 - * @param $search
494 - * @param $paged
528 + * @param string $post_type Post type.
529 + * @param int $limit Limit.
530 + * @param string $search Search.
531 + * @param int $paged Paged.
495 532 *
496 533 * @return array
497 534 */
498 535 public function get_query_data( $post_type = 'any', $limit = 10, $search = '', $paged = 1 ) {
@@ -529,10 +566,19 @@
529 566 if ( ! empty( $search ) ) {
530 567 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title LIKE %s", '%' . esc_sql( $search ) . '%' );
531 568 }
532 569
570 + // Add a query for shop_coupon post-type to check 'show on frontend' meta.
571 + if ( 'shop_coupon' === $post_type ) {
572 + $where .= " AND {$wpdb->posts}.ID IN (
573 + SELECT post_id FROM {$wpdb->postmeta}
574 + WHERE meta_key = 'rtsb_show_on_frontend'
575 + AND meta_value = 'on'
576 + )";
577 + }
578 +
533 579 $query = "select post_title,ID from $wpdb->posts where post_status = 'publish' {$where} {$limit}";
534 - $results = $wpdb->get_results( $query );
580 + $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching
535 581
536 582 if ( ! empty( $results ) ) {
537 583 foreach ( $results as $row ) {
538 584 $data[ $row->ID ] = $row->post_title . ' [#' . $row->ID . ']';
@@ -563,10 +609,10 @@
563 609
564 610 $pro_widgets = [
565 611 [
566 612 'name' => 'rtsb-ajax-product-filters',
567 - 'title' => esc_html__( 'Ajax Product Filters', 'testimonial-slider-showcase' ),
568 - 'description' => esc_html__( 'Ajax Product Filters', 'testimonial-slider-showcase' ),
613 + 'title' => esc_html__( 'Ajax Product Filters', 'shopbuilder' ),
614 + 'description' => esc_html__( 'Ajax Product Filters', 'shopbuilder' ),
569 615 'icon' => 'rtsb-el-custom rtsb-element icon-rtsb-ajax-product-filters rtsb-promotional-element',
570 616 'categories' => '[ "rtsb-shopbuilder" ]',
571 617 ],
572 618 ];