Version Description
If you're using a caching plugin, flushing its cache right after installing / upgrading to this version is required.
- Fixes fatal PHP error triggered on some server setups.
- Makes sure non-ajaxified themed widgets are properly moved into the ShadowRoot.
- Fixes declaration of the wpp_params variable.
Release notes
Download this release
Release Info
Developer | hcabrera |
Plugin | WordPress Popular Posts |
Version | 5.2.1 |
Comparing to | |
See all releases |
Code changes from version 5.2.0 to 5.2.1
- assets/js/wpp-5.2.0.min.js +0 -6
- assets/js/wpp-5.2.1.min.js +1 -0
- assets/js/wpp.js +9 -0
- i18n/wordpress-popular-posts.pot +1 -1
- readme.txt +11 -1
- src/Front/Front.php +25 -32
- wordpress-popular-posts.php +2 -2
assets/js/wpp-5.2.0.min.js
DELETED
@@ -1,6 +0,0 @@
|
|
1 |
-
var WordPressPopularPosts=function(){var g=function(){},f=!!HTMLElement.prototype.attachShadow,d=function(b,c,a,d){var e=new XMLHttpRequest;b=-1!=["GET","POST"].indexOf(b)?b:"GET";e.open(b,c+("GET"==b?"?"+a:""),!0);"POST"==b&&e.setRequestHeader("Content-type","application/x-www-form-urlencoded");e.setRequestHeader("X-Requested-With","XMLHttpRequest");e.onreadystatechange=function(){4===e.readyState&&200<=e.status&&300>e.status&&"function"===typeof d&&d.call(void 0,e.response)};e.send("POST"==b?a:
|
2 |
-
null)};return{get:function(b,c,a){a="function"===typeof a?a:g;d("GET",b,c,a)},post:function(b,c,a){a="function"===typeof a?a:g;d("POST",b,c,a)},ajax:d,theme:function(b){if(f){var c=document.createElement("style"),a=document.createElement("ul");a.innerHTML='<li><a href="#"></a></li>';b.parentNode.appendChild(a);var d=getComputedStyle(a.querySelector("li")),e=getComputedStyle(a.querySelector("li a"));c.innerHTML=".wpp-list li {font-size: "+d.fontSize+"}";c.innerHTML+=".wpp-list li a {color: "+e.color+
|
3 |
-
"}";b.parentNode.removeChild(a);a=b.attachShadow({mode:"open"});for(a.append(c);b.firstElementChild;)a.append(b.firstElementChild)}}}}();
|
4 |
-
(function(){try{var g=document.querySelector("script#wpp-json"),f=!0;wpp_params=JSON.parse(g.textContent);wpp_params.ID&&("1"==wpp_params.sampling_active&&(f=1===Math.floor(Math.random()*wpp_params.sampling_rate)+1),f&&WordPressPopularPosts.post(wpp_params.ajax_url,"_wpnonce="+wpp_params.token+"&wpp_id="+wpp_params.ID+"&sampling="+wpp_params.sampling_active+"&sampling_rate="+wpp_params.sampling_rate,function(d){wpp_params.debug&&window.console&&window.console.log&&window.console.log(JSON.parse(d))}))}catch(d){console.error("WPP: Couldn't read JSON data")}})();
|
5 |
-
document.addEventListener("DOMContentLoaded",function(){function g(b){WordPressPopularPosts.get(wpp_params.ajax_url+"/widget/"+b.getAttribute("data-widget-id").split("-")[1],"is_single="+wpp_params.ID+(wpp_params.lang?"&lang="+wpp_params.lang:""),function(c){b.insertAdjacentHTML("afterend",JSON.parse(c).widget);c=b.parentNode;var a=c.querySelector(".popular-posts-sr");c.removeChild(b);a&&WordPressPopularPosts.theme(a);a=null;"function"===typeof Event?a=new Event("wpp-onload",{bubbles:!0,cancelable:!1}):
|
6 |
-
document.createEvent&&(a=document.createEvent("Event"),a.initEvent("wpp-onload",!0,!1));a&&c.dispatchEvent(a)})}var f=document.querySelectorAll(".wpp-widget-placeholder");if(f.length)for(var d=0;d<f.length;d++)g(f[d])});
|
|
|
|
|
|
|
|
|
|
|
|
assets/js/wpp-5.2.1.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
var wpp_params=null,WordPressPopularPosts=function(){"use strict";var a=function(){},b=!!HTMLElement.prototype.attachShadow,c=function(a,b,c,d){var e=new XMLHttpRequest,f=c;a=-1==["GET","POST"].indexOf(a)?"GET":a,e.open(a,b+("GET"==a?"?"+f:""),!0),"POST"==a&&e.setRequestHeader("Content-type","application/x-www-form-urlencoded"),e.setRequestHeader("X-Requested-With","XMLHttpRequest"),e.onreadystatechange=function(){4===e.readyState&&200<=e.status&&300>e.status&&"function"==typeof d&&d.call(void 0,e.response)},e.send("POST"==a?f:null)};return{get:function(b,d,e){e="function"==typeof e?e:a,c("GET",b,d,e)},post:function(b,d,e){e="function"==typeof e?e:a,c("POST",b,d,e)},ajax:c,theme:function(a){if(b){let b=document.createElement("style"),c=document.createElement("ul");c.innerHTML="<li><a href=\"#\"></a></li>",a.parentNode.appendChild(c);let d=getComputedStyle(c.querySelector("li")),e=getComputedStyle(c.querySelector("li a"));b.innerHTML=".wpp-list li {font-size: "+d.fontSize+"}",b.innerHTML+=".wpp-list li a {color: "+e.color+"}",a.parentNode.removeChild(c);let f=a.attachShadow({mode:"open"});for(f.append(b);a.firstElementChild;)f.append(a.firstElementChild)}}}}();(function(){try{var a=document.querySelector("script#wpp-json"),b=!0;if(wpp_params=JSON.parse(a.textContent),wpp_params.ID){if("1"==wpp_params.sampling_active){var c=Math.floor(Math.random()*wpp_params.sampling_rate)+1;b=1===c}b&&WordPressPopularPosts.post(wpp_params.ajax_url,"_wpnonce="+wpp_params.token+"&wpp_id="+wpp_params.ID+"&sampling="+wpp_params.sampling_active+"&sampling_rate="+wpp_params.sampling_rate,function(a){wpp_params.debug&&window.console&&window.console.log&&window.console.log(JSON.parse(a))})}}catch(a){console.error("WPP: Couldn't read JSON data")}})(),document.addEventListener("DOMContentLoaded",function(){function a(a){WordPressPopularPosts.get(wpp_params.ajax_url+"/widget/"+a.getAttribute("data-widget-id").split("-")[1],"is_single="+wpp_params.ID+(wpp_params.lang?"&lang="+wpp_params.lang:""),function(b){a.insertAdjacentHTML("afterend",JSON.parse(b).widget);let c=a.parentNode,d=c.querySelector(".popular-posts-sr");c.removeChild(a),d&&WordPressPopularPosts.theme(d);let e=null;"function"==typeof Event?e=new Event("wpp-onload",{bubbles:!0,cancelable:!1}):document.createEvent&&(e=document.createEvent("Event"),e.initEvent("wpp-onload",!0,!1)),e&&c.dispatchEvent(e)})}var b=document.querySelectorAll(".wpp-widget-placeholder");if(b.length)for(var c=0;c<b.length;c++)a(b[c]);else{var d=document.querySelectorAll(".popular-posts-sr");if(d.length)for(var e=0;e<d.length;e++)WordPressPopularPosts.theme(d[e])}});
|
assets/js/wpp.js
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
var WordPressPopularPosts = (function(){
|
2 |
|
3 |
"use strict";
|
@@ -111,6 +112,14 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
111 |
for( var w = 0; w < widget_placeholders.length; w++ ) {
|
112 |
fetchWidget(widget_placeholders[w]);
|
113 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
}
|
115 |
|
116 |
function fetchWidget(widget_placeholder) {
|
1 |
+
var wpp_params = null;
|
2 |
var WordPressPopularPosts = (function(){
|
3 |
|
4 |
"use strict";
|
112 |
for( var w = 0; w < widget_placeholders.length; w++ ) {
|
113 |
fetchWidget(widget_placeholders[w]);
|
114 |
}
|
115 |
+
} else {
|
116 |
+
var sr = document.querySelectorAll('.popular-posts-sr');
|
117 |
+
|
118 |
+
if ( sr.length ) {
|
119 |
+
for( var s = 0; s < sr.length; s++ ) {
|
120 |
+
WordPressPopularPosts.theme(sr[s]);
|
121 |
+
}
|
122 |
+
}
|
123 |
}
|
124 |
|
125 |
function fetchWidget(widget_placeholder) {
|
i18n/wordpress-popular-posts.pot
CHANGED
@@ -5,7 +5,7 @@ msgid ""
|
|
5 |
msgstr ""
|
6 |
"Project-Id-Version: WordPress Popular Posts\n"
|
7 |
"Report-Msgid-Bugs-To: http://wordpress.org/tag/wordpress-popular-posts\n"
|
8 |
-
"POT-Creation-Date: 2020-07-
|
9 |
"PO-Revision-Date: 2015-04-24 13:30-0430\n"
|
10 |
"Last-Translator: Héctor Cabrera <hcabrerab@gmail.com>\n"
|
11 |
"Language-Team: Héctor Cabrera <me@cabrerahector.com>\n"
|
5 |
msgstr ""
|
6 |
"Project-Id-Version: WordPress Popular Posts\n"
|
7 |
"Report-Msgid-Bugs-To: http://wordpress.org/tag/wordpress-popular-posts\n"
|
8 |
+
"POT-Creation-Date: 2020-07-12 14:41-0400\n"
|
9 |
"PO-Revision-Date: 2015-04-24 13:30-0430\n"
|
10 |
"Last-Translator: Héctor Cabrera <hcabrerab@gmail.com>\n"
|
11 |
"Language-Team: Héctor Cabrera <me@cabrerahector.com>\n"
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Tags: popular, posts, widget, popularity, top
|
|
5 |
Requires at least: 4.7
|
6 |
Tested up to: 5.4.2
|
7 |
Requires PHP: 5.4
|
8 |
-
Stable tag: 5.2.
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
@@ -89,6 +89,16 @@ The FAQ section has been moved [here](https://github.com/cabrerahector/wordpress
|
|
89 |
4. Statistics panel.
|
90 |
|
91 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
= 5.2.0 =
|
93 |
|
94 |
**If you're using a caching plugin, flushing its cache right after installing / upgrading to this version is required.**
|
5 |
Requires at least: 4.7
|
6 |
Tested up to: 5.4.2
|
7 |
Requires PHP: 5.4
|
8 |
+
Stable tag: 5.2.1
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
89 |
4. Statistics panel.
|
90 |
|
91 |
== Changelog ==
|
92 |
+
= 5.2.1 =
|
93 |
+
|
94 |
+
**If you're using a caching plugin, flushing its cache right after installing / upgrading to this version is required.**
|
95 |
+
|
96 |
+
- Fixes fatal PHP error triggered on some server setups.
|
97 |
+
- Makes sure non-ajaxified themed widgets are properly moved into the ShadowRoot.
|
98 |
+
- Fixes declaration of the wpp_params variable.
|
99 |
+
|
100 |
+
[Release notes](https://cabrerahector.com/wordpress/wordpress-popular-posts-5-2-is-here)
|
101 |
+
|
102 |
= 5.2.0 =
|
103 |
|
104 |
**If you're using a caching plugin, flushing its cache right after installing / upgrading to this version is required.**
|
src/Front/Front.php
CHANGED
@@ -89,28 +89,7 @@ class Front {
|
|
89 |
}
|
90 |
|
91 |
// Enqueue WPP's library.
|
92 |
-
|
93 |
-
|
94 |
-
if (
|
95 |
-
( 0 == $this->config['tools']['log']['level'] && !is_user_logged_in() )
|
96 |
-
|| ( 1 == $this->config['tools']['log']['level'] )
|
97 |
-
|| ( 2 == $this->config['tools']['log']['level'] && is_user_logged_in() )
|
98 |
-
) {
|
99 |
-
$is_single = Helper::is_single();
|
100 |
-
}
|
101 |
-
|
102 |
-
wp_register_script('wpp-js', plugin_dir_url(dirname(dirname(__FILE__))) . 'assets/js/wpp-5.2.0.min.js', [], WPP_VERSION, false);
|
103 |
-
$params = [
|
104 |
-
'sampling_active' => (int) $this->config['tools']['sampling']['active'],
|
105 |
-
'sampling_rate' => $this->config['tools']['sampling']['rate'],
|
106 |
-
'ajax_url' => esc_url_raw(rest_url('wordpress-popular-posts/v1/popular-posts')),
|
107 |
-
'ID' => $is_single,
|
108 |
-
'token' => wp_create_nonce('wp_rest'),
|
109 |
-
'lang' => function_exists('PLL') ? $this->translate->get_current_language() : null,
|
110 |
-
'debug' => WP_DEBUG
|
111 |
-
];
|
112 |
-
wp_enqueue_script('wpp-js');
|
113 |
-
wp_add_inline_script('wpp-js', json_encode($params), 'before');
|
114 |
}
|
115 |
|
116 |
/**
|
@@ -130,17 +109,31 @@ class Front {
|
|
130 |
function convert_inline_js_into_json($tag, $handle, $src)
|
131 |
{
|
132 |
if ( 'wpp-js' === $handle ) {
|
133 |
-
$
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
|
|
|
|
|
|
142 |
|
143 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
}
|
145 |
|
146 |
return $tag;
|
89 |
}
|
90 |
|
91 |
// Enqueue WPP's library.
|
92 |
+
wp_enqueue_script('wpp-js', plugin_dir_url(dirname(dirname(__FILE__))) . 'assets/js/wpp-5.2.1.min.js', [], WPP_VERSION, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
}
|
94 |
|
95 |
/**
|
109 |
function convert_inline_js_into_json($tag, $handle, $src)
|
110 |
{
|
111 |
if ( 'wpp-js' === $handle ) {
|
112 |
+
$is_single = 0;
|
113 |
+
$lang = ( function_exists('PLL') )
|
114 |
+
? $this->translate->get_current_language()
|
115 |
+
: null;
|
116 |
+
|
117 |
+
if (
|
118 |
+
( 0 == $this->config['tools']['log']['level'] && ! is_user_logged_in() )
|
119 |
+
|| ( 1 == $this->config['tools']['log']['level'] )
|
120 |
+
|| ( 2 == $this->config['tools']['log']['level'] && is_user_logged_in() )
|
121 |
+
) {
|
122 |
+
$is_single = Helper::is_single();
|
123 |
+
}
|
124 |
|
125 |
+
$params = [
|
126 |
+
'sampling_active' => (int) $this->config['tools']['sampling']['active'],
|
127 |
+
'sampling_rate' => $this->config['tools']['sampling']['rate'],
|
128 |
+
'ajax_url' => esc_url_raw(rest_url('wordpress-popular-posts/v1/popular-posts')),
|
129 |
+
'ID' => $is_single,
|
130 |
+
'token' => wp_create_nonce('wp_rest'),
|
131 |
+
'lang' => $lang,
|
132 |
+
'debug' => WP_DEBUG
|
133 |
+
];
|
134 |
+
$json_script = '<script type="application/json" id="wpp-json">' . json_encode($params) . '</script>';
|
135 |
+
|
136 |
+
$tag = $json_script . "\n" . $tag;
|
137 |
}
|
138 |
|
139 |
return $tag;
|
wordpress-popular-posts.php
CHANGED
@@ -16,7 +16,7 @@
|
|
16 |
* Plugin Name: WordPress Popular Posts
|
17 |
* Plugin URI: https://wordpress.org/plugins/wordpress-popular-posts/
|
18 |
* Description: A highly customizable widget that displays the most popular posts on your blog.
|
19 |
-
* Version: 5.2.
|
20 |
* Author: Hector Cabrera
|
21 |
* Author URI: https://cabrerahector.com/
|
22 |
* License: GPL-2.0+
|
@@ -29,7 +29,7 @@ if ( ! defined( 'WPINC' ) ) {
|
|
29 |
die();
|
30 |
}
|
31 |
|
32 |
-
define('WPP_VERSION', '5.2.
|
33 |
define('WPP_MIN_PHP_VERSION', '5.4');
|
34 |
define('WPP_MIN_WP_VERSION', '4.9');
|
35 |
|
16 |
* Plugin Name: WordPress Popular Posts
|
17 |
* Plugin URI: https://wordpress.org/plugins/wordpress-popular-posts/
|
18 |
* Description: A highly customizable widget that displays the most popular posts on your blog.
|
19 |
+
* Version: 5.2.1
|
20 |
* Author: Hector Cabrera
|
21 |
* Author URI: https://cabrerahector.com/
|
22 |
* License: GPL-2.0+
|
29 |
die();
|
30 |
}
|
31 |
|
32 |
+
define('WPP_VERSION', '5.2.1');
|
33 |
define('WPP_MIN_PHP_VERSION', '5.4');
|
34 |
define('WPP_MIN_WP_VERSION', '4.9');
|
35 |
|