Make WordPress Core


Ignore:
Timestamp:
05/18/2024 06:20:19 PM (5 months ago)
Author:
dmsnell
Message:

Move is_utf8_charset() into functions.php

This caused issues in maintenance mode, and it's not warranted to have
its own module. This will live alongside _canonical_charset(), it's
partner function.

Fixes: #61182.
Props: dmsnell, sergeybiryukov, swisspiddy.
Follow-up to: [58148].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r58147 r58169  
    74677467
    74687468/**
     7469 * Indicates if a given slug for a character set represents the UTF-8
     7470 * text encoding. If not provided, examines the current blog's charset.
     7471 *
     7472 * A charset is considered to represent UTF-8 if it is a case-insensitive
     7473 * match of "UTF-8" with or without the hyphen.
     7474 *
     7475 * Example:
     7476 *
     7477 *     true  === is_utf8_charset( 'UTF-8' );
     7478 *     true  === is_utf8_charset( 'utf8' );
     7479 *     false === is_utf8_charset( 'latin1' );
     7480 *     false === is_utf8_charset( 'UTF 8' );
     7481 *
     7482 *     // Only strings match.
     7483 *     false === is_utf8_charset( [ 'charset' => 'utf-8' ] );
     7484 *
     7485 *     // Without a given charset, it depends on the site option "blog_charset".
     7486 *     $is_utf8 = is_utf8_charset();
     7487 *
     7488 * @since 6.6.0
     7489 *
     7490 * @param ?string $blog_charset Slug representing a text character encoding, or "charset".
     7491 *                              E.g. "UTF-8", "Windows-1252", "ISO-8859-1", "SJIS".
     7492 * @return bool Whether the slug represents the UTF-8 encoding.
     7493 */
     7494function is_utf8_charset( $blog_charset = null ) {
     7495    $charset_to_examine = $blog_charset ?? get_option( 'blog_charset' );
     7496
     7497    /*
     7498     * Only valid string values count: the absence of a charset
     7499     * does not imply any charset, let alone UTF-8.
     7500     */
     7501    if ( ! is_string( $charset_to_examine ) ) {
     7502        return false;
     7503    }
     7504
     7505    return (
     7506        0 === strcasecmp( 'UTF-8', $charset_to_examine ) ||
     7507        0 === strcasecmp( 'UTF8', $charset_to_examine )
     7508    );
     7509}
     7510
     7511/**
    74697512 * Retrieves a canonical form of the provided charset appropriate for passing to PHP
    74707513 * functions such as htmlspecialchars() and charset HTML attributes.
Note: See TracChangeset for help on using the changeset viewer.