WordPress.PHP.DevelopmentFunctions.error_log_trigger_error : recommend wp_trigger_error() as alternative
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 50/100
Research direction
Start by locating the sniff that emits WordPress.PHP.DevelopmentFunctions.error_log_trigger_error and the tests covering its current warning message. Update the diagnostic to recommend wp_trigger_error() as the alternative, then run the relevant sniff tests and confirm the new wording is reported for the supplied trigger_error() example.
Written by the indexing model from the issue text.
Description
Wasn't sure if this should be reported as a bug or feature request..?
Bug Description
The current warning message is vague and does not provide helpful recommendation:
trigger_error() found. Debug code should not normally be used in production.
(WordPress.PHP.DevelopmentFunctions.error_log_trigger_error) phpcs
Minimal Code Snippet
trigger_error( 'Cannot add postmeta for negative post ID value.', \E_USER_WARNING );
Error Code
WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
Environment
| Question | Answer |
|---|---|
| PHP version | 8.3.6 |
| PHP_CodeSniffer version | 1.0.0 |
| WordPressCS version | 3.1.0 |
| PHPCSUtils version | 1.0.12 |
| PHPCSExtra version | 1.2.1 |
| WordPressCS install type | Composer global |
| IDE (if relevant) | Visual Studio Code (Version: 1.96.2) |
Full version info of Visual Studio Code
Version: 1.96.2
Commit: fabdb6a30b49f79a7aba0f2ad9df9b399473380f
Date: 2024-12-19T10:22:47.216Z
Electron: 32.2.6
ElectronBuildId: 10629634
Chromium: 128.0.6613.186
Node.js: 20.18.1
V8: 12.8.374.38-electron.0
OS: Darwin arm64 24.1.0
Additional Context (optional)
I really appreciate the warning message about using json_encode():
json_encode() is discouraged. Use wp_json_encode() instead.
(WordPress.WP.AlternativeFunctions.json_encode_json_encode)phpcs
I had no idea wp_trigger_error() even existed until I was reading the documentation for _doing_it_wrong(), yet it's exactly what I've been wanting and resolves the warnings.
Originally, I also had no idea about wp_json_encode() which is why I'm so thankful for the great messaging for that warning.
Tested Against develop Branch?
- I have verified the issue still exists in the
developbranch of WordPressCS.- I'm using the Composer global installation, so I'm not sure how to confirm this.
- Dominant language
- PHP
- Stars
- 2.8k
- Forks
- 521
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
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.
More from WordPress/WordPress-Coding-Standards
-
Component: Core Focus: DB Type: Bug
Difficulty 2/5 Half a day Newbie friendliness 68/100
WordPress/WordPress-Coding-Standards#2720 · 1 comment ·
-
Component: Extra Type: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
WordPress/WordPress-Coding-Standards#2516 · 3 comments ·
-
WordPress.Security.EscapeOutput: Wiki misses hint about lower case entry for customEscapingFunctions Open
Difficulty 1/5 Under an hour Newbie friendliness 62/100
WordPress/WordPress-Coding-Standards#2508 · 3 comments ·
-
Status: Good first issue Status: Help wanted Type: Documentation
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
WordPress/WordPress-Coding-Standards#1722 · 15 comments ·
-
Component: Helpers Priority: Low Type: Bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
All issues in WordPress/WordPress-Coding-Standards
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
getgrav/grav-plugin-api#45 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
RSS-Bridge/rss-bridge#5098 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
phingofficial/phing#2025 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
silverstripe/developer-docs#911 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100