wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_json_encode › WordPress Function

Seit4.1.0
Veraltetn/v
wp_json_encode ( $value, $flags = 0, $depth = 512 )
Parameter: (3)
  • (mixed) $value Variable (usually an array or object) to encode as JSON.
    Erforderlich: Ja
  • (int) $flags Optional. Options to be passed to json_encode(). Default 0.
    Erforderlich: Nein
    Standard:
  • (int) $depth Optional. Maximum depth to walk through $value. Must be greater than 0. Default 512.
    Erforderlich: Nein
    Standard: 512
Gibt zurück:
  • (string|false) The JSON encoded string, or false if it cannot be encoded.
Definiert in:
Codex:
Changelog:
  • 5.3.0
  • 6.5.0

Encodes a variable into JSON, with some confidence checks.



Quellcode

function wp_json_encode( $value, $flags = 0, $depth = 512 ) {
	$json = json_encode( $value, $flags, $depth );

	// If json_encode() was successful, no need to do more confidence checking.
	if ( false !== $json ) {
		return $json;
	}

	try {
		$value = _wp_json_sanity_check( $value, $depth );
	} catch ( Exception $e ) {
		return false;
	}

	return json_encode( $value, $flags, $depth );
}