diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index 198bf94478..2fb98bcb9d 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -934,7 +934,10 @@ function get_theme_mod( $name, $default = false ) { } if ( is_string( $default ) ) { - $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); + // Only run the replacement if an sprintf() string format pattern was found. + if ( preg_match( '#(?assertEquals( '', get_theme_mod( 'test_remove' ) ); } + /** + * @ticket 34290 + * + * @dataProvider data_theme_mod_default_value_with_percent_symbols + */ + function test_theme_mod_default_value_with_percent_symbols( $default, $expected ) { + $this->assertEquals( $expected, get_theme_mod( 'test_name', $default ) ); + } + + function data_theme_mod_default_value_with_percent_symbols() { + return array( + array( + '100%', + '100%', + ), + array( + '%s', + get_template_directory_uri(), + ), + array( + '%s%s', + get_template_directory_uri() . get_stylesheet_directory_uri(), + ), + array( + '%1$s%s', + get_template_directory_uri() . get_template_directory_uri(), + ), + array( + '%2$s%s', + get_stylesheet_directory_uri() . get_template_directory_uri(), + ), + array( + '%1$s%2$s', + get_template_directory_uri() . get_stylesheet_directory_uri(), + ), + array( + '%40s%40s', + get_template_directory_uri() . get_stylesheet_directory_uri(), + ), + array( + '%%1', + '%%1', + ), + array( + '%1%', + '%1%', + ), + array( + '1%%', + '1%%', + ), + array( + '%%s', + '%%s', + ), + array( + '%s%', + get_template_directory_uri(), + ), + array( + 's%%', + 's%%', + ), + ); + } + }