public
Last active

WordPress JSON Parser Example

  • Download Gist
wordpress_json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
<?php
/**
* JSON Response
* Get json data from url and decode.
*/
# Get the WordPress json parser
 
if ( ! function_exists( 'json_parser' ) ) :
# Get the WordPress json parser
add_action('wp_print_scripts', 'json_parser');
function json_parser() {
wp_enqueue_script('json2');
}
 
endif;
 
// Return Parsed json from url
if ( ! function_exists( 'json_response' ) ) :
 
function json_response( $url ) {
 
# Parse the given url
$raw = file_get_contents( $url, 0, null, null );
$decoded = json_decode( $raw );
return $decoded;
}
 
endif;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.