[wp-trac] [WordPress Trac] #34290: Not possible to have a percent symbol contained in the default value of a theme_mod
WordPress Trac
noreply at wordpress.org
Mon Apr 23 09:27:37 UTC 2018
#34290: Not possible to have a percent symbol contained in the default value of a
theme_mod
--------------------------+-----------------------------------------
Reporter: kuus | Owner: (none)
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: Awaiting Review
Component: Customize | Version: 4.4
Severity: normal | Resolution:
Keywords: needs-patch | Focuses: javascript, administration
--------------------------+-----------------------------------------
Comment (by aristath):
Most people that have issues with this is because we're working with CSS
values and need to be able to use `%`.
Right now this is what the `get_theme_mod` function uses:
{{{
if ( is_string( $default ) ) {
$default = sprintf( $default,
get_template_directory_uri(), get_stylesheet_directory_uri() );
}
}}}
The `sprintf` there is useful... I've used it to set default values for
image theme-mods where I need the default value to be an image contained
in the theme and I'm too bored to type `get_template_directory_url`. I'm
not saying it's right... It's just fast and it works.
Why don't we simply change it to this:
{{{
if ( is_string( $default ) && false !== strpos( $default, '%s' ) )
{
$default = sprintf( $default,
get_template_directory_uri(), get_stylesheet_directory_uri() );
}
}}}
f we don't want to strip `%` symbols then checking for `%s` before
`sprintf` looks like a reasonable and safe solution. This way `sprintf`
will only run if we've got a syntax where it actually makes sense to use
`sprintf`. Otherwise this is a really annoying bug...
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34290#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list