From b6229650e0d95909388e1159ec2e85e68b9e9240 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 25 Feb 2018 13:18:30 +0000 Subject: [PATCH] Themes: Pre-translate theme names on Themes screen before sorting the array, to improve performance and avoid a warning in PHP 5.x. Props bobbingwide, sebastian.pisula. Fixes #34565. Built from https://develop.svn.wordpress.org/trunk@42734 git-svn-id: http://core.svn.wordpress.org/trunk@42564 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-theme.php | 8 +++++--- wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php index 683065cd2f..6583503b9c 100644 --- a/wp-includes/class-wp-theme.php +++ b/wp-includes/class-wp-theme.php @@ -1559,6 +1559,9 @@ final class WP_Theme implements ArrayAccess { if ( 0 === strpos( get_user_locale(), 'en_' ) ) { uasort( $themes, array( 'WP_Theme', '_name_sort' ) ); } else { + foreach ( $themes as $key => $theme ) { + $theme->translate_header( 'Name', $theme->headers['Name'] ); + } uasort( $themes, array( 'WP_Theme', '_name_sort_i18n' ) ); } } @@ -1583,7 +1586,7 @@ final class WP_Theme implements ArrayAccess { } /** - * Name sort (with translation). + * Callback function for usort() to naturally sort themes by translated name. * * @since 3.4.0 * @@ -1595,7 +1598,6 @@ final class WP_Theme implements ArrayAccess { * Greater than 0 if `$a` falls higher in the natural order than `$b`. Used with usort(). */ private static function _name_sort_i18n( $a, $b ) { - // Don't mark up; Do translate. - return strnatcasecmp( $a->display( 'Name', false, true ), $b->display( 'Name', false, true ) ); + return strnatcasecmp( $a->name_translated, $b->name_translated ); } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 218973acdf..9f07504114 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '5.0-alpha-42733'; +$wp_version = '5.0-alpha-42734'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.