close

Make WordPress Core

Opened 5 days ago

Closed 5 days ago

#64828 closed defect (bug) (fixed)

add_filter() used on actions and add_action() used on filters in core

Reported by: apermo's profile apermo Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 7.0 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch
Focuses: Cc:

Description

Three cases in core where hooks are registered with the wrong function:

  • add_filter( 'admin_print_styles', ... ) in wp-admin/includes/admin-filters.php:56 — hook fires via do_action()
  • add_filter( 'login_head', ... ) in wp-includes/default-filters.php:388 — hook fires via do_action()
  • add_action( 'use_block_editor_for_post_type', ... ) in wp-admin/includes/admin-filters.php:88 — hook fires via apply_filters()

A 4th case (get_block_type_variations) originates in Gutenberg: https://github.com/WordPress/gutenberg/issues/76296

Functionally equivalent since add_action() calls add_filter() internally, but semantically incorrect.

Found while working on #64224 (docblock improvements). Related to #64238 (PHPStan catchall).

PR: https://github.com/WordPress/wordpress-develop/pull/11204

Change History (3)

Image

This ticket was mentioned in PR #11204 on WordPress/wordpress-develop by @apermo.


5 days ago
#1

## Summary

Fixes 3 cases where hooks are registered with the wrong function — add_action() used on a filter or add_filter() used on an action. Functionally equivalent (since add_action() calls add_filter() internally), but semantically incorrect.

### add_filter()add_action() (hook is fired via do_action()):

  • admin_print_styles in wp-admin/includes/admin-filters.php
  • login_head in wp-includes/default-filters.php

### add_action()add_filter() (hook is fired via apply_filters()):

  • use_block_editor_for_post_type in wp-admin/includes/admin-filters.php

A 4th mismatch (get_block_type_variations using add_action() on a filter) originates in the Gutenberg repo and is tracked separately: https://github.com/WordPress/gutenberg/issues/76296

For detailed investigation notes, see: https://github.com/apermo/wordpress-develop/milestone/4

## Use of AI Tools

Research (systematic cross-referencing of all add_action/add_filter registrations against their do_action/apply_filters call sites) and code were produced by Claude Code (claude-sonnet-4-6). The contributor reviewed the findings, verified each fix, and approved the final implementation.

#2 Image @SergeyBiryukov
5 days ago

  • Milestone changed from Awaiting Review to 7.0
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#3 Image @SergeyBiryukov
5 days ago

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

In 61866:

Code Quality: Correct hook registration type mismatches.

Though add_action() and add_filter() are functionally equivalent internally, for proper semantics the former should be used on actions and the latter on filters.

Follow-up to [37920], [38046], [53266].

Props apermo.
Fixes #64828.

Note: See TracTickets for help on using tickets.