From bd1e4edb343705e74253b8ea29f7f740c5507689 Mon Sep 17 00:00:00 2001 From: Brian Hogg Date: Fri, 11 Apr 2025 10:29:58 -0400 Subject: [PATCH] Changelog. Query to avoid showing hidden products in next/previous links. --- ...ide-hidden-products-from-next-previous.yml | 5 +++ includes/class.llms.query.php | 33 ++++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 .changelogs/2910-hide-hidden-products-from-next-previous.yml diff --git a/.changelogs/2910-hide-hidden-products-from-next-previous.yml b/.changelogs/2910-hide-hidden-products-from-next-previous.yml new file mode 100644 index 0000000000..3be13891bd --- /dev/null +++ b/.changelogs/2910-hide-hidden-products-from-next-previous.yml @@ -0,0 +1,5 @@ +significance: minor +type: changed +links: + - "#2910" +entry: Avoid showing hidden courses or memberships in a theme's next/previous links. diff --git a/includes/class.llms.query.php b/includes/class.llms.query.php index 93ca30873f..0637736c31 100644 --- a/includes/class.llms.query.php +++ b/includes/class.llms.query.php @@ -54,7 +54,8 @@ public function __construct() { $this->init_query_vars(); add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ), 15 ); - + add_filter( 'get_previous_post_where', array( $this, 'exclude_hidden_llms_products' ) ); + add_filter( 'get_next_post_where', array( $this, 'exclude_hidden_llms_products' ) ); } /** @@ -80,7 +81,6 @@ public function add_endpoints() { add_rewrite_rule( $regex, $redirect, 'top' ); } } - } /** @@ -131,7 +131,6 @@ private function get_tax_query( $query = array() ) { ); return $query; - } /** @@ -147,7 +146,6 @@ public function init_query_vars() { 'confirm-payment' => get_option( 'lifterlms_myaccount_confirm_payment_endpoint', 'confirm-payment' ), 'lost-password' => get_option( 'lifterlms_myaccount_lost_password_endpoint', 'lost-password' ), ); - } /** @@ -169,7 +167,6 @@ public function parse_request() { $wp->query_vars[ $key ] = $wp->query_vars[ $var ]; } } - } /** @@ -256,7 +253,6 @@ public function pre_get_posts( $query ) { $query->set( 'tax_query', $this->get_tax_query( $query->get( 'tax_query' ) ) ); } - } /** @@ -279,7 +275,6 @@ public function maybe_404_certificate() { } } - } /** @@ -310,7 +305,6 @@ public function maybe_redirect_certificate() { llms_redirect_and_exit( get_permalink( $new_post->ID ) ); } } - } /** @@ -328,9 +322,30 @@ public function set_query_vars( $vars ) { } return $vars; - } + /** + * Avoid showing hidden products in the previous/next post queries. + * + * @since [version] + * @param $where + * + * @return string + */ + public function exclude_hidden_llms_products( $where ) { + global $wpdb; + + $where .= " AND p.ID NOT IN ( + SELECT object_id + FROM {$wpdb->term_relationships} AS tr + INNER JOIN {$wpdb->term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id + INNER JOIN {$wpdb->terms} AS t ON tt.term_id = t.term_id + WHERE tt.taxonomy = 'llms_product_visibility' + AND t.slug IN ('hidden') + )"; + + return $where; + } } return new LLMS_Query();