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 +59 -121 3.4.12.6.2 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,48 +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 - // On the frontend the Elementor Widgets Manager can initialise at an
223 - // unpredictable time — e.g. Elementor Pro's Theme Builder boots it on
224 - // template_redirect — when WooCommerce query conditionals such as
225 - // is_shop()/is_archive() are not yet reliable. Widget registration is
226 - // cached for the whole request, so gating it by those conditionals can
227 - // permanently skip ShopBuilder widgets, leaving the builder template to
228 - // render empty container shells. Register unconditionally on the
229 - // frontend; keep the per-category gate only for the editor widget panel.
230 - if ( ! is_admin() ) {
231 - return true;
232 - }
233 -
234 - switch ( $category ) {
235 - case 'product':
236 - return BuilderFns::is_product() || $import;
237 - case 'shop':
238 - return BuilderFns::is_archive() || BuilderFns::is_shop() || $import;
239 - case 'archive':
240 - return BuilderFns::is_archive() || $import;
241 - case 'cart':
242 - return BuilderFns::is_cart() || $import;
243 - case 'checkout':
244 - return BuilderFns::is_checkout() || $import;
245 - case 'general':
246 - return true;
247 - default:
248 - return false;
249 - }
250 - }
251 -
252 - /**
253 224 * Adding custom icons in Elementor
254 225 *
255 226 * @param array $tabs Tabs.
256 227 *
@@ -315,26 +286,18 @@
315 286 *
316 287 * @since 2.0.0
317 288 */
318 289 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
319 - 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' );
320 291 }
321 292
322 293 $parent_class = apply_filters( 'rtsb/builder/content/parent_class', [] );
323 294
324 295 if ( BuilderFns::is_product() ) {
325 - $product_id = Fns::get_prepared_product_id();
326 -
327 - // Ensure the WordPress global $product is a valid WC_Product before
328 - // wc_get_product_class() fires the `woocommerce_post_class` filter.
329 - // Some themes (e.g. Blocksy) read the global $product directly inside
330 - // that filter and call methods like get_type() on it, which throws a
331 - // fatal error when the global is still an unresolved string.
332 - $_product = Fns::get_product();
333 -
296 + $product_id = Fns::get_prepared_product_id();
334 297 $parent_class = wc_get_product_class( $parent_class, $product_id );
335 -
336 - if ( function_exists( 'rtwpvs' ) && $_product instanceof \WC_Product ) {
298 + if ( function_exists( 'rtwpvs' ) ) {
299 + $_product = Fns::get_product();
337 300 if ( $_product->is_type( 'variable' ) ) {
338 301 $parent_class[] = 'rtwpvs-product';
339 302 $beside_label = function_exists( 'rtwpvsp' ) && rtwpvs()->get_option( 'attribute_on_click_behavior' );
340 303 if ( $beside_label ) {
@@ -363,34 +326,10 @@
363 326 if ( BuilderFns::is_checkout() ) {
364 327 if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) {
365 328 return;
366 329 }
367 -
368 - $checkout = WC()->checkout();
369 -
370 - // Temporarily remove callbacks that Elementor checkout
371 - // handles via separate widgets to prevent duplicates.
372 - remove_action( 'woocommerce_before_checkout_form', [ Hooks\ActionHooks::class, 'woocommerce_checkout_login_form' ], 10 );
373 - remove_action( 'woocommerce_before_checkout_form', [ Hooks\ActionHooks::class, 'woocommerce_checkout_coupon_form' ], 10 );
374 - remove_action( 'woocommerce_before_checkout_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
375 -
376 - do_action( 'woocommerce_before_checkout_form', $checkout );
377 -
378 - // Restore callbacks for non-Elementor contexts.
379 - add_action( 'woocommerce_before_checkout_form', [ Hooks\ActionHooks::class, 'woocommerce_checkout_login_form' ], 10 );
380 - add_action( 'woocommerce_before_checkout_form', [ Hooks\ActionHooks::class, 'woocommerce_checkout_coupon_form' ], 10 );
381 - add_action( 'woocommerce_before_checkout_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
382 -
383 - // If checkout registration is disabled and not logged in, the user cannot checkout.
384 - if ( ! $checkout->is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) {
385 - echo esc_html( apply_filters( 'woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'shopbuilder' ) ) );
386 - return;
387 - }
388 330 ?>
389 - <!--
390 - woocommerce-checkout added for fix issue with payment method ( Revolut Pay )
391 - -->
392 - <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">
393 332 <?php
394 333 }
395 334 }
396 335
@@ -407,9 +346,9 @@
407 346 *
408 347 * @since 2.0.0
409 348 */
410 349 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
411 - 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' );
412 351 }
413 352
414 353 if ( BuilderFns::is_checkout() ) {
415 354 if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) {
@@ -417,9 +356,8 @@
417 356 }
418 357 ?>
419 358 </form>
420 359 <?php
421 - do_action( 'woocommerce_after_checkout_form', WC()->checkout() );
422 360 }
423 361 ?>
424 362 </div>
425 363 <!-- After Content end -->
@@ -450,9 +388,9 @@
450 388 }
451 389
452 390 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
453 391 $search = ! empty( $_POST['search'] ) ? sanitize_text_field( $_POST['search'] ) : '';
454 - $results = $post_list = []; // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
392 + $results = $post_list = [];
455 393 switch ( $source_name ) {
456 394 case 'taxonomy':
457 395 $args = [
458 396 'hide_empty' => false,
@@ -457,13 +395,13 @@
457 395 $args = [
458 396 'hide_empty' => false,
459 397 'orderby' => 'name',
460 398 'order' => 'ASC',
461 - 'name__like' => $search,
399 + 'search' => $search,
462 400 'number' => '5',
463 401 ];
464 402
465 - if ( 'all' !== $post_type ) {
403 + if ( $post_type !== 'all' ) {
466 404 $args['taxonomy'] = $post_type;
467 405 }
468 406
469 407 $post_list = wp_list_pluck( get_terms( $args ), 'name', 'term_id' );
@@ -535,10 +473,10 @@
535 473 'include' => implode( ',', $ids ),
536 474 ];
537 475
538 476 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
539 - if ( 'all' !== $_POST['post_type'] ) {
540 - // 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
541 479 $args['taxonomy'] = sanitize_text_field( $_POST['post_type'] );
542 480 }
543 481
544 482 $response = wp_list_pluck( get_terms( $args ), 'name', 'term_id' );
@@ -574,12 +512,12 @@
574 512
575 513 /**
576 514 * Ajax callback for rt-select2
577 515 *
578 - * @param string $post_type Post type.
579 - * @param int $limit Limit.
580 - * @param string $search Search.
581 - * @param int $paged Paged.
516 + * @param $post_type
517 + * @param $limit
518 + * @param $search
519 + * @param $paged
582 520 *
583 521 * @return array
584 522 */
585 523 public function get_query_data( $post_type = 'any', $limit = 10, $search = '', $paged = 1 ) {