WordPress at Your Fingertips
function is not described

_wp_json_convert_string() WP 4.1.0

Convert a string to UTF-8, so that it can be safely encoded to JSON.

This is an internal function for using it by WP core itself. It's not recommended to use this function in your code.

No Hooks.

Return

String. The checked string.

Usage

_wp_json_convert_string( $string );
$string(string) (required)
The string which is to be converted.

Notes

Changelog

Since 4.1.0 Introduced.

Code of _wp_json_convert_string() WP 5.8.2

function _wp_json_convert_string( $string ) {
	static $use_mb = null;
	if ( is_null( $use_mb ) ) {
		$use_mb = function_exists( 'mb_convert_encoding' );
	}

	if ( $use_mb ) {
		$encoding = mb_detect_encoding( $string, mb_detect_order(), true );
		if ( $encoding ) {
			return mb_convert_encoding( $string, 'UTF-8', $encoding );
		} else {
			return mb_convert_encoding( $string, 'UTF-8', 'UTF-8' );
		}
	} else {
		return wp_check_invalid_utf8( $string, true );
	}
}