Skip to content

Commit

Permalink
Merge branch 'cabrerahector:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
sekedus authored Mar 24, 2024
2 parents 930495c + e29165e commit d1fc9cb
Show file tree
Hide file tree
Showing 8 changed files with 841 additions and 483 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": [
[
"@babel/plugin-proposal-class-properties"
"transform-class-properties"
]
]
}
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

## 6.4.2 ##

- Fixes default thumbnail resetting to the stock "No Thumbnail" image (props to aalmans!)
- Fixes filtering by category / taxonomy when using Polylang (props to mlepore and wpfed!)
- Updates dependencies.

[Release notes](https://cabrerahector.com/wordpress/wordpress-popular-posts-6-4-shortcode-enhancements-new-rest-api-endpoints/#6.4.2)

## 6.4.1 ##

- Adds support for webp images.
Expand Down
1,212 changes: 768 additions & 444 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wordpress-popular-posts",
"version": "6.4.1",
"version": "6.4.2",
"description": "A highly customizable widget that displays your most popular posts.",
"main": "index.js",
"scripts": {
Expand All @@ -23,12 +23,12 @@
},
"homepage": "https://github.com/cabrerahector/wordpress-popular-posts#readme",
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/preset-env": "^7.23.9",
"babel-plugin-transform-class-properties": "^6.24.1",
"@babel/preset-env": "^7.24.0",
"@babel/preset-react": "^7.23.3",
"@wordpress/scripts": "^27.3.0"
"@wordpress/scripts": "^27.4.0"
},
"dependencies": {
"caniuse-lite": "^1.0.30001580"
"caniuse-lite": "^1.0.30001596"
}
}
12 changes: 10 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Contributors: hcabrera
Donate link: https://ko-fi.com/cabrerahector
Tags: popular, posts, widget, popularity, top
Requires at least: 5.3
Tested up to: 6.4.1
Tested up to: 6.4.3
Requires PHP: 7.2
Stable tag: 6.4.1
Stable tag: 6.4.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -109,6 +109,14 @@ The FAQ section has been moved [here](https://github.com/cabrerahector/wordpress

== Changelog ==

= 6.4.2 =

- Fixes default thumbnail resetting to the stock "No Thumbnail" image (props to aalmans!)
- Fixes filtering by category / taxonomy when using Polylang (props to mlepore and wpfed!)
- Updates dependencies.

[Release notes](https://cabrerahector.com/wordpress/wordpress-popular-posts-6-4-shortcode-enhancements-new-rest-api-endpoints/#6.4.2)

= 6.4.1 =

- Adds support for webp images.
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

$this->config['tools']['thumbnail']['source'] = sanitize_text_field($_POST['thumb_source']);
$this->config['tools']['thumbnail']['field'] = ( ! empty($_POST['thumb_field']) ) ? sanitize_text_field($_POST['thumb_field']) : 'wpp_thumbnail';
$this->config['tools']['thumbnail']['default'] = ( ! empty($_POST['upload_thumb_src']) ) ? $_POST['upload_thumb_src'] : '';
$this->config['tools']['thumbnail']['default'] = ( ! empty($_POST['upload_thumb_src']) ) ? $_POST['upload_thumb_src'] : $this->config['tools']['thumbnail']['default'];
$this->config['tools']['thumbnail']['resize'] = (bool) $_POST['thumb_field_resize'];
$this->config['tools']['thumbnail']['lazyload'] = (bool) $_POST['thumb_lazy_load'];

Expand Down
74 changes: 46 additions & 28 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ private function build_query()
&& ! empty($term_IDs_for_taxonomies)
) {

$tax_query_args = [];
$tax_terms = [];

foreach( $taxonomies as $taxIndex => $taxonomy ) {
Expand All @@ -233,38 +232,57 @@ private function build_query()
foreach( $tax_terms as $taxonomy => $terms ) {

if ( ! empty($terms['term_id_include']) ) {
$terms['term_id_include'] = array_unique($terms['term_id_include']);
$where .= " AND p.ID IN (
SELECT object_id
FROM `{$wpdb->term_relationships}` AS r
JOIN `{$wpdb->term_taxonomy}` AS x ON x.term_taxonomy_id = r.term_taxonomy_id
WHERE x.taxonomy = %s";

$tax_query_args[] = [
'taxonomy' => $taxonomy,
'terms' => $terms['term_id_include'],
'include_children' => false,
];
}

if ( ! empty($terms['term_id_exclude']) ) {
$terms['term_id_exclude'] = array_unique($terms['term_id_exclude']);

$tax_query_args[] = [
'taxonomy' => $taxonomy,
'terms' => $terms['term_id_exclude'],
'operator' => 'NOT IN',
'include_children' => false,
];
}
}
array_push($args, $taxonomy);

if ( $tax_query_args ) {
$tax_query_args = apply_filters('wpp_tax_query_args', $tax_query_args, $this->options);
$inTID = '';

if ( is_array($tax_query_args) && ! empty($tax_query_args) ) {
$tax_query = new \WP_Tax_Query($tax_query_args);
foreach ($terms['term_id_include'] as $term_ID) {
$inTID .= '%d, ';
array_push($args, $term_ID);
}

$tax_query_clauses = $tax_query->get_sql($wpdb->posts, 'ID');
$tax_query_join = $tax_query_clauses['join'];
$tax_query_where = $tax_query_clauses['where'];
$where .= ' AND x.term_id IN(' . rtrim($inTID, ', ') . ') )';
}

$where .= " AND p.ID IN (SELECT {$wpdb->posts}.ID FROM {$wpdb->posts} {$tax_query_join} WHERE 1 = 1 {$tax_query_where}) ";
if ( ! empty($terms['term_id_exclude']) ) {
$post_ids = get_posts(
[
'post_type' => $post_types,
'posts_per_page' => -1,
'tax_query' => [
[
'taxonomy' => $taxonomy,
'field' => 'id',
'terms' => $terms['term_id_exclude'],
],
],
'fields' => 'ids'
]
);

if ( is_array($post_ids) && ! empty($post_ids) ) {
if ( isset($this->options['pid']) && ! empty($this->options['pid']) ) {
$pid_arr = explode(',', $this->options['pid']);
$pid_arr = array_merge($pid_arr, $post_ids);

// Remove duplicates
$pid_arr_no_dupes = [];
foreach( $pid_arr as $key => $post_id ) {
$pid_arr_no_dupes[$post_id] = true;
}
$pid_arr_no_dupes = array_keys($pid_arr_no_dupes);

$this->options['pid'] = implode(',', $pid_arr_no_dupes);
} else {
$this->options['pid'] = implode(',', $post_ids);
}
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions wordpress-popular-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Plugin Name: WordPress Popular Posts
* Plugin URI: https://wordpress.org/plugins/wordpress-popular-posts/
* Description: A highly customizable widget that displays the most popular posts on your blog.
* Version: 6.4.1
* Version: 6.4.2
* Requires at least: 5.3
* Requires PHP: 7.2
* Author: Hector Cabrera
Expand All @@ -31,7 +31,7 @@
die();
}

define('WPP_VERSION', '6.4.1');
define('WPP_VERSION', '6.4.2');

$wpp_main_plugin_file = __FILE__;
// Load plugin bootstrap
Expand Down

0 comments on commit d1fc9cb

Please sign in to comment.