Skip to content

WordPress.PHP.DevelopmentFunctions.error_log_trigger_error : recommend wp_trigger_error() as alternative #2515

Open
@MichelleBlanchette

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 develop branch of WordPressCS.
    • I'm using the Composer global installation, so I'm not sure how to confirm this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions