| @@ -60,22 +60,19 @@ | ||
| 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 | - 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' ] ); | |
| 70 | + add_action( 'wp_ajax_rtsb_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); | |
| 71 | + add_action( 'wp_ajax_nopriv_rtsb_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); | |
| 75 | 72 | // 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' ] ); | |
| 73 | + add_action( 'wp_ajax_rtsb_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] ); | |
| 74 | + add_action( 'wp_ajax_nopriv_rtsb_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] ); | |
| 78 | 75 | } |
| 79 | 76 | |
| 80 | 77 | /** |
| 81 | 78 | * Apply for frontend. |
| @@ -114,9 +111,9 @@ | ||
| 114 | 111 | $type = BuilderFns::builder_type( $id ); |
| 115 | 112 | |
| 116 | 113 | if ( $type ) { |
| 117 | 114 | $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : ''; |
| 118 | - $builder_type = str_replace( 'My Account - ', '', $builder_type ); | |
| 115 | + $builder_type = str_replace( [ 'My Account - ', 'Endpoint: ' ], '', $builder_type ); | |
| 119 | 116 | $categories['rtsb-shopbuilder'] = [ |
| 120 | 117 | 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ), |
| 121 | 118 | 'icon' => 'fa fa-plug', |
| 122 | 119 | ]; |
| @@ -135,10 +132,10 @@ | ||
| 135 | 132 | $categories, |
| 136 | 133 | array_slice( $other_categories, 1 ) |
| 137 | 134 | ); |
| 138 | 135 | |
| 139 | - $set_categories = function ( $categories ) { | |
| 140 | - $this->categories = $categories; | |
| 136 | + $set_categories = function ( $categories ) use ( $elements_manager ) { | |
| 137 | + $elements_manager->categories = $categories; | |
| 141 | 138 | }; |
| 142 | 139 | |
| 143 | 140 | $set_categories->call( $elements_manager, $categories ); |
| 144 | 141 | } |
| @@ -230,9 +227,9 @@ | ||
| 230 | 227 | * |
| 231 | 228 | * @return array |
| 232 | 229 | */ |
| 233 | 230 | public function rtsb_icons( $tabs = [] ) { |
| 234 | - $custom_icons = $this->get_icons(); | |
| 231 | + $custom_icons = Fns::get_custom_icon_names(); | |
| 235 | 232 | |
| 236 | 233 | $tabs['shopbuilder-icons'] = [ |
| 237 | 234 | 'name' => 'rtsb-fonts', |
| 238 | 235 | 'label' => esc_html__( 'ShopBuilder Icons', 'shopbuilder' ), |
| @@ -380,15 +377,18 @@ | ||
| 380 | 377 | $post_type = 'post'; |
| 381 | 378 | $source_name = 'post_type'; |
| 382 | 379 | $paged = absint( $_POST['page'] ?? 1 ); |
| 383 | 380 | if ( ! empty( $_POST['post_type'] ) ) { |
| 381 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 384 | 382 | $post_type = sanitize_text_field( $_POST['post_type'] ); |
| 385 | 383 | } |
| 386 | 384 | |
| 387 | 385 | if ( ! empty( $_POST['source_name'] ) ) { |
| 386 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 388 | 387 | $source_name = sanitize_text_field( $_POST['source_name'] ); |
| 389 | 388 | } |
| 390 | 389 | |
| 390 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 391 | 391 | $search = ! empty( $_POST['search'] ) ? sanitize_text_field( $_POST['search'] ) : ''; |
| 392 | 392 | $results = $post_list = []; |
| 393 | 393 | switch ( $source_name ) { |
| 394 | 394 | case 'taxonomy': |
| @@ -456,13 +456,14 @@ | ||
| 456 | 456 | if ( empty( $_POST['id'] ) ) { |
| 457 | 457 | wp_send_json_error( [] ); |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 460 | 461 | if ( empty( array_filter( $_POST['id'] ) ) ) { |
| 461 | 462 | wp_send_json_error( [] ); |
| 462 | 463 | } |
| 463 | 464 | $ids = array_map( 'intval', $_POST['id'] ); |
| 464 | - $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : ''; | |
| 465 | + $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 465 | 466 | |
| 466 | 467 | switch ( $source_name ) { |
| 467 | 468 | case 'taxonomy': |
| 468 | 469 | $args = [ |
| @@ -471,9 +472,11 @@ | ||
| 471 | 472 | 'order' => 'ASC', |
| 472 | 473 | 'include' => implode( ',', $ids ), |
| 473 | 474 | ]; |
| 474 | 475 | |
| 476 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 475 | 477 | if ( $_POST['post_type'] !== 'all' ) { |
| 478 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 476 | 479 | $args['taxonomy'] = sanitize_text_field( $_POST['post_type'] ); |
| 477 | 480 | } |
| 478 | 481 | |
| 479 | 482 | $response = wp_list_pluck( get_terms( $args ), 'name', 'term_id' ); |
| @@ -491,9 +494,9 @@ | ||
| 491 | 494 | break; |
| 492 | 495 | default: |
| 493 | 496 | $post_info = get_posts( |
| 494 | 497 | [ |
| 495 | - 'post_type' => sanitize_text_field( $_POST['post_type'] ), | |
| 498 | + 'post_type' => sanitize_text_field( $_POST['post_type'] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 496 | 499 | 'include' => implode( ',', $ids ), |
| 497 | 500 | ] |
| 498 | 501 | ); |
| 499 | 502 | $response = wp_list_pluck( $post_info, 'post_title', 'ID' ); |
| @@ -549,8 +552,17 @@ | ||
| 549 | 552 | } |
| 550 | 553 | |
| 551 | 554 | if ( ! empty( $search ) ) { |
| 552 | 555 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title LIKE %s", '%' . esc_sql( $search ) . '%' ); |
| 556 | + } | |
| 557 | + | |
| 558 | + // Add a query for shop_coupon post-type to check 'show on frontend' meta. | |
| 559 | + if ( 'shop_coupon' === $post_type ) { | |
| 560 | + $where .= " AND {$wpdb->posts}.ID IN ( | |
| 561 | + SELECT post_id FROM {$wpdb->postmeta} | |
| 562 | + WHERE meta_key = 'rtsb_show_on_frontend' | |
| 563 | + AND meta_value = 'on' | |
| 564 | + )"; | |
| 553 | 565 | } |
| 554 | 566 | |
| 555 | 567 | $query = "select post_title,ID from $wpdb->posts where post_status = 'publish' {$where} {$limit}"; |
| 556 | 568 | $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching |