wppaste
WordPress

wp_json_encode( mixed $value, int $flags = 0, int $depth = 512 ): string|false

Since
4.1.0, 5.3.0, 6.5.0
Source
wp-includes/functions.php:4397
Encodes a variable into JSON, with some confidence checks.

Parameters

$valuemixed
Variable (usually an array or object) to encode as JSON.
$flagsintoptional
Options to be passed to json_encode(). Default 0.Default: 0
$depthintoptional
Maximum depth to walk through $value. Must be greater than 0. Default 512.Default: 512

Return

string|false
The JSON encoded string, or false if it cannot be encoded.

Uses · 1

Used by · 50

Show all 50

Source

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 );}

History

Introduced in 4.1.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.5.0
The $data parameter has been renamed to $value and the $options parameter to $flags for parity with PHP.from the docblock
5.3.0
No longer handles support for PHP < 5.6.from the docblock
4.1.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/functions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.