Wordpress Ninja - The Missing "Sorting Plugins By Popularity"

Posted at

When You Look For New Plugins (or themes, or, whatever from wordpress.org) you'll get a list that is not organised by amount of installs

[before - original state]


Here is a little JavaScript-Ninja technique,
that you can run on your self-hosted wordpress website after searching for a new plugins,
to reorder the list..


(function(placeholder, items){
"use strict";

items = Array.prototype.map.call(items, function(e){ return e; }); /* to array */

items = items .sort(function(a,b){
a = a.innerText.match(/([\\d\\,\\+]+)\\s+active installs/i)[1].replace(/[\\,\\+]/g,"");
b = b.innerText.match(/([\\d\\,\\+]+)\\s+active installs/i)[1].replace(/[\\,\\+]/g,"");
return a - b;
})
.reverse()
.map(function(e){ return e.cloneNode(true); })
;

placeholder.innerHTML = "";
items.forEach(function(item){ placeholder.appendChild(item) });
}(
document.querySelector('#the-list')
, document.querySelectorAll('#the-list > div.plugin-card')
));


[after - after running the JavaScript code and the list is rewritten by most installed- to least installed]


Fun, isn't? :]