Opened 14 years ago
Closed 14 years ago
#17911 closed defect (bug) (invalid)
WP_Dependencies::remove() may generate PHP Warning
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | 3.1.3 |
Component: | Warnings/Notices | Keywords: | close |
Focuses: | Cc: |
Description
The following code will always generate a PHP Warning: Illegal offset type in unset, on line 159 of /wp-includes/class.wp-dependencies.php
global $wp_styles; foreach ($wp_styles->registered AS $handle) $wp_styles->remove($handle);
... and here is a simple fix :
if (@isset($this->registered[$handle])) { unset($this->registered[$handle]); }
Change History (5)
#3
@
14 years ago
WP_Dependencies::remove() expects a single $handle
(the name a script or stylesheet was registered with) or an array of handles if you want to remove more than one at the same time. WP_Dependencies::enqueue() and WP_Dependencies::dequeue() work in the same way.
Not sure where the above example code comes from but it seems it needs to be:
foreach ( $wp_styles->registered AS $handle => $object ) $wp_styles->remove($handle);
Note: See
TracTickets for help on using
tickets.
PHP is throwing the warning because
$handle
being passed is the whole WP_Dependency object for the style, rather than it's actual slug, which is incorrect usage. A workaround would be to check is_string() for$handle
.