General: Introduce a wp_list_sort() helper function.

In addition to `wp_list_filter()` for filtering a list of objects, and `wp_list_pluck()` for plucking a certain field out of each object in a list, this new function can be used for sorting a list of objects by specific fields. These functions are now all contained within the new `WP_List_Util()` class and `wp_list_sort()` is used in various parts of core for sorting lists.

Props flixos90, DrewAPicture, jorbin.
Fixes #37128.
Built from https://develop.svn.wordpress.org/trunk@38859


git-svn-id: http://core.svn.wordpress.org/trunk@38802 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler
2016-10-21 11:12:51 +00:00
parent 7d9563801a
commit f54558e75b
11 changed files with 423 additions and 150 deletions

View File

@@ -169,7 +169,9 @@ function get_permalink( $post = 0, $leavename = false ) {
if ( strpos($permalink, '%category%') !== false ) {
$cats = get_the_category($post->ID);
if ( $cats ) {
usort($cats, '_usort_terms_by_ID'); // order by ID
$cats = wp_list_sort( $cats, array(
'term_id' => 'ASC',
) );
/**
* Filters the category that gets used in the %category% permalink token.