Skip to content

Instantly share code, notes, and snippets.

@jeffsebring
Created December 24, 2011 01:20
Show Gist options
  • Save jeffsebring/1515866 to your computer and use it in GitHub Desktop.
Save jeffsebring/1515866 to your computer and use it in GitHub Desktop.
WordPress JSON Parser Example
<?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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment