| @@ -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 |
| @@ -108,12 +113,15 @@ | ||
| 108 | 113 | * @return void |
| 109 | 114 | */ |
| 110 | 115 | public function add_elementor_widget_categories( $elements_manager ) { |
| 111 | 116 | $categories = []; |
| 112 | - $type = BuilderFns::builder_type( get_the_ID() ); | |
| 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 ); | |
| 120 | + | |
| 113 | 121 | if ( $type ) { |
| 114 | 122 | $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : ''; |
| 115 | - $builder_type = str_replace( 'My Account - ', '', $builder_type ); | |
| 123 | + $builder_type = str_replace( [ 'My Account - ', 'Endpoint: ' ], '', $builder_type ); | |
| 116 | 124 | $categories['rtsb-shopbuilder'] = [ |
| 117 | 125 | 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ), |
| 118 | 126 | 'icon' => 'fa fa-plug', |
| 119 | 127 | ]; |
| @@ -123,9 +131,10 @@ | ||
| 123 | 131 | 'title' => esc_html__( 'Shopbuilder - General', 'shopbuilder' ), |
| 124 | 132 | 'icon' => 'fa fa-plug', |
| 125 | 133 | ]; |
| 126 | 134 | } |
| 127 | - $categories = apply_filters( 'rtsb_elementor_widgets_category_lists', $categories ); | |
| 135 | + $categories = apply_filters( 'rtsb_elementor_widgets_category_lists', $categories ); | |
| 136 | + | |
| 128 | 137 | $other_categories = $elements_manager->get_categories(); |
| 129 | 138 | $categories = array_merge( |
| 130 | 139 | array_slice( $other_categories, 0, 1 ), |
| 131 | 140 | $categories, |
| @@ -131,10 +140,10 @@ | ||
| 131 | 140 | $categories, |
| 132 | 141 | array_slice( $other_categories, 1 ) |
| 133 | 142 | ); |
| 134 | 143 | |
| 135 | - $set_categories = function ( $categories ) { | |
| 136 | - $this->categories = $categories; | |
| 144 | + $set_categories = function ( $categories ) use ( $elements_manager ) { | |
| 145 | + $elements_manager->categories = $categories; | |
| 137 | 146 | }; |
| 138 | 147 | |
| 139 | 148 | $set_categories->call( $elements_manager, $categories ); |
| 140 | 149 | } |
| @@ -155,10 +164,14 @@ | ||
| 155 | 164 | |
| 156 | 165 | /** |
| 157 | 166 | * Init Widgets |
| 158 | 167 | * |
| 159 | - * Include widgets files and register them | |
| 168 | + * Include widget files and register them | |
| 160 | 169 | * |
| 170 | + * @param object $widgets_manager Widgets Manager. | |
| 171 | + * | |
| 172 | + * @return void | |
| 173 | + * | |
| 161 | 174 | * @since 1.0.0 |
| 162 | 175 | */ |
| 163 | 176 | public function init_widgets( $widgets_manager ) { |
| 164 | 177 | |
| @@ -226,9 +239,9 @@ | ||
| 226 | 239 | * |
| 227 | 240 | * @return array |
| 228 | 241 | */ |
| 229 | 242 | public function rtsb_icons( $tabs = [] ) { |
| 230 | - $custom_icons = $this->get_icons(); | |
| 243 | + $custom_icons = Fns::get_custom_icon_names(); | |
| 231 | 244 | |
| 232 | 245 | $tabs['shopbuilder-icons'] = [ |
| 233 | 246 | 'name' => 'rtsb-fonts', |
| 234 | 247 | 'label' => esc_html__( 'ShopBuilder Icons', 'shopbuilder' ), |
| @@ -285,9 +298,9 @@ | ||
| 285 | 298 | * |
| 286 | 299 | * @since 2.0.0 |
| 287 | 300 | */ |
| 288 | 301 | if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) { |
| 289 | - 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 | |
| 290 | 303 | } |
| 291 | 304 | |
| 292 | 305 | $parent_class = apply_filters( 'rtsb/builder/content/parent_class', [] ); |
| 293 | 306 | |
| @@ -345,9 +358,9 @@ | ||
| 345 | 358 | * |
| 346 | 359 | * @since 2.0.0 |
| 347 | 360 | */ |
| 348 | 361 | if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) { |
| 349 | - 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 | |
| 350 | 363 | } |
| 351 | 364 | |
| 352 | 365 | if ( BuilderFns::is_checkout() ) { |
| 353 | 366 | if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) { |
| @@ -376,17 +389,20 @@ | ||
| 376 | 389 | $post_type = 'post'; |
| 377 | 390 | $source_name = 'post_type'; |
| 378 | 391 | $paged = absint( $_POST['page'] ?? 1 ); |
| 379 | 392 | if ( ! empty( $_POST['post_type'] ) ) { |
| 393 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 380 | 394 | $post_type = sanitize_text_field( $_POST['post_type'] ); |
| 381 | 395 | } |
| 382 | 396 | |
| 383 | 397 | if ( ! empty( $_POST['source_name'] ) ) { |
| 398 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 384 | 399 | $source_name = sanitize_text_field( $_POST['source_name'] ); |
| 385 | 400 | } |
| 386 | 401 | |
| 402 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 387 | 403 | $search = ! empty( $_POST['search'] ) ? sanitize_text_field( $_POST['search'] ) : ''; |
| 388 | - $results = $post_list = []; | |
| 404 | + $results = $post_list = []; // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found | |
| 389 | 405 | switch ( $source_name ) { |
| 390 | 406 | case 'taxonomy': |
| 391 | 407 | $args = [ |
| 392 | 408 | 'hide_empty' => false, |
| @@ -395,9 +411,9 @@ | ||
| 395 | 411 | 'search' => $search, |
| 396 | 412 | 'number' => '5', |
| 397 | 413 | ]; |
| 398 | 414 | |
| 399 | - if ( $post_type !== 'all' ) { | |
| 415 | + if ( 'all' !== $post_type ) { | |
| 400 | 416 | $args['taxonomy'] = $post_type; |
| 401 | 417 | } |
| 402 | 418 | |
| 403 | 419 | $post_list = wp_list_pluck( get_terms( $args ), 'name', 'term_id' ); |
| @@ -452,13 +468,14 @@ | ||
| 452 | 468 | if ( empty( $_POST['id'] ) ) { |
| 453 | 469 | wp_send_json_error( [] ); |
| 454 | 470 | } |
| 455 | 471 | |
| 472 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 456 | 473 | if ( empty( array_filter( $_POST['id'] ) ) ) { |
| 457 | 474 | wp_send_json_error( [] ); |
| 458 | 475 | } |
| 459 | 476 | $ids = array_map( 'intval', $_POST['id'] ); |
| 460 | - $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 | |
| 461 | 478 | |
| 462 | 479 | switch ( $source_name ) { |
| 463 | 480 | case 'taxonomy': |
| 464 | 481 | $args = [ |
| @@ -467,9 +484,11 @@ | ||
| 467 | 484 | 'order' => 'ASC', |
| 468 | 485 | 'include' => implode( ',', $ids ), |
| 469 | 486 | ]; |
| 470 | 487 | |
| 471 | - 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 | |
| 472 | 491 | $args['taxonomy'] = sanitize_text_field( $_POST['post_type'] ); |
| 473 | 492 | } |
| 474 | 493 | |
| 475 | 494 | $response = wp_list_pluck( get_terms( $args ), 'name', 'term_id' ); |
| @@ -487,9 +506,9 @@ | ||
| 487 | 506 | break; |
| 488 | 507 | default: |
| 489 | 508 | $post_info = get_posts( |
| 490 | 509 | [ |
| 491 | - '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 | |
| 492 | 511 | 'include' => implode( ',', $ids ), |
| 493 | 512 | ] |
| 494 | 513 | ); |
| 495 | 514 | $response = wp_list_pluck( $post_info, 'post_title', 'ID' ); |
| @@ -505,12 +524,12 @@ | ||
| 505 | 524 | |
| 506 | 525 | /** |
| 507 | 526 | * Ajax callback for rt-select2 |
| 508 | 527 | * |
| 509 | - * @param $post_type | |
| 510 | - * @param $limit | |
| 511 | - * @param $search | |
| 512 | - * @param $paged | |
| 528 | + * @param string $post_type Post type. | |
| 529 | + * @param int $limit Limit. | |
| 530 | + * @param string $search Search. | |
| 531 | + * @param int $paged Paged. | |
| 513 | 532 | * |
| 514 | 533 | * @return array |
| 515 | 534 | */ |
| 516 | 535 | public function get_query_data( $post_type = 'any', $limit = 10, $search = '', $paged = 1 ) { |
| @@ -547,8 +566,17 @@ | ||
| 547 | 566 | if ( ! empty( $search ) ) { |
| 548 | 567 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title LIKE %s", '%' . esc_sql( $search ) . '%' ); |
| 549 | 568 | } |
| 550 | 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 | + | |
| 551 | 579 | $query = "select post_title,ID from $wpdb->posts where post_status = 'publish' {$where} {$limit}"; |
| 552 | 580 | $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 553 | 581 | |
| 554 | 582 | if ( ! empty( $results ) ) { |
| @@ -581,10 +609,10 @@ | ||
| 581 | 609 | |
| 582 | 610 | $pro_widgets = [ |
| 583 | 611 | [ |
| 584 | 612 | 'name' => 'rtsb-ajax-product-filters', |
| 585 | - 'title' => esc_html__( 'Ajax Product Filters', 'testimonial-slider-showcase' ), | |
| 586 | - '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' ), | |
| 587 | 615 | 'icon' => 'rtsb-el-custom rtsb-element icon-rtsb-ajax-product-filters rtsb-promotional-element', |
| 588 | 616 | 'categories' => '[ "rtsb-shopbuilder" ]', |
| 589 | 617 | ], |
| 590 | 618 | ]; |