Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#57097 closed defect (bug) (fixed)

`_add_template_loader_filters` uses `add_filter` instead of `add_action`

Reported by: swissspidy Owned by: davidbaumwald
Priority: low Milestone: 6.2
Component: Themes Version:
Severity: normal Keywords: good-first-bug has-patch commit
Cc: Focuses:

Description

_add_template_loader_filters uses add_filter to hook into pre_get_posts, which is an action hook and not a filter. Therefore, add_action should be used.

Technically, both are identical under the hood, but especially for people new to the code base this could cause confusion.

https://github.com/WordPress/wordpress-develop/blob/f404ff34c0ce1b9fab35635f6b92f299a1442c7f/src/wp-includes/block-template.php#L14-L32

Attachments (1)

57097.diff (493 bytes ) - added by riccardodicurti 4 years ago.

Download all attachments as: .zip

Change History (5)

#1 @davidbaumwald
4 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone Future Release6.2
  • Owner set to davidbaumwald
  • Status newassigned

#2 @swissspidy
4 years ago

  • Keywords commit added

This ticket was mentioned in Slack in #core by costdev. View the logs.


3 years ago

#4 @davidbaumwald
3 years ago

  • Resolutionfixed
  • Status assignedclosed

In 55335:

Themes: Use add_action for pre_get_posts hook in _add_template_loader_filters().

Although add_action and add_filter are internally the same, pre_get_posts is an action hook. This change updates the hook type to match what developers would expect when evaluating the code.

Follow-up to [52316].

Props swissspidy, riccardodicurti.
Fixes #57097.

Note: See TracTickets for help on using tickets.