<?php 

/**
 *  Escaping for HTML attributes use this instead of esc_attr( json_encode( ) )
 *
 * @param  array or object $data array or object to be escaped 
 * @return properly escaped data
 */
function esc_json_encode( $data ) {

	if ( defined( 'JSON_HEX_AMP' ) ) { 
		// This is nice to have, but not strictly necessary since we use _wp_specialchars() below 
		$data = json_encode( $data, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ); 
	} else { 
		$data = json_encode( $data ); 
	} 
	return _wp_specialchars( $data, ENT_QUOTES, false, true );
}
