From d096e59992d60ca25d75f8664dee10ae13170ac9 Mon Sep 17 00:00:00 2001 From: Ajay D'Souza Date: Mon, 30 Sep 2024 22:17:51 +0100 Subject: [PATCH] Updated Top 10 Free from Pro * Modifications: * Renamed filter to: `top_ten_posts_post_types`. * Updated filter `tptn_query_args_before` to be the queried object instead of just the post. * Bug fix: * Fixed issue where admin columns setting didn't work. * Fixed: meta_query was not set. --- includes/class-top-ten-core-query.php | 48 ++++++++++++--------------- readme.txt | 14 ++++++-- top-10.php | 4 +-- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/includes/class-top-ten-core-query.php b/includes/class-top-ten-core-query.php index d234c52..bb75154 100644 --- a/includes/class-top-ten-core-query.php +++ b/includes/class-top-ten-core-query.php @@ -191,10 +191,10 @@ public function prepare_query_args( $args = array() ) { * * @since 4.0.0 * - * @param array $args The query arguments. - * @param \WP_Post $source_post The source post. + * @param array $args The query arguments. + * @param \WP_Term|\WP_Post_Type|\WP_Post|\WP_User|null $queried_object The queried object. */ - $args = apply_filters( 'tptn_query_args_before', $args, get_post() ); + $args = apply_filters( 'tptn_query_args_before', $args, get_queried_object() ); // Parse the blog_id argument to get an array of IDs. $this->blog_id = wp_parse_id_list( $args['blog_id'] ); @@ -238,7 +238,7 @@ public function prepare_query_args( $args = array() ) { * @param array $post_types Array of post types to filter by. * @param array $args Arguments array. */ - $args['post_type'] = apply_filters( 'tptn_posts_post_types', $post_types, $args ); + $args['post_type'] = apply_filters( 'top_ten_posts_post_types', $post_types, $args ); } // Tax Query. @@ -372,6 +372,8 @@ public function prepare_query_args( $args = array() ) { $meta_query['relation'] = apply_filters( 'top_ten_query_meta_query_relation', 'AND', $args ); } + $args['meta_query'] = $meta_query; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query + // Set post_status. $args['post_status'] = empty( $args['post_status'] ) ? array( 'publish', 'inherit' ) : $args['post_status']; @@ -417,29 +419,21 @@ public function prepare_query_args( $args = array() ) { public function pre_get_posts( $query ) { if ( true === $query->get( 'top_ten_query' ) ) { - if ( ! empty( $this->query_args['date_query'] ) ) { - $query->set( 'date_query', $this->query_args['date_query'] ); - } - if ( ! empty( $this->query_args['tax_query'] ) ) { - $query->set( 'tax_query', $this->query_args['tax_query'] ); - } - if ( ! empty( $this->query_args['meta_query'] ) ) { - $query->set( 'meta_query', $this->query_args['meta_query'] ); - } - if ( ! empty( $this->query_args['post_type'] ) ) { - $query->set( 'post_type', $this->query_args['post_type'] ); - } - if ( ! empty( $this->query_args['post__not_in'] ) ) { - $query->set( 'post__not_in', $this->query_args['post__not_in'] ); - } - if ( ! empty( $this->query_args['post_status'] ) ) { - $query->set( 'post_status', $this->query_args['post_status'] ); - } - if ( ! empty( $this->query_args['posts_per_page'] ) ) { - $query->set( 'posts_per_page', $this->query_args['posts_per_page'] ); - } - if ( ! empty( $this->query_args['author'] ) ) { - $query->set( 'author', $this->query_args['author'] ); + $query_args_keys = array( + 'date_query', + 'tax_query', + 'meta_query', + 'post_type', + 'post__not_in', + 'post_status', + 'posts_per_page', + 'author', + ); + + foreach ( $query_args_keys as $key ) { + if ( ! empty( $this->query_args[ $key ] ) ) { + $query->set( $key, $this->query_args[ $key ] ); + } } $query->set( 'suppress_filters', false ); diff --git a/readme.txt b/readme.txt index 3e21c0b..c6167de 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Tags: popular posts, top 10, counter, statistics, tracker Contributors: webberzone, ajay Donate link: https://ajaydsouza.com/donate/ -Stable tag: 4.0.0 +Stable tag: 4.0.1 Requires at least: 6.3 Tested up to: 6.6 Requires PHP: 7.4 @@ -149,6 +149,16 @@ When you enabled the scheduled maintenance, Top 10 will create a cron job that w == Changelog == += 4.0.1 = + +* Modifications: + * Renamed filter to: `top_ten_posts_post_types`. + * Updated filter `tptn_query_args_before` to be the queried object instead of just the post. + +* Bug fix: + * Fixed issue where admin columns setting didn't work. + * Fixed: meta_query was not set. + = 4.0.0 = Release post: [https://webberzone.com/announcements/top-10-v4-0-0/](https://webberzone.com/announcements/top-10-v4-0-0/) @@ -188,5 +198,5 @@ For previous changelog entries, please refer to the separate changelog.txt file == Upgrade Notice == -= 4.0.0 = += 4.0.1 = Major release. Top 10 Pro is here. Check out the release post or changelog for further information. diff --git a/top-10.php b/top-10.php index 6a12b27..4c2bd10 100644 --- a/top-10.php +++ b/top-10.php @@ -14,7 +14,7 @@ * Plugin Name: Top 10 * Plugin URI: https://webberzone.com/plugins/top-10/ * Description: Count daily and total visits per post and display the most popular posts based on the number of views - * Version: 4.0.0 + * Version: 4.0.1 * Author: WebberZone * Author URI: https://webberzone.com * License: GPL-2.0+ @@ -36,7 +36,7 @@ * @since 3.1.0 */ if ( ! defined( 'TOP_TEN_VERSION' ) ) { - define( 'TOP_TEN_VERSION', '4.0.0' ); + define( 'TOP_TEN_VERSION', '4.0.1' ); } /**