WordPress / WordPress/WordPress-Coding-Standards

Add rule to warn when using deprecated actions/filters

Open
#2,071 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Core Type: Enhancement
Dominant language
PHP
Stars
2.8k
Forks
521
Avg merge
5d 20h
Merged PRs (30d)
1

Description

Is your feature request related to a problem?

I notice sometimes when using the PHPStorm autocompletion for WordPress hooks that some hooks I use to used don't show up in the hints. I guess it's because PHPStorm only suggest hooks from apply_filters and do_action functions and not from apply_filters_deprecated and do_action_deprecated.

Even if it would be relatively safe to keep using deprecated hooks (at least for hooks in WordPress core) it would be really useful to be warn when a deprecated usage is detected.

Describe the solution you'd like

Usage of a deprecated action/filter should trigger a CS warning.

add_filter( 'allowed_block_types', 'my_callback_function' ); // deprecated since WordPress 5.8.0

Additional context (optional)

I was thinking of something along the line of the Sniff WordPress.WP.DeprecatedFunctions which provide details about the deprecation and the replacement if available.

wp_setcookie() has been deprecated since WordPress version 2.5.0. Use wp_set_auth_cookie() instead (WordPress.WP.DeprecatedFunctions.wp_setcookieFound)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the WordPress.WP.DeprecatedFunctions sniff and compare its deprecation details and replacement handling with the add_filter example in this issue. The work is done when deprecated actions and filters produce CS warnings with available deprecation information, while ordinary hook usage is not warned about.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.