PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.6.3
ShopBuilder – WooCommerce Builder For Elementor v2.6.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 +59 -109 3.4.02.6.3 View file →
@@ -8,14 +8,14 @@
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\ElementList;
13 12 use RadiusTheme\SB\Traits\SingletonTrait;
14 13 use RadiusTheme\SB\Controllers\Builder\BuilderCpt;
15 14 use RadiusTheme\SB\Controllers\Hooks\BuilderHooks;
16 15 use RadiusTheme\SB\Elementor\Controls\ImageSelectorControl;
17 16 use RadiusTheme\SB\Elementor\Controls\Select2AjaxControl;
17 +use RadiusTheme\SB\Models\ElementList;
18 18
19 19 // Do not allow directly accessing this file.
20 20 if ( ! defined( 'ABSPATH' ) ) {
21 21 exit( 'This script cannot be accessed directly.' );
@@ -54,8 +54,9 @@
54 54 */
55 55 private function __construct() {
56 56 $this->builder_page_id = BuilderFns::builder_page_id_by_page();
57 57 $this->page_edit_with = Fns::page_edit_with( $this->builder_page_id );
58 +
58 59 if ( ! is_admin() ) {
59 60 BuilderHooks::instance();
60 61 }
61 62
@@ -88,20 +89,13 @@
88 89 *
89 90 * @return void
90 91 */
91 92 public function elementor_init() {
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 - );
93 + add_action( 'elementor/elements/categories_registered', [ $this, 'add_elementor_widget_categories' ] );
94 + add_action( 'elementor/widgets/register', [ $this, 'init_widgets' ] );
95 + add_action( 'elementor/controls/register', [ $this, 'init_controls' ] );
96 + add_filter( 'elementor/editor/localize_settings', [ $this, 'promotePremiumWidgets' ] );
97 + add_action( 'elementor/icons_manager/additional_tabs', [ $this, 'rtsb_icons' ] );
104 98 }
105 99
106 100 /**
107 101 * Register Category
@@ -115,9 +109,9 @@
115 109 $builder_id = get_queried_object_id();
116 110 $id = Fns::wpml_object_id( $builder_id, BuilderFns::$post_type_tb, 'default' );
117 111 $type = BuilderFns::builder_type( $id );
118 112
119 - if ( $type && 'popup-builder' !== $type ) {
113 + if ( $type ) {
120 114 $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : '';
121 115 $builder_type = str_replace( [ 'My Account - ', 'Endpoint: ' ], '', $builder_type );
122 116 $categories['rtsb-shopbuilder'] = [
123 117 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ),
@@ -162,14 +156,10 @@
162 156
163 157 /**
164 158 * Init Widgets
165 159 *
166 - * Include widget files and register them
160 + * Include widgets files and register them
167 161 *
168 - * @param object $widgets_manager Widgets Manager.
169 - *
170 - * @return void
171 - *
172 162 * @since 1.0.0
173 163 */
174 164 public function init_widgets( $widgets_manager ) {
175 165
@@ -187,24 +177,45 @@
187 177 continue;
188 178 }
189 179
190 180 if ( ! empty( $element['category'] ) ) {
191 - try {
192 - $widget = false;
193 - $import = apply_filters( 'rtsb_import_status', false );
194 -
195 - if ( $this->should_register_widget( $element['category'], $import ) ) {
181 + $widget = false;
182 + $import = apply_filters( 'rtsb_import_status', false );
183 + switch ( $element['category'] ) {
184 + case 'product':
185 + if ( BuilderFns::is_product() || $import ) {
186 + $widget = new $element['base_class']();
187 + }
188 + break;
189 + case 'shop':
190 + if ( BuilderFns::is_archive() || BuilderFns::is_shop() || $import ) {
191 + $widget = new $element['base_class']();
192 + }
193 + break;
194 + case 'archive':
195 + if ( BuilderFns::is_archive() || $import ) {
196 + $widget = new $element['base_class']();
197 + }
198 + break;
199 + case 'cart':
200 + if ( BuilderFns::is_cart() || $import ) {
201 + $widget = new $element['base_class']();
202 + }
203 + break;
204 + case 'checkout':
205 + if ( BuilderFns::is_checkout() || $import ) {
206 + $widget = new $element['base_class']();
207 + }
208 + break;
209 + case 'general':
196 210 $widget = new $element['base_class']();
197 - }
211 + break;
212 + default:
213 + }
214 + $widget = apply_filters( 'rtsb/element/list/init/widgets', $widget, $element );
198 215
199 - $widget = apply_filters( 'rtsb/element/list/init/widgets', $widget, $element );
200 -
201 - if ( $widget && is_object( $widget ) ) {
202 - $widgets_manager->register( $widget );
203 - }
204 - } catch ( \Throwable $e ) {
205 - error_log( 'ShopBuilder widget error (' . $element['base_class'] . '): ' . $e->getMessage() ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
206 - continue;
216 + if ( $widget && is_object( $widget ) ) {
217 + $widgets_manager->register( $widget );
207 218 }
208 219 }
209 220 }
210 221 }
@@ -209,36 +220,8 @@
209 220 }
210 221 }
211 222
212 223 /**
213 - * Determine whether a widget for the given category should be registered
214 - * in the current request context.
215 - *
216 - * @param string $category Element category.
217 - * @param bool $import Whether an import is in progress.
218 - *
219 - * @return bool
220 - */
221 - protected function should_register_widget( $category, $import ) {
222 - switch ( $category ) {
223 - case 'product':
224 - return BuilderFns::is_product() || $import;
225 - case 'shop':
226 - return BuilderFns::is_archive() || BuilderFns::is_shop() || $import;
227 - case 'archive':
228 - return BuilderFns::is_archive() || $import;
229 - case 'cart':
230 - return BuilderFns::is_cart() || $import;
231 - case 'checkout':
232 - return BuilderFns::is_checkout() || $import;
233 - case 'general':
234 - return true;
235 - default:
236 - return false;
237 - }
238 - }
239 -
240 - /**
241 224 * Adding custom icons in Elementor
242 225 *
243 226 * @param array $tabs Tabs.
244 227 *
@@ -303,26 +286,18 @@
303 286 *
304 287 * @since 2.0.0
305 288 */
306 289 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
307 - do_action( 'elementor/page_templates/header-footer/before_content' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
290 + do_action( 'elementor/page_templates/header-footer/before_content' );
308 291 }
309 292
310 293 $parent_class = apply_filters( 'rtsb/builder/content/parent_class', [] );
311 294
312 295 if ( BuilderFns::is_product() ) {
313 - $product_id = Fns::get_prepared_product_id();
314 -
315 - // Ensure the WordPress global $product is a valid WC_Product before
316 - // wc_get_product_class() fires the `woocommerce_post_class` filter.
317 - // Some themes (e.g. Blocksy) read the global $product directly inside
318 - // that filter and call methods like get_type() on it, which throws a
319 - // fatal error when the global is still an unresolved string.
320 - $_product = Fns::get_product();
321 -
296 + $product_id = Fns::get_prepared_product_id();
322 297 $parent_class = wc_get_product_class( $parent_class, $product_id );
323 -
324 - if ( function_exists( 'rtwpvs' ) && $_product instanceof \WC_Product ) {
298 + if ( function_exists( 'rtwpvs' ) ) {
299 + $_product = Fns::get_product();
325 300 if ( $_product->is_type( 'variable' ) ) {
326 301 $parent_class[] = 'rtwpvs-product';
327 302 $beside_label = function_exists( 'rtwpvsp' ) && rtwpvs()->get_option( 'attribute_on_click_behavior' );
328 303 if ( $beside_label ) {
@@ -351,34 +326,10 @@
351 326 if ( BuilderFns::is_checkout() ) {
352 327 if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) {
353 328 return;
354 329 }
355 -
356 - $checkout = WC()->checkout();
357 -
358 - // Temporarily remove callbacks that Elementor checkout
359 - // handles via separate widgets to prevent duplicates.
360 - remove_action( 'woocommerce_before_checkout_form', [ Hooks\ActionHooks::class, 'woocommerce_checkout_login_form' ], 10 );
361 - remove_action( 'woocommerce_before_checkout_form', [ Hooks\ActionHooks::class, 'woocommerce_checkout_coupon_form' ], 10 );
362 - remove_action( 'woocommerce_before_checkout_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
363 -
364 - do_action( 'woocommerce_before_checkout_form', $checkout );
365 -
366 - // Restore callbacks for non-Elementor contexts.
367 - add_action( 'woocommerce_before_checkout_form', [ Hooks\ActionHooks::class, 'woocommerce_checkout_login_form' ], 10 );
368 - add_action( 'woocommerce_before_checkout_form', [ Hooks\ActionHooks::class, 'woocommerce_checkout_coupon_form' ], 10 );
369 - add_action( 'woocommerce_before_checkout_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
370 -
371 - // If checkout registration is disabled and not logged in, the user cannot checkout.
372 - if ( ! $checkout->is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) {
373 - echo esc_html( apply_filters( 'woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'shopbuilder' ) ) );
374 - return;
375 - }
376 330 ?>
377 - <!--
378 - woocommerce-checkout added for fix issue with payment method ( Revolut Pay )
379 - -->
380 - <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">
331 + <form name="checkout" method="post" class="rtsb-woocommerce-checkout checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data">
381 332 <?php
382 333 }
383 334 }
384 335
@@ -395,9 +346,9 @@
395 346 *
396 347 * @since 2.0.0
397 348 */
398 349 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
399 - do_action( 'elementor/page_templates/header-footer/after_content' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
350 + do_action( 'elementor/page_templates/header-footer/after_content' );
400 351 }
401 352
402 353 if ( BuilderFns::is_checkout() ) {
403 354 if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) {
@@ -405,9 +356,8 @@
405 356 }
406 357 ?>
407 358 </form>
408 359 <?php
409 - do_action( 'woocommerce_after_checkout_form', WC()->checkout() );
410 360 }
411 361 ?>
412 362 </div>
413 363 <!-- After Content end -->
@@ -438,9 +388,9 @@
438 388 }
439 389
440 390 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
441 391 $search = ! empty( $_POST['search'] ) ? sanitize_text_field( $_POST['search'] ) : '';
442 - $results = $post_list = []; // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
392 + $results = $post_list = [];
443 393 switch ( $source_name ) {
444 394 case 'taxonomy':
445 395 $args = [
446 396 'hide_empty' => false,
@@ -445,13 +395,13 @@
445 395 $args = [
446 396 'hide_empty' => false,
447 397 'orderby' => 'name',
448 398 'order' => 'ASC',
449 - 'name__like' => $search,
399 + 'search' => $search,
450 400 'number' => '5',
451 401 ];
452 402
453 - if ( 'all' !== $post_type ) {
403 + if ( $post_type !== 'all' ) {
454 404 $args['taxonomy'] = $post_type;
455 405 }
456 406
457 407 $post_list = wp_list_pluck( get_terms( $args ), 'name', 'term_id' );
@@ -523,10 +473,10 @@
523 473 'include' => implode( ',', $ids ),
524 474 ];
525 475
526 476 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
527 - if ( 'all' !== $_POST['post_type'] ) {
528 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
477 + if ( $_POST['post_type'] !== 'all' ) {
478 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
529 479 $args['taxonomy'] = sanitize_text_field( $_POST['post_type'] );
530 480 }
531 481
532 482 $response = wp_list_pluck( get_terms( $args ), 'name', 'term_id' );
@@ -562,12 +512,12 @@
562 512
563 513 /**
564 514 * Ajax callback for rt-select2
565 515 *
566 - * @param string $post_type Post type.
567 - * @param int $limit Limit.
568 - * @param string $search Search.
569 - * @param int $paged Paged.
516 + * @param $post_type
517 + * @param $limit
518 + * @param $search
519 + * @param $paged
570 520 *
571 521 * @return array
572 522 */
573 523 public function get_query_data( $post_type = 'any', $limit = 10, $search = '', $paged = 1 ) {