WordPress-Coding-Standards icon indicating copy to clipboard operation
WordPress-Coding-Standards copied to clipboard

Add rule to warn when using deprecated actions/filters

Open petitphp opened this issue 3 years ago • 3 comments

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)

petitphp avatar Jul 20 '22 19:07 petitphp

Related to and partial duplicate of #576.

This would be a great sniff to add. The biggest concern is the initial creation and subsequent maintenance of the "list" of deprecated hooks.

jrfnl avatar Jul 20 '22 20:07 jrfnl

Sorry for missing the existing issue. I didn't realize this would require a static list.

The first step for moving forward with the issue would be to have a tools to scan for deprecated hooks and build a list with the details for each ones ?

petitphp avatar Jul 20 '22 20:07 petitphp

The first step for moving forward with the issue would be to have a tools to scan for deprecated hooks and build a list with the details for each ones ?

This is what we currently use to keep the DeprecatedFunctions sniff up to date: https://github.com/JDGrimes/wp-deprecated-code-scanner

Also see https://github.com/WordPress/WordPress-Coding-Standards/issues/1803

jrfnl avatar Jul 20 '22 20:07 jrfnl