| @@ -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 |
| @@ -114,9 +119,9 @@ | ||
| 114 | 119 | $type = BuilderFns::builder_type( $id ); |
| 115 | 120 | |
| 116 | 121 | if ( $type ) { |
| 117 | 122 | $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : ''; |
| 118 | - $builder_type = str_replace( 'My Account - ', '', $builder_type ); | |
| 123 | + $builder_type = str_replace( [ 'My Account - ', 'Endpoint: ' ], '', $builder_type ); | |
| 119 | 124 | $categories['rtsb-shopbuilder'] = [ |
| 120 | 125 | 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ), |
| 121 | 126 | 'icon' => 'fa fa-plug', |
| 122 | 127 | ]; |
| @@ -135,10 +140,10 @@ | ||
| 135 | 140 | $categories, |
| 136 | 141 | array_slice( $other_categories, 1 ) |
| 137 | 142 | ); |
| 138 | 143 | |
| 139 | - $set_categories = function ( $categories ) { | |
| 140 | - $this->categories = $categories; | |
| 144 | + $set_categories = function ( $categories ) use ( $elements_manager ) { | |
| 145 | + $elements_manager->categories = $categories; | |
| 141 | 146 | }; |
| 142 | 147 | |
| 143 | 148 | $set_categories->call( $elements_manager, $categories ); |
| 144 | 149 | } |
| @@ -159,10 +164,14 @@ | ||
| 159 | 164 | |
| 160 | 165 | /** |
| 161 | 166 | * Init Widgets |
| 162 | 167 | * |
| 163 | - * Include widgets files and register them | |
| 168 | + * Include widget files and register them | |
| 164 | 169 | * |
| 170 | + * @param object $widgets_manager Widgets Manager. | |
| 171 | + * | |
| 172 | + * @return void | |
| 173 | + * | |
| 165 | 174 | * @since 1.0.0 |
| 166 | 175 | */ |
| 167 | 176 | public function init_widgets( $widgets_manager ) { |
| 168 | 177 | |
| @@ -230,9 +239,9 @@ | ||
| 230 | 239 | * |
| 231 | 240 | * @return array |
| 232 | 241 | */ |
| 233 | 242 | public function rtsb_icons( $tabs = [] ) { |
| 234 | - $custom_icons = $this->get_icons(); | |
| 243 | + $custom_icons = Fns::get_custom_icon_names(); | |
| 235 | 244 | |
| 236 | 245 | $tabs['shopbuilder-icons'] = [ |
| 237 | 246 | 'name' => 'rtsb-fonts', |
| 238 | 247 | 'label' => esc_html__( 'ShopBuilder Icons', 'shopbuilder' ), |
| @@ -289,9 +298,9 @@ | ||
| 289 | 298 | * |
| 290 | 299 | * @since 2.0.0 |
| 291 | 300 | */ |
| 292 | 301 | if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) { |
| 293 | - 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 | |
| 294 | 303 | } |
| 295 | 304 | |
| 296 | 305 | $parent_class = apply_filters( 'rtsb/builder/content/parent_class', [] ); |
| 297 | 306 | |
| @@ -330,9 +339,12 @@ | ||
| 330 | 339 | if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) { |
| 331 | 340 | return; |
| 332 | 341 | } |
| 333 | 342 | ?> |
| 334 | - <form name="checkout" method="post" class="rtsb-woocommerce-checkout checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data"> | |
| 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"> | |
| 335 | 347 | <?php |
| 336 | 348 | } |
| 337 | 349 | } |
| 338 | 350 | |
| @@ -349,9 +361,9 @@ | ||
| 349 | 361 | * |
| 350 | 362 | * @since 2.0.0 |
| 351 | 363 | */ |
| 352 | 364 | if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) { |
| 353 | - 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 | |
| 354 | 366 | } |
| 355 | 367 | |
| 356 | 368 | if ( BuilderFns::is_checkout() ) { |
| 357 | 369 | if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) { |
| @@ -380,17 +392,20 @@ | ||
| 380 | 392 | $post_type = 'post'; |
| 381 | 393 | $source_name = 'post_type'; |
| 382 | 394 | $paged = absint( $_POST['page'] ?? 1 ); |
| 383 | 395 | if ( ! empty( $_POST['post_type'] ) ) { |
| 396 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 384 | 397 | $post_type = sanitize_text_field( $_POST['post_type'] ); |
| 385 | 398 | } |
| 386 | 399 | |
| 387 | 400 | if ( ! empty( $_POST['source_name'] ) ) { |
| 401 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 388 | 402 | $source_name = sanitize_text_field( $_POST['source_name'] ); |
| 389 | 403 | } |
| 390 | 404 | |
| 405 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 391 | 406 | $search = ! empty( $_POST['search'] ) ? sanitize_text_field( $_POST['search'] ) : ''; |
| 392 | - $results = $post_list = []; | |
| 407 | + $results = $post_list = []; // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found | |
| 393 | 408 | switch ( $source_name ) { |
| 394 | 409 | case 'taxonomy': |
| 395 | 410 | $args = [ |
| 396 | 411 | 'hide_empty' => false, |
| @@ -399,9 +414,9 @@ | ||
| 399 | 414 | 'search' => $search, |
| 400 | 415 | 'number' => '5', |
| 401 | 416 | ]; |
| 402 | 417 | |
| 403 | - if ( $post_type !== 'all' ) { | |
| 418 | + if ( 'all' !== $post_type ) { | |
| 404 | 419 | $args['taxonomy'] = $post_type; |
| 405 | 420 | } |
| 406 | 421 | |
| 407 | 422 | $post_list = wp_list_pluck( get_terms( $args ), 'name', 'term_id' ); |
| @@ -456,13 +471,14 @@ | ||
| 456 | 471 | if ( empty( $_POST['id'] ) ) { |
| 457 | 472 | wp_send_json_error( [] ); |
| 458 | 473 | } |
| 459 | 474 | |
| 475 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 460 | 476 | if ( empty( array_filter( $_POST['id'] ) ) ) { |
| 461 | 477 | wp_send_json_error( [] ); |
| 462 | 478 | } |
| 463 | 479 | $ids = array_map( 'intval', $_POST['id'] ); |
| 464 | - $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 | |
| 465 | 481 | |
| 466 | 482 | switch ( $source_name ) { |
| 467 | 483 | case 'taxonomy': |
| 468 | 484 | $args = [ |
| @@ -471,9 +487,11 @@ | ||
| 471 | 487 | 'order' => 'ASC', |
| 472 | 488 | 'include' => implode( ',', $ids ), |
| 473 | 489 | ]; |
| 474 | 490 | |
| 475 | - 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 | |
| 476 | 494 | $args['taxonomy'] = sanitize_text_field( $_POST['post_type'] ); |
| 477 | 495 | } |
| 478 | 496 | |
| 479 | 497 | $response = wp_list_pluck( get_terms( $args ), 'name', 'term_id' ); |
| @@ -491,9 +509,9 @@ | ||
| 491 | 509 | break; |
| 492 | 510 | default: |
| 493 | 511 | $post_info = get_posts( |
| 494 | 512 | [ |
| 495 | - '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 | |
| 496 | 514 | 'include' => implode( ',', $ids ), |
| 497 | 515 | ] |
| 498 | 516 | ); |
| 499 | 517 | $response = wp_list_pluck( $post_info, 'post_title', 'ID' ); |
| @@ -509,12 +527,12 @@ | ||
| 509 | 527 | |
| 510 | 528 | /** |
| 511 | 529 | * Ajax callback for rt-select2 |
| 512 | 530 | * |
| 513 | - * @param $post_type | |
| 514 | - * @param $limit | |
| 515 | - * @param $search | |
| 516 | - * @param $paged | |
| 531 | + * @param string $post_type Post type. | |
| 532 | + * @param int $limit Limit. | |
| 533 | + * @param string $search Search. | |
| 534 | + * @param int $paged Paged. | |
| 517 | 535 | * |
| 518 | 536 | * @return array |
| 519 | 537 | */ |
| 520 | 538 | public function get_query_data( $post_type = 'any', $limit = 10, $search = '', $paged = 1 ) { |
| @@ -549,8 +567,17 @@ | ||
| 549 | 567 | } |
| 550 | 568 | |
| 551 | 569 | if ( ! empty( $search ) ) { |
| 552 | 570 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title LIKE %s", '%' . esc_sql( $search ) . '%' ); |
| 571 | + } | |
| 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 | + )"; | |
| 553 | 580 | } |
| 554 | 581 | |
| 555 | 582 | $query = "select post_title,ID from $wpdb->posts where post_status = 'publish' {$where} {$limit}"; |
| 556 | 583 | $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching |