Un motore di ricerca WordPress per sviluppatori e autori di temi



wp_json_encode ›

Da4.1.0
Deprecaton/a
wp_json_encode ( $data, $options = 0, $depth = 512 )
Parametri: (3)
  • (mixed) $data Variable (usually an array or object) to encode as JSON.
    Richiesto:
  • (int) $options Optional. Options to be passed to json_encode(). Default 0.
    Richiesto: No
    Default:
  • (int) $depth Optional. Maximum depth to walk through $data. Must be greater than 0. Default 512.
    Richiesto: No
    Default: 512
Ritorna:
  • (string|false) The JSON encoded string, or false if it cannot be encoded.
Definito a:
Codex:
ChangeLog:
  • 5.3.0

Encode a variable into JSON, with some sanity checks.



Sorgenti

function wp_json_encode( $data, $options = 0, $depth = 512 ) {
	$json = json_encode( $data, $options, $depth );

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

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

	return json_encode( $data, $options, $depth );
}