Skip to content

Commit

Permalink
Updated Top 10 Free from Pro
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ajaydsouza committed Sep 30, 2024
1 parent cbb06e9 commit d096e59
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
48 changes: 21 additions & 27 deletions includes/class-top-ten-core-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] );
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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'];

Expand Down Expand Up @@ -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 );
Expand Down
14 changes: 12 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/)
Expand Down Expand Up @@ -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.
4 changes: 2 additions & 2 deletions top-10.php
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand All @@ -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' );
}

/**
Expand Down

0 comments on commit d096e59

Please sign in to comment.