[wp-trac] [WordPress Trac] #49484: Add option 'OR' to wp_sprintf()
WordPress Trac
noreply at wordpress.org
Fri Feb 21 13:56:19 UTC 2020
#49484: Add option 'OR' to wp_sprintf()
-----------------------------+------------------------------
Reporter: pedromendonca | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Formatting | Version:
Severity: normal | Resolution:
Keywords: needs-patch | Focuses:
-----------------------------+------------------------------
Comment (by pedromendonca):
= **Some additional considerations** =
1. Adding a third parameter to `wp_sprintf()` is not possible, because the
current second parameter is `...$args`, which has variable lenght and must
be kept as the last parameter.
2. A single `wp_sprintf()` can have multiple `%l` placeholders, with both
`' and '`/`' or '`, so it doesn't make sense to set it function wide.
= **The solution** =
Currently `wp_sprintf()` supports `%l` placeholder that sets a list `' and
'` type delimited.
It's possible to add support for more placeholders:
- `%l$o` - **$o** stands for **OR** - Outputs `' or '` delimiters
- `%l$a` - **$a** stands for **AND** - Outputs `' and '` delimiters and is
an alias for the default `%l`
The solution should allow all the below placeholder types:
- Normal: `%l$o`, `%l$a`, `%l` (alias for `%l$a`)
- Numbered: `%2$l$o`, `%2$l$a`, `%2$l` (alias for `%2$l$a`)
I've tested this successfully, I'll publishing a patch below for everyone
interested in testing this.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49484#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list