[wp-trac] [WordPress Trac] #62643: Prevent errors from `printf()` and `sprintf()` calls
WordPress Trac
noreply at wordpress.org
Mon Nov 3 17:17:51 UTC 2025
#62643: Prevent errors from `printf()` and `sprintf()` calls
-------------------------+------------------------------
Reporter: grapestain | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: I18N | Version:
Severity: normal | Resolution:
Keywords: 2nd-opinion | Focuses:
-------------------------+------------------------------
Comment (by barry.hughes):
That's good feedback: I understand what I suggested may not be appealing
to everyone (and perhaps may not be worth the effort).
Looking at some rough numbers (here using WooCommerce as a representative
codebase), when `(s)printf` is followed by a translation function, the
breakdown looks something like this:
- `__()` → 883 cases (66%)
- `esc_html__()` → 307 cases (23%)
- `_n()` → 104 cases (8%)
Applying the same approach to a union of the `wp-includes` and `wp-admin`
directories from WordPress, our top 3 would instead look like:
- `__()` → 1,452 cases (89%)
- `_n()` → 99 cases (7%)
- `_x()` → 86 cases (6%)
So, for either codebase, just implementing complements for `__()`,
`esc_html__()` and `_n()` would be useful in 96% or more cases. Given
that, perhaps the 'gaps' wouldn't matter too much?
> I still think it would be good to change best-practice recommendations
to wrapper functions with suitable try catch blocks wrapping the print
functions
I agree, that would also improve on the situation 👍🏼
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62643#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list