wc_esc_json( string $json, bool $html = false )

Escape JSON for use on HTML or attribute text nodes.


Description Description


Parameters Parameters

$json

(Required) JSON to escape.

$html

(Optional) True if escaping for HTML text node, false for attributes. Determines how quotes are handled.

Default value: false


Top ↑

Return Return

(string) Escaped JSON.


Top ↑

Source Source

File: includes/wc-formatting-functions.php

function wc_esc_json( $json, $html = false ) {
	return _wp_specialchars(
		$json,
		$html ? ENT_NOQUOTES : ENT_QUOTES, // Escape quotes in attribute nodes only.
		'UTF-8',                           // json_encode() outputs UTF-8 (really just ASCII), not the blog's charset.
		true                               // Double escape entities: `&` -> `&`.
	);
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.5.5 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.