diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index ff0b6a4fd9..c2f08028c5 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -3706,6 +3706,10 @@ function sanitize_option( $option, $value ) { case 'blogdescription': case 'blogname': $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value ); + if ( $value !== $original_value ) { + $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', wp_encode_emoji( $original_value ) ); + } + if ( is_wp_error( $value ) ) { $error = $value->get_error_message(); } else { diff --git a/tests/phpunit/tests/option/sanitize-option.php b/tests/phpunit/tests/option/sanitize-option.php index 4dd0942344..c4bea4554e 100644 --- a/tests/phpunit/tests/option/sanitize-option.php +++ b/tests/phpunit/tests/option/sanitize-option.php @@ -102,4 +102,21 @@ class Tests_Sanitize_Option extends WP_UnitTestCase { $this->assertSame( $expected, sanitize_option( 'upload_path', $provided ) ); } + /** + * @ticket #36122 + */ + public function test_emoji_in_blogname_and_description() { + global $wpdb; + + $value = "whee\xf0\x9f\x98\x88"; + + if ( 'utf8mb4' === $wpdb->get_col_charset( $wpdb->options, 'option_value' ) ) { + $expected = $value; + } else { + $expected = 'whee😈'; + } + + $this->assertSame( $expected, sanitize_option( 'blogname', $value ) ); + $this->assertSame( $expected, sanitize_option( 'blogdescription', $value ) ); + } }