| @@ -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; | |
| 12 | 13 | use RadiusTheme\SB\Traits\SingletonTrait; |
| 13 | 14 | use RadiusTheme\SB\Controllers\Builder\BuilderCpt; |
| 14 | 15 | use RadiusTheme\SB\Controllers\Hooks\BuilderHooks; |
| 15 | 16 | use RadiusTheme\SB\Elementor\Controls\ImageSelectorControl; |
| 16 | 17 | 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.' ); |
| @@ -60,16 +60,13 @@ | ||
| 60 | 60 | BuilderHooks::instance(); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | 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 | - | |
| 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 | + } | |
| 72 | 69 | // RT Select2 Ajax. |
| 73 | 70 | add_action( 'wp_ajax_rtsb_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); |
| 74 | 71 | add_action( 'wp_ajax_nopriv_rtsb_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); |
| 75 | 72 | // Select2 ajax save data. |
| @@ -92,13 +89,20 @@ | ||
| 92 | 89 | * |
| 93 | 90 | * @return void |
| 94 | 91 | */ |
| 95 | 92 | 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' ] ); | |
| 93 | + add_action( | |
| 94 | + 'init', | |
| 95 | + function () { | |
| 96 | + if ( Fns::should_load_elementor_scripts() ) { | |
| 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' ] ); | |
| 102 | + } | |
| 103 | + } | |
| 104 | + ); | |
| 101 | 105 | } |
| 102 | 106 | |
| 103 | 107 | /** |
| 104 | 108 | * Register Category |
| @@ -112,9 +116,9 @@ | ||
| 112 | 116 | $builder_id = get_queried_object_id(); |
| 113 | 117 | $id = Fns::wpml_object_id( $builder_id, BuilderFns::$post_type_tb, 'default' ); |
| 114 | 118 | $type = BuilderFns::builder_type( $id ); |
| 115 | 119 | |
| 116 | - if ( $type ) { | |
| 120 | + if ( $type && 'popup-builder' !== $type ) { | |
| 117 | 121 | $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : ''; |
| 118 | 122 | $builder_type = str_replace( [ 'My Account - ', 'Endpoint: ' ], '', $builder_type ); |
| 119 | 123 | $categories['rtsb-shopbuilder'] = [ |
| 120 | 124 | 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ), |
| @@ -135,10 +139,10 @@ | ||
| 135 | 139 | $categories, |
| 136 | 140 | array_slice( $other_categories, 1 ) |
| 137 | 141 | ); |
| 138 | 142 | |
| 139 | - $set_categories = function ( $categories ) { | |
| 140 | - $this->categories = $categories; | |
| 143 | + $set_categories = function ( $categories ) use ( $elements_manager ) { | |
| 144 | + $elements_manager->categories = $categories; | |
| 141 | 145 | }; |
| 142 | 146 | |
| 143 | 147 | $set_categories->call( $elements_manager, $categories ); |
| 144 | 148 | } |
| @@ -159,10 +163,14 @@ | ||
| 159 | 163 | |
| 160 | 164 | /** |
| 161 | 165 | * Init Widgets |
| 162 | 166 | * |
| 163 | - * Include widgets files and register them | |
| 167 | + * Include widget files and register them | |
| 164 | 168 | * |
| 169 | + * @param object $widgets_manager Widgets Manager. | |
| 170 | + * | |
| 171 | + * @return void | |
| 172 | + * | |
| 165 | 173 | * @since 1.0.0 |
| 166 | 174 | */ |
| 167 | 175 | public function init_widgets( $widgets_manager ) { |
| 168 | 176 | |
| @@ -289,9 +297,9 @@ | ||
| 289 | 297 | * |
| 290 | 298 | * @since 2.0.0 |
| 291 | 299 | */ |
| 292 | 300 | if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) { |
| 293 | - do_action( 'elementor/page_templates/header-footer/before_content' ); | |
| 301 | + do_action( 'elementor/page_templates/header-footer/before_content' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores | |
| 294 | 302 | } |
| 295 | 303 | |
| 296 | 304 | $parent_class = apply_filters( 'rtsb/builder/content/parent_class', [] ); |
| 297 | 305 | |
| @@ -330,9 +338,12 @@ | ||
| 330 | 338 | if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) { |
| 331 | 339 | return; |
| 332 | 340 | } |
| 333 | 341 | ?> |
| 334 | - <form name="checkout" method="post" class="rtsb-woocommerce-checkout checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data"> | |
| 342 | + <!-- | |
| 343 | + woocommerce-checkout added for fix issue with payment method ( Revolut Pay ) | |
| 344 | + --> | |
| 345 | + <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"> | |
| 335 | 346 | <?php |
| 336 | 347 | } |
| 337 | 348 | } |
| 338 | 349 | |
| @@ -349,9 +360,9 @@ | ||
| 349 | 360 | * |
| 350 | 361 | * @since 2.0.0 |
| 351 | 362 | */ |
| 352 | 363 | if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) { |
| 353 | - do_action( 'elementor/page_templates/header-footer/after_content' ); | |
| 364 | + do_action( 'elementor/page_templates/header-footer/after_content' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores | |
| 354 | 365 | } |
| 355 | 366 | |
| 356 | 367 | if ( BuilderFns::is_checkout() ) { |
| 357 | 368 | if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) { |
| @@ -380,17 +391,20 @@ | ||
| 380 | 391 | $post_type = 'post'; |
| 381 | 392 | $source_name = 'post_type'; |
| 382 | 393 | $paged = absint( $_POST['page'] ?? 1 ); |
| 383 | 394 | if ( ! empty( $_POST['post_type'] ) ) { |
| 395 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 384 | 396 | $post_type = sanitize_text_field( $_POST['post_type'] ); |
| 385 | 397 | } |
| 386 | 398 | |
| 387 | 399 | if ( ! empty( $_POST['source_name'] ) ) { |
| 400 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 388 | 401 | $source_name = sanitize_text_field( $_POST['source_name'] ); |
| 389 | 402 | } |
| 390 | 403 | |
| 404 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 391 | 405 | $search = ! empty( $_POST['search'] ) ? sanitize_text_field( $_POST['search'] ) : ''; |
| 392 | - $results = $post_list = []; | |
| 406 | + $results = $post_list = []; // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found | |
| 393 | 407 | switch ( $source_name ) { |
| 394 | 408 | case 'taxonomy': |
| 395 | 409 | $args = [ |
| 396 | 410 | 'hide_empty' => false, |
| @@ -399,9 +413,9 @@ | ||
| 399 | 413 | 'search' => $search, |
| 400 | 414 | 'number' => '5', |
| 401 | 415 | ]; |
| 402 | 416 | |
| 403 | - if ( $post_type !== 'all' ) { | |
| 417 | + if ( 'all' !== $post_type ) { | |
| 404 | 418 | $args['taxonomy'] = $post_type; |
| 405 | 419 | } |
| 406 | 420 | |
| 407 | 421 | $post_list = wp_list_pluck( get_terms( $args ), 'name', 'term_id' ); |
| @@ -456,13 +470,14 @@ | ||
| 456 | 470 | if ( empty( $_POST['id'] ) ) { |
| 457 | 471 | wp_send_json_error( [] ); |
| 458 | 472 | } |
| 459 | 473 | |
| 474 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 460 | 475 | if ( empty( array_filter( $_POST['id'] ) ) ) { |
| 461 | 476 | wp_send_json_error( [] ); |
| 462 | 477 | } |
| 463 | 478 | $ids = array_map( 'intval', $_POST['id'] ); |
| 464 | - $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : ''; | |
| 479 | + $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 465 | 480 | |
| 466 | 481 | switch ( $source_name ) { |
| 467 | 482 | case 'taxonomy': |
| 468 | 483 | $args = [ |
| @@ -471,9 +486,11 @@ | ||
| 471 | 486 | 'order' => 'ASC', |
| 472 | 487 | 'include' => implode( ',', $ids ), |
| 473 | 488 | ]; |
| 474 | 489 | |
| 475 | - if ( $_POST['post_type'] !== 'all' ) { | |
| 490 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 491 | + if ( 'all' !== $_POST['post_type'] ) { | |
| 492 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 476 | 493 | $args['taxonomy'] = sanitize_text_field( $_POST['post_type'] ); |
| 477 | 494 | } |
| 478 | 495 | |
| 479 | 496 | $response = wp_list_pluck( get_terms( $args ), 'name', 'term_id' ); |
| @@ -491,9 +508,9 @@ | ||
| 491 | 508 | break; |
| 492 | 509 | default: |
| 493 | 510 | $post_info = get_posts( |
| 494 | 511 | [ |
| 495 | - 'post_type' => sanitize_text_field( $_POST['post_type'] ), | |
| 512 | + 'post_type' => sanitize_text_field( $_POST['post_type'] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 496 | 513 | 'include' => implode( ',', $ids ), |
| 497 | 514 | ] |
| 498 | 515 | ); |
| 499 | 516 | $response = wp_list_pluck( $post_info, 'post_title', 'ID' ); |
| @@ -509,12 +526,12 @@ | ||
| 509 | 526 | |
| 510 | 527 | /** |
| 511 | 528 | * Ajax callback for rt-select2 |
| 512 | 529 | * |
| 513 | - * @param $post_type | |
| 514 | - * @param $limit | |
| 515 | - * @param $search | |
| 516 | - * @param $paged | |
| 530 | + * @param string $post_type Post type. | |
| 531 | + * @param int $limit Limit. | |
| 532 | + * @param string $search Search. | |
| 533 | + * @param int $paged Paged. | |
| 517 | 534 | * |
| 518 | 535 | * @return array |
| 519 | 536 | */ |
| 520 | 537 | public function get_query_data( $post_type = 'any', $limit = 10, $search = '', $paged = 1 ) { |
| @@ -549,8 +566,17 @@ | ||
| 549 | 566 | } |
| 550 | 567 | |
| 551 | 568 | if ( ! empty( $search ) ) { |
| 552 | 569 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title LIKE %s", '%' . esc_sql( $search ) . '%' ); |
| 570 | + } | |
| 571 | + | |
| 572 | + // Add a query for shop_coupon post-type to check 'show on frontend' meta. | |
| 573 | + if ( 'shop_coupon' === $post_type ) { | |
| 574 | + $where .= " AND {$wpdb->posts}.ID IN ( | |
| 575 | + SELECT post_id FROM {$wpdb->postmeta} | |
| 576 | + WHERE meta_key = 'rtsb_show_on_frontend' | |
| 577 | + AND meta_value = 'on' | |
| 578 | + )"; | |
| 553 | 579 | } |
| 554 | 580 | |
| 555 | 581 | $query = "select post_title,ID from $wpdb->posts where post_status = 'publish' {$where} {$limit}"; |
| 556 | 582 | $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching |