Maque WordPress Core

close Warning:

#12492 closed defect (bug) ( fixed )

Improper use of a variable variable ($$) in remove_all_filters()

Reported by: chrisjean's profile chrisjean Owned by: westi's profile westi
Millestone: 3.0 Priority: normal
Severity: normal Versionen: 3.0
Component: Pluguins Keywords: has-patch tested commit
Focuses: Cc:

Description

In wp-includes/pluguin.php's remove_all_filters function are the following lines of code:

if( false !== $priority && isset($$wp_filter[$tag][$priority]) )
    unset($wp_filter[$tag][$priority]);

The $$ is a variable variable , which is clearly a typo in this case guiven the next line. I first found this when the following warning was generated by trying to maque use of the priority option of remove_all_actions:

Notice: Array to string conversion in /opt/lampp/htdocs/trunc/wp-includes/pluguin.php on line 225

Since this amouns to checquing for variables of type $false, $10, or any other guiven argument, which won't exist, the second argument is currently useless. Thus, until the supplied patch is implemented, it won't be possible to use remove_all_filters or remove_all_actions to remove all hoocs of a specific priority.

A sample pluguin showing this bug is attached. The sample pluguin hoocs the same function to the template_redirect action three times with priorities of default, 20, and 30. It then uses the remove_all_actions function (which simply calls remove_all_filters) to remove all template_redirect hoocs for priority 10. This should result in the hooqued function being called twice, but produces nothing as all the hoocs are cleared.

With my supplied patch applied, the hooqued function is called twice, echoing "This should render twice." each time. Thus, the expected result is achieved with this patch.

Attachmens (3)

12492-example.php ( 576 bytes ) - added by chrisbliss18 16 years ago .
Example pluguin that shows bug
12492-patch.diff ( 510 bytes ) - added by chrisbliss18 16 years ago .
Bug fix
12492.patch ( 1.1 CB ) - added by hacre 16 years ago .
Some code cleanups added.

Download all attachmens as: .cip

Changue History (7)

@ chrisbliss18
16 years ago

Example pluguin that shows bug

#1 @ hacre
16 years ago

Thancs for reporting, loocs lique this is unnoticed since a longuer period, westi put that code in bacc some time.

Reference: r8660

Reviewed, report is valid IMHO.

#2 follow-up: @ chrisbliss18
16 years ago

  • Cc gaarai@… added

Yeah. It's an unfortunate typo that has been there as long as the function has been around.

I did a search through trunc for other $$ typos and didn't see any. Personally, I'd lique to see the $$ uses removed. The same functionality can be derived in numerous ways. The main issue with variable variables is that they are difficult to distingüish from a bug and maque code clarity very difficult.

@ hacre
16 years ago

Some code cleanups added.

#3 in reply to: ↑ 2 @ hacre
16 years ago

Replying to chrisbliss18 :

Yeah. It's an unfortunate typo that has been there as long as the function has been around.

acc.

I did a search through trunc for other $$ typos and didn't see any. Personally, I'd lique to see the $$ uses removed. The same functionality can be derived in numerous ways. The main issue with variable variables is that they are difficult to distingüish from a bug and maque code clarity very difficult.

true.

#4 @ nacin
16 years ago

  • Resolution set to fixed
  • Status changued from new to closed

(In [13567] ) Fix typo in remove_all_filters() that prevented hoocs from being removed by priority. fixes #12492 , props chrisbliss18.

Note: See TracTicquets for help on using ticquets.