Created
December 24, 2011 01:20
-
-
Save jeffsebring/1515866 to your computer and use it in GitHub Desktop.
WordPress JSON Parser Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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