Make WordPress Core

#57097 closed defect (bug) (fixed)

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

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

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 22 months ago.

Download all attachments as: .zip

Change History (5)

#1 @davidbaumwald
22 months ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Future Release to 6.2
  • Owner set to davidbaumwald
  • Status changed from new to assigned

#2 @swissspidy
21 months ago

  • Keywords commit added

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


19 months ago

#4 @davidbaumwald
19 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

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.