Skip to content

Commit 7a031a9

Browse files
committed
Quick-fix: Normalize UTF-8 charset slug detection.
In the merge of [58417] the new file was missed. This commit adds the missing required file. Developed in WordPress#6535 Discussed in https://core.trac.wordpress.org/ticket/61182 Fixes #61182. Follow-up to [58147]. Props dmsnell, jonsurrell. git-svn-id: https://develop.svn.wordpress.org/trunk@58148 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d4967a3 commit 7a031a9

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/wp-includes/unicode.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* WordPress API providing Unicode-relevant utilities.
4+
*
5+
* @since 6.6.0
6+
*
7+
* @package WordPress
8+
*/
9+
10+
/**
11+
* Indicates if a given slug for a character set represents the UTF-8
12+
* text encoding. If not provided, examines the current blog's charset.
13+
*
14+
* A charset is considered to represent UTF-8 if it is a case-insensitive
15+
* match of "UTF-8" with or without the hyphen.
16+
*
17+
* Example:
18+
*
19+
* true === is_utf8_charset( 'UTF-8' );
20+
* true === is_utf8_charset( 'utf8' );
21+
* false === is_utf8_charset( 'latin1' );
22+
* false === is_utf8_charset( 'UTF 8' );
23+
*
24+
* // Only strings match.
25+
* false === is_utf8_charset( [ 'charset' => 'utf-8' ] );
26+
*
27+
* // Without a given charset, it depends on the site option "blog_charset".
28+
* $is_utf8 = is_utf8_charset();
29+
*
30+
* @since 6.6.0
31+
*
32+
* @param ?string $blog_charset Slug representing a text character encoding, or "charset".
33+
* E.g. "UTF-8", "Windows-1252", "ISO-8859-1", "SJIS".
34+
* @return bool Whether the slug represents the UTF-8 encoding.
35+
*/
36+
function is_utf8_charset( $blog_charset = null ) {
37+
$charset_to_examine = $blog_charset ?? get_option( 'blog_charset' );
38+
39+
/*
40+
* Only valid string values count: the absence of a charset
41+
* does not imply any charset, let alone UTF-8.
42+
*/
43+
if ( ! is_string( $charset_to_examine ) ) {
44+
return false;
45+
}
46+
47+
return (
48+
0 === strcasecmp( 'UTF-8', $charset_to_examine ) ||
49+
0 === strcasecmp( 'UTF8', $charset_to_examine )
50+
);
51+
}

0 commit comments

Comments
 (0)