Make WordPress Core


Ignore:
Timestamp:
07/18/2024 06:20:39 PM (8 weeks ago)
Author:
jorbin
Message:

General: Provide _is_utf8_charset() in compat.php for early use

#61182 introduced is_utf8_charset() as a way of standardizing checks for charset slugs referring to UTF-8. This is called by _mb_strlen() inside of compat.php, but is_utf8_charset() is defined in functions.php, which isn't loaded early on. Code calling mb_strlen() early on before functions.php loads in hosts without the multibyte extension therefore may crash.

Reviewed by hellofromTonya.
Merges [58763] to the 6.6 branch.

Props dmsnell, jonsurrell, joemcgill, jorbin.
Fixes #61680.

Location:
branches/6.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.6

  • branches/6.6/src/wp-includes/functions.php

    r58570 r58764  
    74977497 *
    74987498 * @since 6.6.0
    7499  *
    7500  * @param ?string $blog_charset Slug representing a text character encoding, or "charset".
    7501  *                              E.g. "UTF-8", "Windows-1252", "ISO-8859-1", "SJIS".
     7499 * @since 6.6.1 A wrapper for _is_utf8_charset
     7500 *
     7501 * @see _is_utf8_charset
     7502 *
     7503 * @param string|null $blog_charset Optional. Slug representing a text character encoding, or "charset".
     7504 *                                  E.g. "UTF-8", "Windows-1252", "ISO-8859-1", "SJIS".
     7505 *                                  Default value is to infer from "blog_charset" option.
    75027506 * @return bool Whether the slug represents the UTF-8 encoding.
    75037507 */
    75047508function is_utf8_charset( $blog_charset = null ) {
    7505     $charset_to_examine = $blog_charset ?? get_option( 'blog_charset' );
    7506 
    7507     /*
    7508      * Only valid string values count: the absence of a charset
    7509      * does not imply any charset, let alone UTF-8.
    7510      */
    7511     if ( ! is_string( $charset_to_examine ) ) {
    7512         return false;
    7513     }
    7514 
    7515     return (
    7516         0 === strcasecmp( 'UTF-8', $charset_to_examine ) ||
    7517         0 === strcasecmp( 'UTF8', $charset_to_examine )
    7518     );
     7509    return _is_utf8_charset( $blog_charset ?? get_option( 'blog_charset' ) );
    75197510}
    75207511
Note: See TracChangeset for help on using the changeset viewer.