| @@ -6,16 +6,17 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace RadiusTheme\SB\Controllers; |
| 9 | 9 | |
| 10 | +use Elementor\Plugin; | |
| 10 | 11 | use RadiusTheme\SB\Helpers\Fns; |
| 11 | 12 | use RadiusTheme\SB\Helpers\BuilderFns; |
| 12 | -use RadiusTheme\SB\Models\ElementList; | |
| 13 | 13 | use RadiusTheme\SB\Traits\SingletonTrait; |
| 14 | 14 | use RadiusTheme\SB\Controllers\Builder\BuilderCpt; |
| 15 | 15 | use RadiusTheme\SB\Controllers\Hooks\BuilderHooks; |
| 16 | 16 | use RadiusTheme\SB\Elementor\Controls\ImageSelectorControl; |
| 17 | 17 | use RadiusTheme\SB\Elementor\Controls\Select2AjaxControl; |
| 18 | +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.' ); |
| @@ -25,13 +26,8 @@ | ||
| 25 | 26 | * Builder Controller |
| 26 | 27 | */ |
| 27 | 28 | class BuilderController { |
| 28 | 29 | /** |
| 29 | - * @var array | |
| 30 | - */ | |
| 31 | - private static $cache = []; | |
| 32 | - | |
| 33 | - /** | |
| 34 | 30 | * Builder page id. |
| 35 | 31 | * |
| 36 | 32 | * @var integer |
| 37 | 33 | */ |
| @@ -54,24 +50,25 @@ | ||
| 54 | 50 | */ |
| 55 | 51 | private function __construct() { |
| 56 | 52 | $this->builder_page_id = BuilderFns::builder_page_id_by_page(); |
| 57 | 53 | $this->page_edit_with = Fns::page_edit_with( $this->builder_page_id ); |
| 54 | + | |
| 58 | 55 | if ( ! is_admin() ) { |
| 59 | 56 | BuilderHooks::instance(); |
| 60 | 57 | } |
| 61 | 58 | |
| 62 | 59 | BuilderCpt::instance(); |
| 63 | - if ( defined( 'ELEMENTOR_VERSION' ) ) { | |
| 64 | - $this->elementor_init(); | |
| 65 | - $this->both_builder_frontend(); | |
| 66 | - add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'editor_scripts' ] ); | |
| 67 | - } | |
| 60 | + | |
| 61 | + add_action( 'elementor/init', [ $this, 'elementor_init' ] ); | |
| 62 | + add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'editor_scripts' ] ); | |
| 63 | + add_action( 'template_redirect', [ $this, 'both_builder_frontend' ], 99 ); | |
| 64 | + | |
| 68 | 65 | // RT Select2 Ajax. |
| 69 | - add_action( 'wp_ajax_rtsb_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); | |
| 70 | - add_action( 'wp_ajax_nopriv_rtsb_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); | |
| 66 | + add_action( 'wp_ajax_rt_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); | |
| 67 | + add_action( 'wp_ajax_nopriv_rt_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); | |
| 71 | 68 | // Select2 ajax save data. |
| 72 | - add_action( 'wp_ajax_rtsb_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] ); | |
| 73 | - add_action( 'wp_ajax_nopriv_rtsb_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] ); | |
| 69 | + add_action( 'wp_ajax_rt_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] ); | |
| 70 | + add_action( 'wp_ajax_nopriv_rt_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] ); | |
| 74 | 71 | } |
| 75 | 72 | |
| 76 | 73 | /** |
| 77 | 74 | * Apply for frontend. |
| @@ -88,20 +85,13 @@ | ||
| 88 | 85 | * |
| 89 | 86 | * @return void |
| 90 | 87 | */ |
| 91 | 88 | 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 | - ); | |
| 89 | + add_action( 'elementor/elements/categories_registered', [ $this, 'add_elementor_widget_categories' ] ); | |
| 90 | + add_action( 'elementor/widgets/register', [ $this, 'init_widgets' ] ); | |
| 91 | + add_action( 'elementor/controls/register', [ $this, 'init_controls' ] ); | |
| 92 | + add_filter( 'elementor/editor/localize_settings', [ $this, 'promotePremiumWidgets' ] ); | |
| 93 | + add_action( 'elementor/icons_manager/additional_tabs', [ $this, 'rtsb_icons' ] ); | |
| 104 | 94 | } |
| 105 | 95 | |
| 106 | 96 | /** |
| 107 | 97 | * Register Category |
| @@ -110,29 +100,21 @@ | ||
| 110 | 100 | * |
| 111 | 101 | * @return void |
| 112 | 102 | */ |
| 113 | 103 | public function add_elementor_widget_categories( $elements_manager ) { |
| 114 | - $categories = []; | |
| 115 | - $builder_id = get_queried_object_id(); | |
| 116 | - $id = Fns::wpml_object_id( $builder_id, BuilderFns::$post_type_tb, 'default' ); | |
| 117 | - $type = BuilderFns::builder_type( $id ); | |
| 104 | + $type = BuilderFns::builder_type( get_the_ID() ); | |
| 105 | + $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : ''; | |
| 106 | + $builder_type = str_replace( 'My Account - ', '', $builder_type ); | |
| 107 | + $categories['rtsb-shopbuilder'] = [ | |
| 108 | + 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ), | |
| 109 | + 'icon' => 'fa fa-plug', | |
| 110 | + ]; | |
| 111 | + $categories['rtsb-shopbuilder-general'] = [ | |
| 112 | + 'title' => esc_html__( 'Shopbuilder - General', 'shopbuilder' ), | |
| 113 | + 'icon' => 'fa fa-plug', | |
| 114 | + ]; | |
| 118 | 115 | |
| 119 | - if ( $type && 'popup-builder' !== $type ) { | |
| 120 | - $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : ''; | |
| 121 | - $builder_type = str_replace( [ 'My Account - ', 'Endpoint: ' ], '', $builder_type ); | |
| 122 | - $categories['rtsb-shopbuilder'] = [ | |
| 123 | - 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ), | |
| 124 | - 'icon' => 'fa fa-plug', | |
| 125 | - ]; | |
| 126 | - } | |
| 127 | - if ( 'quick-view' !== $type ) { | |
| 128 | - $categories['rtsb-shopbuilder-general'] = [ | |
| 129 | - 'title' => esc_html__( 'Shopbuilder - General', 'shopbuilder' ), | |
| 130 | - 'icon' => 'fa fa-plug', | |
| 131 | - ]; | |
| 132 | - } | |
| 133 | - $categories = apply_filters( 'rtsb_elementor_widgets_category_lists', $categories ); | |
| 134 | - | |
| 116 | + $categories = apply_filters( 'rtsb_elementor_widgets_category_lists', $categories ); | |
| 135 | 117 | $other_categories = $elements_manager->get_categories(); |
| 136 | 118 | $categories = array_merge( |
| 137 | 119 | array_slice( $other_categories, 0, 1 ), |
| 138 | 120 | $categories, |
| @@ -138,10 +120,10 @@ | ||
| 138 | 120 | $categories, |
| 139 | 121 | array_slice( $other_categories, 1 ) |
| 140 | 122 | ); |
| 141 | 123 | |
| 142 | - $set_categories = function ( $categories ) use ( $elements_manager ) { | |
| 143 | - $elements_manager->categories = $categories; | |
| 124 | + $set_categories = function ( $categories ) { | |
| 125 | + $this->categories = $categories; | |
| 144 | 126 | }; |
| 145 | 127 | |
| 146 | 128 | $set_categories->call( $elements_manager, $categories ); |
| 147 | 129 | } |
| @@ -162,20 +144,21 @@ | ||
| 162 | 144 | |
| 163 | 145 | /** |
| 164 | 146 | * Init Widgets |
| 165 | 147 | * |
| 166 | - * Include widget files and register them | |
| 148 | + * Include widgets files and register them | |
| 167 | 149 | * |
| 168 | - * @param object $widgets_manager Widgets Manager. | |
| 169 | - * | |
| 170 | - * @return void | |
| 171 | - * | |
| 172 | 150 | * @since 1.0.0 |
| 173 | 151 | */ |
| 174 | 152 | public function init_widgets( $widgets_manager ) { |
| 153 | + $product = Fns::get_product(); | |
| 175 | 154 | |
| 176 | - $get_list = ElementList::instance()->get_list( true, 'active' ); | |
| 177 | - foreach ( $get_list as $element ) { | |
| 155 | + // TODO: Need to remove below condition and make compitability in each widgets. | |
| 156 | + if ( ! $product ) { | |
| 157 | + return; | |
| 158 | + } | |
| 159 | + | |
| 160 | + foreach ( ElementList::instance()->get_list( true, 'active' ) as $element ) { | |
| 178 | 161 | if ( isset( $element['active'] ) && 'on' !== $element['active'] ) { |
| 179 | 162 | continue; |
| 180 | 163 | } |
| 181 | 164 | |
| @@ -187,24 +170,45 @@ | ||
| 187 | 170 | continue; |
| 188 | 171 | } |
| 189 | 172 | |
| 190 | 173 | 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 ) ) { | |
| 174 | + $widget = false; | |
| 175 | + $import = apply_filters( 'rtsb_import_status', false ); | |
| 176 | + switch ( $element['category'] ) { | |
| 177 | + case 'product': | |
| 178 | + if ( BuilderFns::is_product() || $import ) { | |
| 179 | + $widget = new $element['base_class'](); | |
| 180 | + } | |
| 181 | + break; | |
| 182 | + case 'shop': | |
| 183 | + if ( BuilderFns::is_archive() || BuilderFns::is_shop() || $import ) { | |
| 184 | + $widget = new $element['base_class'](); | |
| 185 | + } | |
| 186 | + break; | |
| 187 | + case 'archive': | |
| 188 | + if ( BuilderFns::is_archive() || $import ) { | |
| 189 | + $widget = new $element['base_class'](); | |
| 190 | + } | |
| 191 | + break; | |
| 192 | + case 'cart': | |
| 193 | + if ( BuilderFns::is_cart() || $import ) { | |
| 194 | + $widget = new $element['base_class'](); | |
| 195 | + } | |
| 196 | + break; | |
| 197 | + case 'checkout': | |
| 198 | + if ( BuilderFns::is_checkout() || $import ) { | |
| 199 | + $widget = new $element['base_class'](); | |
| 200 | + } | |
| 201 | + break; | |
| 202 | + case 'general': | |
| 196 | 203 | $widget = new $element['base_class'](); |
| 197 | - } | |
| 204 | + break; | |
| 205 | + default: | |
| 206 | + } | |
| 207 | + $widget = apply_filters( 'rtsb/element/list/init/widgets', $widget, $element ); | |
| 198 | 208 | |
| 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; | |
| 209 | + if ( $widget && is_object( $widget ) ) { | |
| 210 | + $widgets_manager->register( $widget ); | |
| 207 | 211 | } |
| 208 | 212 | } |
| 209 | 213 | } |
| 210 | 214 | } |
| @@ -209,48 +213,8 @@ | ||
| 209 | 213 | } |
| 210 | 214 | } |
| 211 | 215 | |
| 212 | 216 | /** |
| 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 | 217 | * Adding custom icons in Elementor |
| 254 | 218 | * |
| 255 | 219 | * @param array $tabs Tabs. |
| 256 | 220 | * |
| @@ -256,10 +220,23 @@ | ||
| 256 | 220 | * |
| 257 | 221 | * @return array |
| 258 | 222 | */ |
| 259 | 223 | public function rtsb_icons( $tabs = [] ) { |
| 260 | - $custom_icons = Fns::get_custom_icon_names(); | |
| 224 | + $fonts = rtsb()->get_assets_uri( 'fonts/rtsb-icons.json' ); | |
| 261 | 225 | |
| 226 | + $response = wp_remote_get( $fonts ); | |
| 227 | + | |
| 228 | + if ( is_wp_error( $response ) ) { | |
| 229 | + return $tabs; | |
| 230 | + } | |
| 231 | + | |
| 232 | + $icons_json = wp_remote_retrieve_body( $response ); | |
| 233 | + $custom_icons = json_decode( $icons_json, true ); | |
| 234 | + | |
| 235 | + if ( null === $custom_icons ) { | |
| 236 | + return $tabs; | |
| 237 | + } | |
| 238 | + | |
| 262 | 239 | $tabs['shopbuilder-icons'] = [ |
| 263 | 240 | 'name' => 'rtsb-fonts', |
| 264 | 241 | 'label' => esc_html__( 'ShopBuilder Icons', 'shopbuilder' ), |
| 265 | 242 | 'labelIcon' => 'fab fa-elementor', |
| @@ -315,34 +292,16 @@ | ||
| 315 | 292 | * |
| 316 | 293 | * @since 2.0.0 |
| 317 | 294 | */ |
| 318 | 295 | 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 | |
| 296 | + do_action( 'elementor/page_templates/header-footer/before_content' ); | |
| 320 | 297 | } |
| 321 | 298 | |
| 322 | 299 | $parent_class = apply_filters( 'rtsb/builder/content/parent_class', [] ); |
| 323 | 300 | |
| 324 | 301 | 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 | - | |
| 302 | + $product_id = Fns::get_prepared_product_id(); | |
| 334 | 303 | $parent_class = wc_get_product_class( $parent_class, $product_id ); |
| 335 | - | |
| 336 | - if ( function_exists( 'rtwpvs' ) && $_product instanceof \WC_Product ) { | |
| 337 | - if ( $_product->is_type( 'variable' ) ) { | |
| 338 | - $parent_class[] = 'rtwpvs-product'; | |
| 339 | - $beside_label = function_exists( 'rtwpvsp' ) && rtwpvs()->get_option( 'attribute_on_click_behavior' ); | |
| 340 | - if ( $beside_label ) { | |
| 341 | - $parent_class[] = 'rtwpvs-selected-term-beside-label'; | |
| 342 | - } | |
| 343 | - } | |
| 344 | - } | |
| 345 | 304 | } |
| 346 | 305 | |
| 347 | 306 | if ( BuilderFns::is_shop() ) { |
| 348 | 307 | $parent_class[] = 'shop'; |
| @@ -358,39 +317,10 @@ | ||
| 358 | 317 | |
| 359 | 318 | ?> |
| 360 | 319 | <!-- Before Content start --> |
| 361 | 320 | <div class="<?php echo esc_attr( implode( ' ', $parent_class ) ); ?>"> |
| 362 | - <?php | |
| 363 | - if ( BuilderFns::is_checkout() ) { | |
| 364 | - if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) { | |
| 365 | - return; | |
| 366 | - } | |
| 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 | - ?> | |
| 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"> | |
| 321 | + <?php if ( BuilderFns::is_checkout() ) { ?> | |
| 322 | + <form name="checkout" method="post" class="rtsb-woocommerce-checkout checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data"> | |
| 393 | 323 | <?php |
| 394 | 324 | } |
| 395 | 325 | } |
| 396 | 326 | |
| @@ -407,19 +337,15 @@ | ||
| 407 | 337 | * |
| 408 | 338 | * @since 2.0.0 |
| 409 | 339 | */ |
| 410 | 340 | 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 | |
| 341 | + do_action( 'elementor/page_templates/header-footer/after_content' ); | |
| 412 | 342 | } |
| 413 | 343 | |
| 414 | 344 | if ( BuilderFns::is_checkout() ) { |
| 415 | - if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) { | |
| 416 | - return; | |
| 417 | - } | |
| 418 | 345 | ?> |
| 419 | 346 | </form> |
| 420 | 347 | <?php |
| 421 | - do_action( 'woocommerce_after_checkout_form', WC()->checkout() ); | |
| 422 | 348 | } |
| 423 | 349 | ?> |
| 424 | 350 | </div> |
| 425 | 351 | <!-- After Content end --> |
| @@ -431,28 +357,24 @@ | ||
| 431 | 357 | * |
| 432 | 358 | * @return void |
| 433 | 359 | */ |
| 434 | 360 | public function select2_ajax_posts_filter_autocomplete() { |
| 435 | - if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) { | |
| 436 | - wp_send_json_error( [] ); | |
| 437 | - } | |
| 361 | + | |
| 438 | 362 | $query_per_page = 15; |
| 439 | 363 | $post_type = 'post'; |
| 440 | 364 | $source_name = 'post_type'; |
| 441 | - $paged = absint( $_POST['page'] ?? 1 ); | |
| 365 | + $paged = $_POST['page'] ?? 1; | |
| 366 | + | |
| 442 | 367 | if ( ! empty( $_POST['post_type'] ) ) { |
| 443 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 444 | 368 | $post_type = sanitize_text_field( $_POST['post_type'] ); |
| 445 | 369 | } |
| 446 | 370 | |
| 447 | 371 | if ( ! empty( $_POST['source_name'] ) ) { |
| 448 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 449 | 372 | $source_name = sanitize_text_field( $_POST['source_name'] ); |
| 450 | 373 | } |
| 451 | 374 | |
| 452 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 453 | 375 | $search = ! empty( $_POST['search'] ) ? sanitize_text_field( $_POST['search'] ) : ''; |
| 454 | - $results = $post_list = []; // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found | |
| 376 | + $results = $post_list = []; | |
| 455 | 377 | switch ( $source_name ) { |
| 456 | 378 | case 'taxonomy': |
| 457 | 379 | $args = [ |
| 458 | 380 | 'hide_empty' => false, |
| @@ -457,13 +379,13 @@ | ||
| 457 | 379 | $args = [ |
| 458 | 380 | 'hide_empty' => false, |
| 459 | 381 | 'orderby' => 'name', |
| 460 | 382 | 'order' => 'ASC', |
| 461 | - 'name__like' => $search, | |
| 383 | + 'search' => $search, | |
| 462 | 384 | 'number' => '5', |
| 463 | 385 | ]; |
| 464 | 386 | |
| 465 | - if ( 'all' !== $post_type ) { | |
| 387 | + if ( $post_type !== 'all' ) { | |
| 466 | 388 | $args['taxonomy'] = $post_type; |
| 467 | 389 | } |
| 468 | 390 | |
| 469 | 391 | $post_list = wp_list_pluck( get_terms( $args ), 'name', 'term_id' ); |
| @@ -510,22 +432,17 @@ | ||
| 510 | 432 | * @return void |
| 511 | 433 | */ |
| 512 | 434 | public function select2_ajax_get_posts_value_titles() { |
| 513 | 435 | |
| 514 | - if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) { | |
| 515 | - wp_send_json_error( [] ); | |
| 516 | - } | |
| 517 | - | |
| 518 | 436 | if ( empty( $_POST['id'] ) ) { |
| 519 | 437 | wp_send_json_error( [] ); |
| 520 | 438 | } |
| 521 | 439 | |
| 522 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 523 | 440 | if ( empty( array_filter( $_POST['id'] ) ) ) { |
| 524 | 441 | wp_send_json_error( [] ); |
| 525 | 442 | } |
| 526 | 443 | $ids = array_map( 'intval', $_POST['id'] ); |
| 527 | - $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 444 | + $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : ''; | |
| 528 | 445 | |
| 529 | 446 | switch ( $source_name ) { |
| 530 | 447 | case 'taxonomy': |
| 531 | 448 | $args = [ |
| @@ -534,11 +451,9 @@ | ||
| 534 | 451 | 'order' => 'ASC', |
| 535 | 452 | 'include' => implode( ',', $ids ), |
| 536 | 453 | ]; |
| 537 | 454 | |
| 538 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 539 | - if ( 'all' !== $_POST['post_type'] ) { | |
| 540 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 455 | + if ( $_POST['post_type'] !== 'all' ) { | |
| 541 | 456 | $args['taxonomy'] = sanitize_text_field( $_POST['post_type'] ); |
| 542 | 457 | } |
| 543 | 458 | |
| 544 | 459 | $response = wp_list_pluck( get_terms( $args ), 'name', 'term_id' ); |
| @@ -556,9 +471,9 @@ | ||
| 556 | 471 | break; |
| 557 | 472 | default: |
| 558 | 473 | $post_info = get_posts( |
| 559 | 474 | [ |
| 560 | - 'post_type' => sanitize_text_field( $_POST['post_type'] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 475 | + 'post_type' => sanitize_text_field( $_POST['post_type'] ), | |
| 561 | 476 | 'include' => implode( ',', $ids ), |
| 562 | 477 | ] |
| 563 | 478 | ); |
| 564 | 479 | $response = wp_list_pluck( $post_info, 'post_title', 'ID' ); |
| @@ -574,12 +489,12 @@ | ||
| 574 | 489 | |
| 575 | 490 | /** |
| 576 | 491 | * Ajax callback for rt-select2 |
| 577 | 492 | * |
| 578 | - * @param string $post_type Post type. | |
| 579 | - * @param int $limit Limit. | |
| 580 | - * @param string $search Search. | |
| 581 | - * @param int $paged Paged. | |
| 493 | + * @param $post_type | |
| 494 | + * @param $limit | |
| 495 | + * @param $search | |
| 496 | + * @param $paged | |
| 582 | 497 | * |
| 583 | 498 | * @return array |
| 584 | 499 | */ |
| 585 | 500 | public function get_query_data( $post_type = 'any', $limit = 10, $search = '', $paged = 1 ) { |
| @@ -616,19 +531,10 @@ | ||
| 616 | 531 | if ( ! empty( $search ) ) { |
| 617 | 532 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title LIKE %s", '%' . esc_sql( $search ) . '%' ); |
| 618 | 533 | } |
| 619 | 534 | |
| 620 | - // Add a query for shop_coupon post-type to check 'show on frontend' meta. | |
| 621 | - if ( 'shop_coupon' === $post_type ) { | |
| 622 | - $where .= " AND {$wpdb->posts}.ID IN ( | |
| 623 | - SELECT post_id FROM {$wpdb->postmeta} | |
| 624 | - WHERE meta_key = 'rtsb_show_on_frontend' | |
| 625 | - AND meta_value = 'on' | |
| 626 | - )"; | |
| 627 | - } | |
| 628 | - | |
| 629 | 535 | $query = "select post_title,ID from $wpdb->posts where post_status = 'publish' {$where} {$limit}"; |
| 630 | - $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 536 | + $results = $wpdb->get_results( $query ); | |
| 631 | 537 | |
| 632 | 538 | if ( ! empty( $results ) ) { |
| 633 | 539 | foreach ( $results as $row ) { |
| 634 | 540 | $data[ $row->ID ] = $row->post_title . ' [#' . $row->ID . ']'; |
| @@ -659,10 +565,10 @@ | ||
| 659 | 565 | |
| 660 | 566 | $pro_widgets = [ |
| 661 | 567 | [ |
| 662 | 568 | 'name' => 'rtsb-ajax-product-filters', |
| 663 | - 'title' => esc_html__( 'Ajax Product Filters', 'shopbuilder' ), | |
| 664 | - 'description' => esc_html__( 'Ajax Product Filters', 'shopbuilder' ), | |
| 569 | + 'title' => esc_html__( 'Ajax Product Filters', 'testimonial-slider-showcase' ), | |
| 570 | + 'description' => esc_html__( 'Ajax Product Filters', 'testimonial-slider-showcase' ), | |
| 665 | 571 | 'icon' => 'rtsb-el-custom rtsb-element icon-rtsb-ajax-product-filters rtsb-promotional-element', |
| 666 | 572 | 'categories' => '[ "rtsb-shopbuilder" ]', |
| 667 | 573 | ], |
| 668 | 574 | ]; |
| @@ -673,49 +579,6 @@ | ||
| 673 | 579 | } |
| 674 | 580 | } |
| 675 | 581 | |
| 676 | 582 | return $config; |
| 677 | - } | |
| 678 | - | |
| 679 | - /** | |
| 680 | - * Get Icons. | |
| 681 | - * | |
| 682 | - * @return array | |
| 683 | - */ | |
| 684 | - public function get_icons() { | |
| 685 | - return [ | |
| 686 | - 'heart-empty', | |
| 687 | - 'heart', | |
| 688 | - 'eye', | |
| 689 | - 'exchange', | |
| 690 | - 'plus', | |
| 691 | - 'minus', | |
| 692 | - 'avatar', | |
| 693 | - 'pay', | |
| 694 | - 'share', | |
| 695 | - 'clock', | |
| 696 | - 'check-alt', | |
| 697 | - 'check', | |
| 698 | - 'delete', | |
| 699 | - 'marker', | |
| 700 | - 'list', | |
| 701 | - 'list-2', | |
| 702 | - 'power', | |
| 703 | - 'cart', | |
| 704 | - 'cart-2', | |
| 705 | - 'cart-3', | |
| 706 | - 'downloads', | |
| 707 | - 'zoom', | |
| 708 | - 'user-edit', | |
| 709 | - 'grid', | |
| 710 | - 'filter', | |
| 711 | - 'billing', | |
| 712 | - 'login', | |
| 713 | - 'payment', | |
| 714 | - 'search', | |
| 715 | - 'edit', | |
| 716 | - 'coupon', | |
| 717 | - 'arrows-cw', | |
| 718 | - 'trash-empty', | |
| 719 | - ]; | |
| 720 | 583 | } |
| 721 | 584 | } |