From cff54fd5f04853548a19c8b4defb0f30fd987b9c Mon Sep 17 00:00:00 2001 From: Mahdi Date: Thu, 22 Jun 2023 23:28:55 +0600 Subject: [PATCH] added an option to set default view type per directory --- includes/helper-functions.php | 11 ++++--- includes/model/Listings.php | 4 +-- .../class-multi-directory-manager.php | 30 +++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/includes/helper-functions.php b/includes/helper-functions.php index 18e3800d22..6034fa7645 100644 --- a/includes/helper-functions.php +++ b/includes/helper-functions.php @@ -1596,7 +1596,7 @@ function atbdp_get_listings_orderby_options($sort_by_items) * @since 4.0.0 * */ -function atbdp_get_listings_current_view_name($view) +function atbdp_get_listings_current_view_name($view, $directory_type) { @@ -1609,9 +1609,12 @@ function atbdp_get_listings_current_view_name($view) array_push($allowed_views, 'listings_with_map'); } if (!in_array($view, $allowed_views)) { - $listing_view = get_directorist_option('default_listing_view'); - $listings_settings = !empty($listing_view) ? $listing_view : 'grid'; - $view = $listings_settings; + $view = get_term_meta($directory_type, 'default_view_type', true); + if(empty($view)) { + $listing_view = get_directorist_option('default_listing_view'); + $listings_settings = !empty($listing_view) ? $listing_view : 'grid'; + $view = $listings_settings; + } } diff --git a/includes/model/Listings.php b/includes/model/Listings.php index 1f24c2ae2d..73e98d2005 100644 --- a/includes/model/Listings.php +++ b/includes/model/Listings.php @@ -239,7 +239,7 @@ public function build_search_data( $key, $value ) { public function prepare_atts_data() { $defaults = array( - 'view' => $this->options['listing_view'], + 'view' => !empty(get_term_meta($this->get_current_listing_type(), 'default_view_type', true)) ? get_term_meta($this->get_current_listing_type(), 'default_view_type', true) : $this->options['listing_view'], '_featured' => 1, 'filterby' => '', 'orderby' => $this->options['order_listing_by'], @@ -271,7 +271,7 @@ public function prepare_atts_data() { $defaults = apply_filters( 'atbdp_all_listings_params', $defaults ); $this->params = shortcode_atts( $defaults, $this->atts ); - $this->view = atbdp_get_listings_current_view_name( $this->params['view'] ); + $this->view = atbdp_get_listings_current_view_name( $this->params['view'], $this->get_current_listing_type() ); $this->_featured = $this->params['_featured']; $this->filterby = $this->params['filterby']; $this->orderby = $this->params['orderby']; diff --git a/includes/modules/multi-directory-setup/class-multi-directory-manager.php b/includes/modules/multi-directory-setup/class-multi-directory-manager.php index 7a7417bb4a..ea38d8c5da 100644 --- a/includes/modules/multi-directory-setup/class-multi-directory-manager.php +++ b/includes/modules/multi-directory-setup/class-multi-directory-manager.php @@ -4506,6 +4506,25 @@ public function prepare_settings() { ], ], ] ), + 'default_view_type' => [ + 'label' => __('Default View Type', 'directorist'), + 'type' => 'select', + 'value' => 'grid', + 'options' => [ + [ + 'label' => __('Grid', 'directorist'), + 'value' => 'grid', + ], + [ + 'label' => __('List', 'directorist'), + 'value' => 'list', + ], + [ + 'label' => __('Map', 'directorist'), + 'value' => 'map', + ], + ], + ], ]); @@ -4689,6 +4708,17 @@ public function prepare_settings() { ], ], ], + 'settings' => [ + 'label' => __( 'Settings', 'directorist' ), + 'sections' => [ + 'listings_default_view' => [ + 'title' => __('Default View', 'directorist'), + 'fields' => [ + 'default_view_type' + ], + ], + ], + ], ], ],