Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#33862 closed defect (bug) (fixed)

Improve docblock for add_filter

Reported by: bobbingwide Owned by: DrewAPicture
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.4
Component: Plugins Keywords:
Focuses: docs Cc:


These two sentences in the documentation for apply_filters() is badly worded and/or incorrect.

Since WordPress 1.5.1, bound callbacks can take as many arguments as are passed as parameters in the corresponding apply_filters() call. 

The $accepted_args parameter allows for calling functions only when the number of args match.

I believe that what it's trying to say is that apply_filters will limit the number of parameters that it passes to a callback to the value specified in $accepted_args.

Therefore I believe there should be a warning in the documentation saying that, if the $accepted_args parameter is lower than the number actually being passed then things might not work properly.

Either that or we just remove the sentence.

Change History (2)

#1 @DrewAPicture
5 years ago

  • Milestone changed from Awaiting Review to 4.4

I agree that read in the wrong context, the second sentence is misleading. Realistically, supplying the incorrect value for $accepted_args already throws an error describing the problem (the number of arguments being wrong).

#2 @DrewAPicture
5 years ago

  • Owner set to DrewAPicture
  • Resolution set to fixed
  • Status changed from new to closed

In 34288:

Docs: Clarify the significance of the $accepted_args parameter value in the documentation for add_filter().

Adds a couple of examples to illustrate callbacks accepting a variable number of arguments.

Fixes #33862.

Note: See TracTickets for help on using tickets.