Automattic / Automattic/babble

Wrap `trigger_error` calls in checks for `WP_DEBUG`

Open
#245 0 comments 0 reactions 0 assignees View on GitHub
task
Dominant language
PHP
Stars
250
Forks
44
PR merge metrics
No merged PRs in 30d

Description

Wherever we have `trigger_error` calls
1. We should ensure the error message is not translated
2. We should swap them to `new Exception` instead of `trigger_error`
3. We should wrap them in a conditional check which ensures they only get called if `WP_DEBUG` is defined and true

So this:

``` php
trigger_error( sprintf( __( 'Warning: The translated name for the post type %s is longer than %d characters. This *will* cause problems.', 'babble' ),
esc_html( $post_type ),
20
) );
```

But this:

``` php
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
throw new exception( sprintf( 'Warning: The translated name for the post type %s is longer than 20 characters. This *will* cause problems.' ), esc_html( $post_type ) );
}
```

Contributor guide

Open the contributing guide

Research direction

Search the repository for every trigger_error call and inspect each surrounding code path. Verify the requested changes against the examples: preserve the message without translation, use an exception, and guard the call with WP_DEBUG. Done means all applicable trigger_error calls follow the requested pattern.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.