WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The following function checks option, if *blog_charset* is not utf8, than return original string. What is the purpose of this?

function sc_check_invalid_utf8( $string, $strip = false ) {
    $string = (string) $string;

    if ( 0 === strlen( $string ) ) {
        return '';

    // Store the site charset as a static to avoid multiple calls to get_option()
    static $is_utf8;
    if ( !isset( $is_utf8 ) ) {
        $is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) );
    if ( !$is_utf8 ) {
        return $string;


    return '';
share|improve this question

It's used by sanitize_text_field function to Sanitize a string from user input or from the db.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.