wc_esc_json()
Escape JSON for use on HTML or attribute text nodes.
No Hooks.
Returns
String. Escaped JSON.
Usage
wc_esc_json( $json, $html );
- $json(string) (required)
- JSON to escape.
- $html(true|false)
- True if escaping for HTML text node, false for attributes. Determines how quotes are handled.
Default:false
Changelog
| Since 3.5.5 | Introduced. |
wc_esc_json() wc esc json code WC 10.6.2
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: `&` -> `&`.
);
}