Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.1 Parents only query args #466

Merged
merged 6 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions assets/js/blocks/slider-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{},
Expand All @@ -52,6 +61,15 @@
filterByOnsale: value
});
}
}),
el(CheckboxControl, {
label: 'Parents Only',
checked: parentsOnly,
onChange: function (value) {
props.setAttributes({
parentsOnly: value
});
}
})
)
)
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
57 changes: 38 additions & 19 deletions includes/classes/blocks/class-registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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 );
}

/**
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
}
2 changes: 2 additions & 0 deletions includes/classes/legacy/class-destination.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );

}

/**
Expand Down Expand Up @@ -113,6 +114,7 @@ public function filter_countries( $countries = array() ) {
}
return $countries;
}


/**
* Filter the travel information and return a shortened version.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tour-operator",
"version": "1.4.9",
"version": "2.0.1",
"description": "Tour Operators for LSX",
"main": "gulpfile.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 2 additions & 8 deletions tour-operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,17 +24,11 @@
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' ) );
define( 'LSX_TO_POSTEXPIRATOR_TIMEFORMAT', esc_html__( 'g:ia', 'tour-operator' ) );

// 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',
) );*/
Loading