WordPress / WordPress/WordPress-Coding-Standards
Handbook: Add sniff(s) for "Interpolation for Naming Dynamic Hooks" section
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.8k
- Forks
- 521
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
Description
Dynamic hooks should be named using interpolation rather than concatenation for readability and discoverability purposes.
Dynamic hooks are hooks that include dynamic values in their tag name, e.g.
{$new_status}_{$post->post_type}(publish_post).Variables used in hook tags should be wrapped in curly braces
{and}, with the complete outer tag name wrapped in double quotes. This is to ensure PHP can correctly parse the given variables’ types within the interpolated string.do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );Where possible, dynamic values in tag names should also be as succinct and to the point as possible.
$user_idis much more self-documenting than, say,$this->id.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the linked WordPress PHP coding-standards section first, then locate the repository's PHP_CodeSniffer sniff and test conventions. Done means the ruleset detects dynamic hook names that use concatenation instead of the specified interpolation style, with coverage for the examples described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100