_wp_json_prepare_data

The timeline below displays how wordpress function _wp_json_prepare_data has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * Prepares response data to be serialized to JSON.
 *
 * This supports the JsonSerializable interface for PHP 5.2-5.3 as well.
 *
 * @ignore
 * @since 4.4.0
 * @deprecated 5.3.0 This function is no longer needed as support for PHP 5.2-5.3
 *                   has been dropped.
 * @access private
 *
 * @param mixed $value Native representation.
 * @return bool|int|float|null|string|array Data ready for `json_encode()`.
 */
function _wp_json_prepare_data($value)
{
    _deprecated_function(__FUNCTION__, '5.3.0');
    return $value;
}

WordPress Version: 5.5

/**
 * Prepares response data to be serialized to JSON.
 *
 * This supports the JsonSerializable interface for PHP 5.2-5.3 as well.
 *
 * @ignore
 * @since 4.4.0
 * @deprecated 5.3.0 This function is no longer needed as support for PHP 5.2-5.3
 *                   has been dropped.
 * @access private
 *
 * @param mixed $data Native representation.
 * @return bool|int|float|null|string|array Data ready for `json_encode()`.
 */
function _wp_json_prepare_data($data)
{
    _deprecated_function(__FUNCTION__, '5.3.0');
    return $data;
}

WordPress Version: 5.4

/**
 * Prepares response data to be serialized to JSON.
 *
 * This supports the JsonSerializable interface for PHP 5.2-5.3 as well.
 *
 * @ignore
 * @since 4.4.0
 * @deprecated 5.3.0 This function is no longer needed as support for PHP 5.2-5.3
 *                   has been dropped.
 * @access     private
 *
 * @param mixed $data Native representation.
 * @return bool|int|float|null|string|array Data ready for `json_encode()`.
 */
function _wp_json_prepare_data($data)
{
    _deprecated_function(__FUNCTION__, '5.3.0');
    return $data;
}

WordPress Version: 5.3

/**
 * Prepares response data to be serialized to JSON.
 *
 * This supports the JsonSerializable interface for PHP 5.2-5.3 as well.
 *
 * @ignore
 * @since      4.4.0
 * @deprecated 5.3.0 This function is no longer needed as support for PHP 5.2-5.3
 *                   has been dropped.
 * @access     private
 *
 * @param mixed $data Native representation.
 * @return bool|int|float|null|string|array Data ready for `json_encode()`.
 */
function _wp_json_prepare_data($data)
{
    _deprecated_function(__FUNCTION__, '5.3.0');
    return $data;
}

WordPress Version: 4.4

/**
 * Prepares response data to be serialized to JSON.
 *
 * This supports the JsonSerializable interface for PHP 5.2-5.3 as well.
 *
 * @ignore
 * @since 4.4.0
 * @access private
 *
 * @param mixed $data Native representation.
 * @return bool|int|float|null|string|array Data ready for `json_encode()`.
 */
function _wp_json_prepare_data($data)
{
    if (!defined('WP_JSON_SERIALIZE_COMPATIBLE') || WP_JSON_SERIALIZE_COMPATIBLE === false) {
        return $data;
    }
    switch (gettype($data)) {
        case 'boolean':
        case 'integer':
        case 'double':
        case 'string':
        case 'NULL':
            // These values can be passed through.
            return $data;
        case 'array':
            // Arrays must be mapped in case they also return objects.
            return array_map('_wp_json_prepare_data', $data);
        case 'object':
            // If this is an incomplete object (__PHP_Incomplete_Class), bail.
            if (!is_object($data)) {
                return null;
            }
            if ($data instanceof JsonSerializable) {
                $data = $data->jsonSerialize();
            } else {
                $data = get_object_vars($data);
            }
            // Now, pass the array (or whatever was returned from jsonSerialize through).
            return _wp_json_prepare_data($data);
        default:
            return null;
    }
}