diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 956e8290e2..50b43a5175 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -4883,7 +4883,11 @@ function sanitize_option( $option, $value ) { break; case 'blog_charset': - $value = preg_replace( '/[^a-zA-Z0-9_-]/', '', $value ); // Strips slashes. + if ( is_string( $value ) ) { + $value = preg_replace( '/[^a-zA-Z0-9_-]/', '', $value ); // Strips slashes. + } else { + $value = ''; + } break; case 'blog_public': @@ -4918,7 +4922,11 @@ function sanitize_option( $option, $value ) { break; case 'gmt_offset': - $value = preg_replace( '/[^0-9:.-]/', '', $value ); // Strips slashes. + if ( is_numeric( $value ) ) { + $value = preg_replace( '/[^0-9:.-]/', '', $value ); // Strips slashes. + } else { + $value = ''; + } break; case 'siteurl': diff --git a/tests/phpunit/tests/option/sanitizeOption.php b/tests/phpunit/tests/option/sanitizeOption.php index e50cec0c62..38fdda1a21 100644 --- a/tests/phpunit/tests/option/sanitizeOption.php +++ b/tests/phpunit/tests/option/sanitizeOption.php @@ -36,6 +36,7 @@ class Tests_Option_SanitizeOption extends WP_UnitTestCase { array( 'blogname', '<i>My Site</i>', 'My Site' ), array( 'blog_charset', 'UTF-8', 'UTF-8' ), array( 'blog_charset', 'charset', '">charset<"' ), + array( 'blog_charset', '', null ), array( 'blog_public', 1, null ), array( 'blog_public', 1, '1' ), array( 'blog_public', -2, '-2' ), @@ -45,6 +46,7 @@ class Tests_Option_SanitizeOption extends WP_UnitTestCase { array( 'ping_sites', "http://www.example.com\nhttp://example.org", "www.example.com \n\texample.org\n\n" ), array( 'gmt_offset', '0', 0 ), array( 'gmt_offset', '1.5', '1.5' ), + array( 'gmt_offset', '', null ), array( 'siteurl', 'http://example.org', 'http://example.org' ), array( 'siteurl', 'http://example.org/subdir', 'http://example.org/subdir' ), array( 'siteurl', get_option( 'siteurl' ), '' ),