$hierarchical ] ) ) ) { return []; } return wp_list_pluck( adqs_get_terms( $name, [ 'hierarchical' => $hierarchical ] ), 'name', $index_type ); } /* array data join */ public function get_join_data( $data = [] ) { if ( empty( $data ) ) { return ''; } // Handle both string and array inputs if ( is_string( $data ) ) { return $data; // Already a string, return as-is } if ( is_array( $data ) ) { return join( ',', $data ); } return ''; } /** * Register listing by widget controls. * * Adds different input fields to allow the user to change and customize the widget settings. * * @since 1.0.0 * @access protected */ protected function register_controls() { $this->start_controls_section( 'section_options', [ 'label' => esc_html__( 'Options', 'adirectory' ), 'tab' => Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'top_bar_show', [ 'label' => esc_html__( 'Nav Bar Show ?', 'adirectory' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'adirectory' ), 'label_off' => esc_html__( 'No', 'adirectory' ), 'return_value' => 'true', 'default' => 'true', ] ); $this->add_control( 'search_bar_show', [ 'label' => esc_html__( 'Search Bar Show ?', 'adirectory' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'adirectory' ), 'label_off' => esc_html__( 'No', 'adirectory' ), 'return_value' => 'true', 'default' => 'true', ] ); $this->add_control( 'ajax_filter', [ 'label' => esc_html__( 'Ajax Filters ?', 'adirectory' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'adirectory' ), 'label_off' => esc_html__( 'No', 'adirectory' ), 'return_value' => 'true', 'default' => empty( adqs_get_setting_option( 'ajax_filters' ) ) ? 'false' : 'true', ] ); $this->add_control( 'pagination_type', [ 'label' => esc_html__( 'Layout With Type', 'adirectory' ), 'type' => Controls_Manager::SELECT, 'label_block' => true, 'multiple' => true, 'options' => [ '' => esc_html__( 'Default', 'adirectory' ), 'pagination' => esc_html__( 'Pagination', 'adirectory' ), 'carousel' => esc_html__( 'Carousel', 'adirectory' ), ], 'default' => 'pagination', ] ); $this->end_controls_section(); // end: Section $this->start_controls_section( 'section_query', [ 'label' => esc_html__( 'Taxonomy Query', 'adirectory' ), 'tab' => Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'tax_type', [ 'label' => esc_html__( 'Taxonomy Type', 'adirectory' ), 'type' => Controls_Manager::SELECT, 'options' => [ 'categories' => esc_html__( 'Categories', 'adirectory' ), 'locations' => esc_html__( 'Locations', 'adirectory' ), ], 'default' => 'categories', ] ); $directory_types = wp_list_pluck( adqs_get_directories(), 'name', 'slug' ) ?? []; $this->add_control( 'custom_directory', [ 'label' => esc_html__( 'Include Directories', 'adirectory' ), 'type' => \Elementor\Controls_Manager::SELECT2, 'label_block' => true, 'multiple' => true, 'options' => $directory_types, ] ); $this->add_control( 'directory_dropdown', [ 'label' => esc_html__( 'Directory Dropdown After', 'adirectory' ), 'type' => Controls_Manager::NUMBER, 'min' => 1, 'step' => 1, 'default' => 5, ] ); // With shared taxonomies we only need single controls for categories and locations. // Add a single shared categories control (uses shared taxonomy 'adqs_category'). if ( ! empty( $this->getTerms( 'adqs_category', 'slug' ) ) ) { $this->add_control( 'adqs_category', [ 'label' => esc_html__( 'Include Categories', 'adirectory' ), 'type' => \Elementor\Controls_Manager::SELECT2, 'label_block' => true, 'multiple' => true, 'options' => $this->getTerms( 'adqs_category', 'slug' ), 'separator' => 'before', 'conditions' => [ 'terms' => [ [ 'name' => 'tax_type', 'operator' => '===', 'value' => 'categories', ], ], ], ] ); } // Add a single shared locations control (uses shared taxonomy 'adqs_location'). if ( ! empty( $this->getTerms( 'adqs_location', 'slug' ) ) ) { $this->add_control( 'adqs_location', [ 'label' => esc_html__( 'Include Locations', 'adirectory' ), 'type' => \Elementor\Controls_Manager::SELECT2, 'label_block' => true, 'multiple' => true, 'options' => $this->getTerms( 'adqs_location', 'slug' ), 'separator' => 'before', 'conditions' => [ 'terms' => [ [ 'name' => 'tax_type', 'operator' => '===', 'value' => 'locations', ], ], ], ] ); } $this->add_control( 'order', [ 'label' => esc_html__( 'Order', 'adirectory' ), 'type' => Controls_Manager::SELECT, 'options' => [ 'ASC' => esc_html__( 'ASC', 'adirectory' ), 'DESC' => esc_html__( 'DESC', 'adirectory' ), ], 'default' => 'ASC', ] ); $this->add_control( 'orderby', [ 'label' => esc_html__( 'Order By', 'adirectory' ), 'type' => Controls_Manager::SELECT, 'options' => [ 'name' => esc_html__( 'Name', 'adirectory' ), 'slug' => esc_html__( 'Slug', 'adirectory' ), 'term_id' => esc_html__( 'Term Id', 'adirectory' ), 'term_order' => esc_html__( 'Term Order', 'adirectory' ), 'count' => esc_html__( 'Count', 'adirectory' ), ], 'default' => 'count', ] ); $this->add_control( 'per_page', [ 'label' => esc_html__( 'Per Page Items', 'adirectory' ), 'type' => Controls_Manager::NUMBER, 'min' => -1, 'step' => 1, 'default' => 10, ] ); $this->end_controls_section(); // end: Section // Carousel setting $this->start_controls_section( 'slider_option', [ 'label' => esc_html__( 'Carousel Option', 'adirectory' ), 'condition' => [ 'pagination_type' => 'carousel', ], ] ); $this->add_responsive_control( 'slitems', [ 'label' => esc_html__( 'Slider Items', 'adirectory' ), 'type' => Controls_Manager::NUMBER, 'min' => 1, 'max' => 20, 'step' => 1, 'default' => 3, ] ); $this->add_responsive_control( 'slrows', [ 'label' => esc_html__( 'Slider Rows', 'adirectory' ), 'type' => Controls_Manager::NUMBER, 'min' => 0, 'max' => 5, 'step' => 1, ] ); $this->add_control( 'slarrows', [ 'label' => esc_html__( 'Slider Arrow', 'adirectory' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'separator' => 'before', 'default' => 'yes', ] ); $this->add_responsive_control( 'slitemmargin', [ 'label' => esc_html__( 'Slider Item Margin', 'adirectory' ), 'type' => Controls_Manager::NUMBER, 'min' => 0, 'max' => 100, 'step' => 1, 'default' => 1, 'selectors' => [ '{{WRAPPER}} .qsd-tax-grid-single' => 'margin-left: {{VALUE}}px;margin-right:{{VALUE}}px;', '{{WRAPPER}} .slick-list' => 'margin-left: -{{VALUE}}px;margin-right: -{{VALUE}}px;', ], ] ); $this->add_control( 'sldots', [ 'label' => esc_html__( 'Slider dots', 'adirectory' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'separator' => 'before', 'default' => 'no', ] ); $this->add_control( 'slpause_on_hover', [ 'type' => Controls_Manager::SWITCHER, 'label_off' => __( 'No', 'adirectory' ), 'label_on' => __( 'Yes', 'adirectory' ), 'return_value' => 'yes', 'separator' => 'before', 'default' => 'yes', 'label' => __( 'Pause on Hover?', 'adirectory' ), ] ); $this->add_control( 'slcentermode', [ 'label' => esc_html__( 'Center Mode', 'adirectory' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'separator' => 'before', 'default' => 'no', ] ); $this->add_control( 'slcenterpadding', [ 'label' => esc_html__( 'Center padding', 'adirectory' ), 'type' => Controls_Manager::NUMBER, 'min' => 0, 'max' => 500, 'step' => 1, 'default' => 50, 'condition' => [ 'slcentermode' => 'yes', ], ] ); $this->add_control( 'slfade', [ 'label' => esc_html__( 'Slider Fade', 'adirectory' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'separator' => 'before', 'default' => 'no', ] ); $this->add_control( 'slfocusonselect', [ 'label' => esc_html__( 'Focus On Select', 'adirectory' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'separator' => 'before', 'default' => 'no', ] ); $this->add_control( 'slvertical', [ 'label' => esc_html__( 'Vertical Slide', 'adirectory' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'separator' => 'before', 'default' => 'no', ] ); $this->add_control( 'slinfinite', [ 'label' => esc_html__( 'Infinite', 'adirectory' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'separator' => 'before', 'default' => 'yes', ] ); $this->add_control( 'slrtl', [ 'label' => esc_html__( 'RTL Slide', 'adirectory' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'separator' => 'before', 'default' => 'no', ] ); $this->add_control( 'slautoplay', [ 'label' => esc_html__( 'Slider auto play', 'adirectory' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'separator' => 'before', 'default' => 'no', ] ); $this->add_control( 'slautoplay_speed', [ 'label' => __( 'Autoplay speed', 'adirectory' ), 'type' => Controls_Manager::NUMBER, 'default' => 3000, ] ); $this->add_control( 'slanimation_speed', [ 'label' => __( 'Autoplay animation speed', 'adirectory' ), 'type' => Controls_Manager::NUMBER, 'default' => 300, ] ); $this->add_control( 'slscroll_columns', [ 'label' => __( 'Slider item to scroll', 'adirectory' ), 'type' => Controls_Manager::NUMBER, 'min' => 1, 'max' => 10, 'step' => 1, 'default' => 1, ] ); $this->end_controls_section(); /* ----------------------- SLIDER OPTIONS END -------------------------*/ $this->start_controls_section( 'golbal_color', [ 'label' => esc_html__( 'Global Color', 'adirectory' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'golbal_primary_color', [ 'label' => esc_html__( 'Primary Color', 'adirectory' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}}' => '--color-primary: {{VALUE}}', ], ] ); $this->add_control( 'golbal_secondary_color', [ 'label' => esc_html__( 'Secondary Color', 'adirectory' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}}' => '--color-secondary: {{VALUE}}', ], ] ); $this->end_controls_section(); /* ------------------------------ GOLOBAL STYLE OPTIONS END -------------------------------*/ /* ----------------------- SLIDER OPTIONS END -------------------------*/ $this->start_controls_section( 'tax_section_styles', [ 'label' => esc_html__( 'Column Style', 'adirectory' ), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->add_responsive_control( 'column_basis', [ 'label' => esc_html__( 'Columns Basis', 'adirectory' ), 'type' => Controls_Manager::SLIDER, 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ], 'range' => [ '%' => [ 'min' => 0, 'max' => 100, ], 'px' => [ 'min' => 0, 'max' => 1000, ], 'vw' => [ 'min' => 0, 'max' => 100, ], ], 'condition' => [ 'pagination_type!' => 'carousel', ], 'selectors' => [ '{{WRAPPER}} .qsd-select-category-grid-item .qsd-tax-grid-single' => '-webkit-flex-basis: {{SIZE}}{{UNIT}} !important;flex-basis: {{SIZE}}{{UNIT}} !important;', ], ] ); $this->add_responsive_control( 'column_gap', [ 'label' => esc_html__( 'Columns Gap', 'adirectory' ), 'type' => Controls_Manager::SLIDER, 'size_units' => [ '%', 'px', 'vw' ], 'range' => [ '%' => [ 'min' => 0, 'max' => 100, ], 'px' => [ 'min' => 0, 'max' => 1000, ], 'vw' => [ 'min' => 0, 'max' => 100, ], ], 'condition' => [ 'pagination_type!' => 'carousel', ], 'selectors' => [ '{{WRAPPER}} .qsd-select-category-grid-item' => 'gap: {{SIZE}}{{UNIT}} !important;', ], ] ); $this->end_controls_section(); } /** * Render Advanced Products widget output on the frontend. * * Written in PHP and used to generate the final HTML. * * @since 1.0.0 * @access protected */ protected function render() { $settings = $this->get_settings_for_display(); $action_elementor = Plugin::instance()->editor->is_edit_mode() ? true : false; $tax_type = $settings['tax_type'] ?? 'categories'; $top_bar_show = $settings['top_bar_show'] ?? 'true'; $search_bar_show = $settings['search_bar_show'] ?? 'true'; $ajax_filter = $settings['ajax_filter'] ?? ''; $pagination_type = $settings['pagination_type'] ?? 'pagination'; $order = $settings['order'] ?? 'DESC'; $orderby = $settings['orderby'] ?? 'count'; $per_page = $settings['per_page'] ?? 10; $directory_dropdown = $settings['directory_dropdown'] ?? 5; $style_type = $settings['style_type'] ?? ''; // Handle multi-directory taxonomies $custom_directory = $this->get_join_data( $settings['custom_directory'] ?? [] ); // Taxonomies are now static and shared across all post types // Collect terms from settings (works with or without custom_directory) $terms = []; $taxonomy_name = ( $tax_type === 'locations' ) ? 'adqs_location' : 'adqs_category'; if ( $tax_type === 'locations' && ! empty( $settings['adqs_location'] ) ) { $terms[ $taxonomy_name ] = join( ',', array_values( array_unique( (array) $settings['adqs_location'] ) ) ); } elseif ( $tax_type === 'categories' && ! empty( $settings['adqs_category'] ) ) { $terms[ $taxonomy_name ] = join( ',', array_values( array_unique( (array) $settings['adqs_category'] ) ) ); } $breakpoints = \Elementor\Plugin::$instance->breakpoints->get_active_breakpoints(); $responsiveBreakpoints = []; foreach ( $breakpoints as $key => $breakpoint ) { $responsiveBreakpoints[ $key ] = $breakpoint->is_enabled() ? $breakpoint->get_value() : 0; } $carousel_settings = []; if ( $pagination_type === 'carousel' ) { $carousel_settings = [ 'arrows' => ( 'yes' === ( $settings['slarrows'] ?? '' ) ), 'dots' => ( 'yes' === ( $settings['sldots'] ?? '' ) ), 'autoplay' => ( 'yes' === ( $settings['slautoplay'] ?? '' ) ), 'autoplay_speed' => absint( $settings['slautoplay_speed'] ?? 3000 ), 'animation_speed' => absint( $settings['slanimation_speed'] ?? 300 ), 'pause_on_hover' => ( 'yes' === ( $settings['slpause_on_hover'] ?? '' ) ), 'center_mode' => ( 'yes' === ( $settings['slcentermode'] ?? '' ) ), 'center_padding' => ! empty( $settings['slcenterpadding'] ?? '' ) ? $settings['slcenterpadding'] . 'px' : '50px', 'rows' => absint( $settings['slrows'] ?? 1 ), 'fade' => ( 'yes' === ( $settings['slfade'] ?? '' ) ), 'focusonselect' => ( 'yes' === ( $settings['slfocusonselect'] ?? '' ) ), 'vertical' => ( 'yes' === ( $settings['slvertical'] ?? '' ) ), 'rtl' => ( 'yes' === ( $settings['slrtl'] ?? '' ) ), 'infinite' => ( 'yes' === ( $settings['slinfinite'] ?? '' ) ), 'display_columns' => absint( $settings['slitems'] ?? 3 ), 'display_scroll' => absint( $settings['slrows'] ?? 1 ), 'display_columns_widescreen' => isset( $responsiveBreakpoints['widescreen'] ) ? absint( $settings['slitems_widescreen'] ?? 0 ) : 0, 'display_scroll_widescreen' => isset( $responsiveBreakpoints['widescreen'] ) ? absint( $settings['slrows_widescreen'] ?? 0 ) : 0, 'display_columns_laptop' => absint( $settings['slitems_laptop'] ?? 0 ), 'display_scroll_laptop' => absint( $settings['slrows_laptop'] ?? 0 ), 'display_columns_tablet_extra' => absint( $settings['slitems_tablet_extra'] ?? 0 ), 'display_scroll_tablet_extra' => absint( $settings['slrows_tablet_extra'] ?? 0 ), 'display_columns_tablet' => absint( $settings['slitems_tablet'] ?? 0 ), 'display_scroll_tablet' => absint( $settings['slrows_tablet'] ?? 0 ), 'display_columns_mobile_extra' => absint( $settings['slitems_mobile_extra'] ?? 0 ), 'display_scroll_mobile_extra' => absint( $settings['slrows_mobile_extra'] ?? 0 ), 'display_columns_mobile' => absint( $settings['slitems_mobile'] ?? 0 ), 'display_scroll_mobile' => absint( $settings['slrows_mobile'] ?? 0 ), 'responsive_breakpoints' => $responsiveBreakpoints, ]; } $uniqId = uniqid(); $carousel_settings['uniq_id'] = $uniqId; $carousel_settings = wp_json_encode( $carousel_settings ); $terms = ! empty( $terms ) ? wp_json_encode( $terms ) : ''; $shortcode = "[adqs_taxonomies custom_directory='{$custom_directory}' tax_type='{$tax_type}' top_bar_show='{$top_bar_show}' search_bar_show='{$search_bar_show}' ajax_filter='{$ajax_filter}' pagination_type='{$pagination_type}' per_page='{$per_page}' terms='{$terms}' order='{$order}' orderby='{$orderby}' carousel_settings='{$carousel_settings}' uniq_id='{$uniqId}' directory_dropdown='{$directory_dropdown}' style_type='{$style_type}' from_addon='true' ]"; echo do_shortcode( $shortcode ); } /** * Render Advanced Products widget output in the editor. * * Written as a Backbone JavaScript template and used to generate the live preview. * * @since 1.0.0 * @access protected */ // protected function _content_template(){} } Plugin::instance()->widgets_manager->register( new Listing_Taxonomy() );