WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#17911 closed defect (bug) (invalid)

WP_Dependencies::remove() may generate PHP Warning

Reported by: ftrudeau 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)

comment:1 kawauso3 years ago

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.

comment:2 SergeyBiryukov3 years ago

  • Keywords needs-patch added

comment:3 azaozz3 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);

comment:4 azaozz3 years ago

  • Keywords close added; needs-patch removed

comment:5 SergeyBiryukov3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.