From 1f31e11ff016cba96ea1b4bc0a0add757761311c Mon Sep 17 00:00:00 2001 From: Warwick Date: Tue, 7 Jan 2025 15:51:49 +0200 Subject: [PATCH 1/6] Adding in the parents only filter. --- assets/js/blocks/slider-query.js | 24 ++++++++ .../classes/blocks/class-registration.php | 57 ++++++++++++------- includes/classes/legacy/class-destination.php | 2 + 3 files changed, 64 insertions(+), 19 deletions(-) diff --git a/assets/js/blocks/slider-query.js b/assets/js/blocks/slider-query.js index 807de78c..da2862b5 100644 --- a/assets/js/blocks/slider-query.js +++ b/assets/js/blocks/slider-query.js @@ -28,6 +28,15 @@ filterByOnsale = props.attributes.filterByOnsale; } + var parentsOnly = props.attributes.parentsOnly || false; + if ( undefined === props.attributes.parentsOnly ) { + if ( props.attributes.className && props.attributes.className.includes( 'parents-only' ) ) { + parentsOnly = true; + } + } else { + parentsOnly = props.attributes.parentsOnly; + } + return el( element.Fragment, {}, @@ -52,6 +61,15 @@ filterByOnsale: value }); } + }), + el(CheckboxControl, { + label: 'Parents Only', + checked: parentsOnly, + onChange: function (value) { + props.setAttributes({ + parentsOnly: value + }); + } }) ) ) @@ -87,6 +105,12 @@ extraProps.className = extraProps.className.replace(/\bon-sale\b\s*/g, '').trim(); } + if ( true === attributes.parentsOnly ) { + extraProps.className = (extraProps.className || '') + ' parents-only'; + } else if ( false === attributes.parentsOnly && extraProps.className ) { + extraProps.className = extraProps.className.replace(/\bparents-only\b\s*/g, '').trim(); + } + } return extraProps; } diff --git a/includes/classes/blocks/class-registration.php b/includes/classes/blocks/class-registration.php index 4a6a3bdd..6771442d 100644 --- a/includes/classes/blocks/class-registration.php +++ b/includes/classes/blocks/class-registration.php @@ -25,6 +25,13 @@ class Registration { */ protected $onsale = false; + /** + * True if the current query outputting needs only the parent outputs. + * + * @var boolean + */ + protected $parents_only = false; + /** * Initialize the plugin by setting localization, filters, and administration functions. * @@ -37,9 +44,8 @@ public function __construct() { add_filter( 'query_loop_block_query_vars', array( $this, 'query_args_filter' ), 1, 2 ); add_filter( 'render_block', array( $this, 'maybe_hide_varitaion' ), 10, 3 ); + add_filter( 'render_block_data', array( $this, 'save_checkbox_queries' ), 10, 1 ); add_filter( 'posts_pre_query', array( $this, 'posts_pre_query' ), 10, 2 ); - - add_filter( 'render_block_data', array( $this, 'save_onsale_queries' ), 10, 1 ); } /** @@ -108,11 +114,31 @@ public function enqueue_block_variations_script() { public function query_args_filter( $query, $block ) { $block = $block->parsed_block; + // These are for all query blocks. + if ( true === $this->onsale ) { + if ( isset( $query['meta_query']['relation'] ) ) { + $query['meta_query']['relation'] = 'AND'; + } + $query['meta_query'][] = array( + 'key' => 'sale_price', + 'compare' => 'EXISTS', + ); + + // reset this to false for the next query. + $this->onsale = false; + } + + + if ( true === $this->parents_only ) { + $query['post_parent'] = 0; + } + // Determine if this is the custom block variation. if ( ! isset( $block['attrs']['className'] ) ) { return $query; } - + + // Add our specific query args to the query for our variations. $pattern = "/(lsx|facts)-(.*?)-query/"; preg_match( $pattern, $block['attrs']['className'], $matches ); @@ -258,20 +284,6 @@ public function query_args_filter( $query, $block ) { break; } - // Look for the "on sale" CSS class. - if ( true === $this->onsale ) { - if ( isset( $query['meta_query']['relation'] ) ) { - $query['meta_query']['relation'] = 'AND'; - } - $query['meta_query'][] = array( - 'key' => 'sale_price', - 'compare' => 'EXISTS', - ); - - // reset this to false for the next query. - $this->onsale = false; - } - return $query; } @@ -477,7 +489,7 @@ public function find_featured_items( $query ) { * @param array $parsed_block * @return array */ - public function save_onsale_queries( $parsed_block ) { + public function save_checkbox_queries( $parsed_block ) { if ( ! isset( $parsed_block['blockName'] ) || ! isset( $parsed_block['attrs'] ) ) { return $parsed_block; } @@ -488,15 +500,22 @@ public function save_onsale_queries( $parsed_block ) { if ( ! in_array( $parsed_block['blockName'], $allowed_blocks, true ) ) { return $parsed_block; } + if ( ! isset( $parsed_block['attrs']['className'] ) || '' === $parsed_block['attrs']['className'] || false === $parsed_block['attrs']['className'] ) { return $parsed_block; } $this->onsale = false; - if ( false !== stripos( $parsed_block['attrs']['className'], 'on-sale' ) ) { $this->onsale = true; } + + $this->parents_only = false; + if ( false !== stripos( $parsed_block['attrs']['className'], 'parents-only' ) ) { + $this->parents_only = true; + } + do_action( 'qm/debug', $this->parents_only ); + return $parsed_block; } } diff --git a/includes/classes/legacy/class-destination.php b/includes/classes/legacy/class-destination.php index cbad203a..2ecb779d 100644 --- a/includes/classes/legacy/class-destination.php +++ b/includes/classes/legacy/class-destination.php @@ -62,6 +62,7 @@ private function __construct() { add_filter( 'lsx_to_custom_field_query', array( $this, 'travel_information_excerpt' ), 5, 10 ); add_action( 'wp_footer', array( $this, 'output_modals' ) ); + } /** @@ -113,6 +114,7 @@ public function filter_countries( $countries = array() ) { } return $countries; } + /** * Filter the travel information and return a shortened version. From f08366f7c9c23a0ef1741d2fbe51304a2fa52515 Mon Sep 17 00:00:00 2001 From: Warwick Date: Tue, 7 Jan 2025 15:53:28 +0200 Subject: [PATCH 2/6] Updating the changelog --- changelog.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/changelog.md b/changelog.md index 26fb6ce0..0fae9db8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # Changelog +## [[2.0.1]](https://github.com/lightspeeddevelopment/tour-operator/releases/tag/2.0.1) - + +### Added +- A "Parents Only" checkbox to the TO query block settings, allowing you to select only the parent destinations. + ## [[2.0.0]](https://github.com/lightspeeddevelopment/tour-operator/releases/tag/2.0.0) - 20-12-2024 ### Enhancements From 0a19d6c24ea10e9d4b2531a5ce678d1cdc73b61d Mon Sep 17 00:00:00 2001 From: Warwick Date: Tue, 7 Jan 2025 15:54:22 +0200 Subject: [PATCH 3/6] Updating the version number --- package.json | 2 +- readme.txt | 2 +- tour-operator.php | 10 ++-------- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index fca910b4..225254b8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tour-operator", - "version": "1.4.9", + "version": "2.0.1", "description": "Tour Operators for LSX", "main": "gulpfile.js", "scripts": { diff --git a/readme.txt b/readme.txt index 2bdd9afb..56babcee 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: lsx, tour operator, travel, tourism, itinerary Requires at least: 6.7 Tested up to: 6.7 Requires PHP: 8.0 -Stable tag: 2.0.0 +Stable tag: 2.0.1 License: GPLv3 or later License URI: https://www.gnu.org/licenses/gpl-3.0.html diff --git a/tour-operator.php b/tour-operator.php index 0d9dfa64..804bbe2d 100644 --- a/tour-operator.php +++ b/tour-operator.php @@ -5,7 +5,7 @@ * Description: Showcase tours, destinations, and accommodations with digital itineraries, galleries, and integrated maps. * Author: lightspeedwp * Author URI: https://lightspeedwp.agency/ - * Version: 2.0.0 + * Version: 2.0.1 * Requires at least: 6.7 * Tested up to: 6.7 * Requires PHP: 8.0 @@ -24,7 +24,7 @@ define( 'LSX_TO_PATH', plugin_dir_path( __FILE__ ) ); define( 'LSX_TO_CORE', __FILE__ ); define( 'LSX_TO_URL', plugin_dir_url( __FILE__ ) ); -define( 'LSX_TO_VER', '2.0.0' ); +define( 'LSX_TO_VER', '2.0.1' ); // Post Expirator. define( 'LSX_TO_POSTEXPIRATOR_DATEFORMAT', esc_html__( 'l F jS, Y', 'tour-operator' ) ); @@ -32,9 +32,3 @@ // Include bootstrapper and start plugin. require_once LSX_TO_PATH . 'tour-operator-bootstrap.php'; - -// Register activation hook. -/*register_activation_hook( LSX_TO_CORE, array( - 'Tour_Operator', - 'register_activation_hook', -) );*/ From 2ce4e8a55f1f25f6cab36b7a3cbc25bd02a85c96 Mon Sep 17 00:00:00 2001 From: Warwick Date: Tue, 7 Jan 2025 21:35:34 +0200 Subject: [PATCH 4/6] Fixing the query args. --- .../classes/blocks/class-registration.php | 2 +- includes/classes/blocks/class-templates.php | 18 +------ includes/classes/legacy/class-destination.php | 47 +++++++++++++++++++ includes/classes/legacy/class-frontend.php | 2 +- templates/archive-destination.html | 7 ++- 5 files changed, 55 insertions(+), 21 deletions(-) diff --git a/includes/classes/blocks/class-registration.php b/includes/classes/blocks/class-registration.php index 6771442d..91b3a169 100644 --- a/includes/classes/blocks/class-registration.php +++ b/includes/classes/blocks/class-registration.php @@ -128,10 +128,10 @@ public function query_args_filter( $query, $block ) { $this->onsale = false; } - if ( true === $this->parents_only ) { $query['post_parent'] = 0; } + // Determine if this is the custom block variation. if ( ! isset( $block['attrs']['className'] ) ) { diff --git a/includes/classes/blocks/class-templates.php b/includes/classes/blocks/class-templates.php index a7c14f27..21473379 100644 --- a/includes/classes/blocks/class-templates.php +++ b/includes/classes/blocks/class-templates.php @@ -81,23 +81,7 @@ public function register_post_type_templates() { 'search-results' => [ 'title' => __( 'Search Results', 'tour-operator' ), 'description' => __( 'Displays when a visitor performs a search on your website.', 'tour-operator' ), - ], - 'index' => [ - 'title' => __( 'Index', 'tour-operator' ), - 'description' => __( 'Used as a fallback template for all pages when a more specific template is not defined.', 'tour-operator' ), - ], - 'no-title' => [ - 'title' => __( 'No Title', 'tour-operator' ), - 'description' => __( 'A generic page template with no page title displayed', 'tour-operator' ), - ], - 'pages' => [ - 'title' => __( 'Pages', 'tour-operator' ), - 'description' => __( 'A generic page template with a page title displayed', 'tour-operator' ), - ], - 'archive' => [ - 'title' => __( 'All Archives', 'tour-operator' ), - 'description' => __( 'Displays any archive, including posts by a single author, category, tag, taxonomy, custom post type, and date. This template will serve as a fallback when more specific templates (e.g., Category or Tag) cannot be found.', 'tour-operator' ), - ], + ] ]; foreach ( $post_types as $key => $labels ) { diff --git a/includes/classes/legacy/class-destination.php b/includes/classes/legacy/class-destination.php index 2ecb779d..206cff4a 100644 --- a/includes/classes/legacy/class-destination.php +++ b/includes/classes/legacy/class-destination.php @@ -60,6 +60,8 @@ private function __construct() { add_filter( 'lsx_to_parents_only', array( $this, 'filter_countries' ) ); add_filter( 'lsx_to_custom_field_query', array( $this, 'travel_information_excerpt' ), 5, 10 ); + add_filter( 'facetwp_query_args', [ $this, 'facet_wp_filter' ] , 10, 2 ); + add_action( 'pre_get_posts', [ $this, 'only_parent_destinations' ] ); add_action( 'wp_footer', array( $this, 'output_modals' ) ); @@ -114,6 +116,51 @@ public function filter_countries( $countries = array() ) { } return $countries; } + + public function only_parent_destinations( $query ) { + // Only run on the front end and for the main query + if ( ! is_admin() && $query->is_main_query() ) { + + // If the query is for the 'destination' post type + $queried_post_type = $query->get( 'post_type' ); + + // Sometimes it's an array, so normalize + if ( is_array( $queried_post_type ) ) { + $queried_post_type = reset( $queried_post_type ); + } + + if ( 'destination' === $queried_post_type ) { + // Show only top-level + $query->set( 'post_parent', 0 ); + + // Alphabetical by title + $query->set( 'orderby', 'title' ); + $query->set( 'order', 'ASC' ); + + // Make sure pagination is not disabled + $query->set( 'posts_per_page', 12 ); // or your desired number + $query->set( 'paged', get_query_var( 'paged' ) ); + $query->set( 'nopaging', false ); + } + } + } + + /** + * Sets the destination archive to only show top-level destinations + * + * @param array $args + * @param array $facet + * @return array + */ + public function facet_wp_filter( $args, $facet ) { + if ( is_post_type_archive( 'destination' ) ) { + $args['post_parent'] = 0; + $args['orderby'] = 'title'; + $args['order'] = 'ASC'; + $args['posts_per_page'] = 12; + } + return $args; + } /** diff --git a/includes/classes/legacy/class-frontend.php b/includes/classes/legacy/class-frontend.php index 87b499e3..643eec86 100644 --- a/includes/classes/legacy/class-frontend.php +++ b/includes/classes/legacy/class-frontend.php @@ -61,7 +61,7 @@ public function __construct() { } // add_filter( 'the_terms', array( $this, 'links_new_window' ), 10, 2 ); - $this->maps = Maps::get_instance(); + //$this->maps = Maps::get_instance(); add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); diff --git a/templates/archive-destination.html b/templates/archive-destination.html index eded0f9c..06218070 100644 --- a/templates/archive-destination.html +++ b/templates/archive-destination.html @@ -29,8 +29,11 @@ -
-
+
+ + + +
From be5e8ddf72c92c30aa32fe57d52503380d5825a1 Mon Sep 17 00:00:00 2001 From: Warwick Date: Wed, 8 Jan 2025 11:18:26 +0200 Subject: [PATCH 5/6] Updating hte last of the query args --- includes/classes/legacy/class-destination.php | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/includes/classes/legacy/class-destination.php b/includes/classes/legacy/class-destination.php index 206cff4a..f67f87ee 100644 --- a/includes/classes/legacy/class-destination.php +++ b/includes/classes/legacy/class-destination.php @@ -119,29 +119,18 @@ public function filter_countries( $countries = array() ) { public function only_parent_destinations( $query ) { // Only run on the front end and for the main query - if ( ! is_admin() && $query->is_main_query() ) { - - // If the query is for the 'destination' post type - $queried_post_type = $query->get( 'post_type' ); - - // Sometimes it's an array, so normalize - if ( is_array( $queried_post_type ) ) { - $queried_post_type = reset( $queried_post_type ); - } - - if ( 'destination' === $queried_post_type ) { - // Show only top-level - $query->set( 'post_parent', 0 ); - - // Alphabetical by title - $query->set( 'orderby', 'title' ); - $query->set( 'order', 'ASC' ); - - // Make sure pagination is not disabled - $query->set( 'posts_per_page', 12 ); // or your desired number - $query->set( 'paged', get_query_var( 'paged' ) ); - $query->set( 'nopaging', false ); - } + if ( ! is_admin() && $query->is_main_query() && $query->is_post_type_archive( 'destination' ) ) { + // Show only top-level + $query->set( 'post_parent', 0 ); + + // Alphabetical by title + $query->set( 'orderby', 'title' ); + $query->set( 'order', 'ASC' ); + + // Make sure pagination is not disabled + $query->set( 'posts_per_page', 12 ); // or your desired number + $query->set( 'paged', get_query_var( 'paged' ) ); + $query->set( 'nopaging', false ); } } @@ -161,7 +150,6 @@ public function facet_wp_filter( $args, $facet ) { } return $args; } - /** * Filter the travel information and return a shortened version. From c972c84224e2b51564fddc04d547ea6d204a356d Mon Sep 17 00:00:00 2001 From: Warwick Date: Wed, 8 Jan 2025 13:22:40 +0200 Subject: [PATCH 6/6] Removing the SVG uploader --- includes/classes/admin/class-admin.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/includes/classes/admin/class-admin.php b/includes/classes/admin/class-admin.php index ca02c079..77586706 100644 --- a/includes/classes/admin/class-admin.php +++ b/includes/classes/admin/class-admin.php @@ -22,21 +22,10 @@ class Admin { * LSX Tour Operator Admin constructor. */ public function __construct() { - add_filter( 'upload_mimes', array( $this, 'allow_svgimg_types' ) ); add_filter( 'type_url_form_media', array( $this, 'change_attachment_field_button' ), 20, 1 ); add_filter( 'plugin_action_links_' . plugin_basename( LSX_TO_CORE ), array( $this, 'add_action_links' ) ); } - /** - * Allow SVG files for upload - */ - public function allow_svgimg_types( $mimes ) { - $mimes['svg'] = 'image/svg+xml'; - $mimes['kml'] = 'image/kml+xml'; - - return $mimes; - } - /** * Change the "Insert into Post" button text when media modal is used for * feature images