#34565 closed defect (bug) (fixed)
Warning after change theme
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.1 | Priority: | normal |
Severity: | normal | Version: | 3.4 |
Component: | Themes | Keywords: | has-patch 2nd-opinion |
Focuses: | Cc: |
Description
Warning:
uasort(): Array was modified by the user comparison function
wp-includes/class-wp-theme.php:1270
Info:
WordPress version 4.3.1
PHP Version: 5.5.9
Attachments (2)
Change History (13)
#3
@
9 years ago
Just like to point out that when the locale is not 'en_' with 83 themes, WP_Theme::_name_sort_i18n is called 890 times. Time 0.047 secs.
It would be more efficient to pre-translate the Name field before calling uasort()
foreach ( $themes as $key => $theme ) { $theme->display( "Name", false, true ); }
and replace the business logic in _name_sort_i18n() with
return strnatcasecmp( $a->name_translated, $b->name_translated );
The sort function is still called the same number of times, but it is slightly quicker.
BTW. I was unable to get the Warning message without resorting to using print_r() in the sort function.
Would like to know more details how to produce the message. Using PHP 5.5.18
#4
@
9 years ago
I was able to reproduce the problem by switching to a theme that produced deprecated messages.
Notice: The called constructor method for WP_Widget is deprecated since version 4.3.0! Use __construct() instead. in C:\apache\htdocs\wordpress\wp-includes\functions.php on line 3457
Another way to achieve it was to implement hooks to the filters invoked during the display(): 'load_textdomain', 'gettext' and use the functions in these hooks. In my case I simply traced the hook invocation.
The alternative solution, pre-translate, avoids these problems.
#6
@
9 years ago
@sebastian.pisula can you furnish more details of how you get the error. Have you tried applying the 34565.2.patch ?
#7
@
9 years ago
Details from Query Monitor:
Warning: uasort(): Array was modified by the user comparison function
Location: wp-includes/class-wp-theme.php:1322
Call Stack:
uasort()
WP_Theme::sort_by_name()
wp_prepare_themes_for_js()
WordPress version: 4.5-alpha-36504
Url: http://localhost/wordpress/wp-admin/themes.php
PHP Version 5.5.9
Windows 10 (Windows NT SPISULA 6.2 build 9200 (Windows 8 Home Premium Edition) i586)
Active theme: Divi Child (Child of Divi)
As mentioned in the SO thread, neither
_name_sort()
nor_name_sort_i18n()
modify the input array, but they still apparently trigger this warning due to PHP bug 50688. However, either of these methods appear to usevar_dump()
,print_r()
,debug_backtrace()
,error_log()
, or exceptions, although there might be one buried in there somewhere.Error suppression is nasty but it might be the easiest solution.