Opened 10 years ago
Closed 10 years ago
#32573 closed defect (bug) (duplicate)
Change in wp_print_styles() causes fatal error if $wp_styles is not set
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.3 |
Component: | Script Loader | Keywords: | |
Focuses: | Cc: |
Description
In 4.3-alpha there is a change in wp_print_styles() such that the final return statement has become:
return $wp_styles->do_items( $handles );
whereas in 4.2.2 the statement is:
return wp_styles()->do_items( $handles );
The change appears to be due to this ticket:
https://core.trac.wordpress.org/ticket/32444#comment:43
which does not seem to take into account the actual context of this statement. The upshot is that there is now an implicit assumption that the global $wp_styles is already set to an instantiation of the WP_Styles object and when this is not the case the function fails with a fatal error:
[Sat Jun 06 14:19:24.795479 2015] [:error] [pid 7955] [client 127.0.0.1:59179] PHP Fatal error: Call to a member function do_items() on a non-object in /Users/ambiguous/Sites/wptest.dev/wp-includes/functions.wp-styles.php on line 64
It cannot be assumed that the global $wp_styles is already set to an instantiated WP_Styles object and the explicit use of the wp_styles() function was to instantiate a WP_Styles object and assign to the global $wp_styles if that was not already the case.
The wp_print_styles() function has an explicit requirement that the global $wp_styles is a valid instantiation of a WP_Styles object if it is necessary to use the global:
* @global WP_Styles $wp_styles The WP_Styles object for printing styles.
Either the change needs to be reverted to call wp_styles() in the return statement or an update must be made earlier in the function to add an else clause in prior conditional so that $wp_styles global will be valid when required.
Duplicate of #32541.