WordPress / WordPress/WordPress-Coding-Standards

Sniff to check for the unused parameters in hooks

Open
#1,882 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Status: Awaiting feedback 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?

A lot of times plugin and theme authors add hook callbacks but fail to provide all the necessary parameters. For instance, in custom widgets (taken from the WPThemeReview issue):

$title = apply_filters( 'widget_title', $title );

and according to the documentation, there should exist two extra parameters:

$title = apply_filters( 'widget_title', $title, $instance, $id_base );

Describe the solution you'd like

A solution would be to have a sniff that checks if any of the core WP hooks, that are invoked in the plugin or theme, have the correct amount of parameters passed as in the hook definition.

We would rely on the utility sniff that would check for all the core hooks, which would be a part of #1803 issue

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

Review issue #1803 and the linked WordPress hook documentation first, since the requested sniff depends on a utility that identifies core hooks. Define how hook invocations and their expected parameters should be compared, then verify that valid and incomplete calls are distinguished by the resulting sniff tests.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.