From e0b18a023c1e11a5cd9f0e81e04df3c87276753f Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 25 Feb 2018 13:17:12 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@42734 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-theme.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/class-wp-theme.php b/src/wp-includes/class-wp-theme.php index 683065cd2f..6583503b9c 100644 --- a/src/wp-includes/class-wp-theme.php +++ b/src/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 ); } }