Skip to content

Instantly share code, notes, and snippets.

@nciske
Created October 29, 2013 16:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nciske/7217586 to your computer and use it in GitHub Desktop.
Save nciske/7217586 to your computer and use it in GitHub Desktop.
<?php
/*
== Requirements ==
http://wordpress.org/plugins/json-api/ on the source domain.
*/
/*
== Usage ==
[json_include url ="http://domain.com/url"]Enter fallback content here.[/json_include]
*/
/*
== Shortcode ==
Using page caching or caching the result in a transient for 24 hours
is probably a good idea from a performance perspective.
*/
add_shortcode( 'json_include', 'json_include_sc' );
function json_include_sc( $atts, $content ){
extract( shortcode_atts( array(
'url' => '',
), $atts, 'json_include' ) );
if( !$url ) return $content;;
$url = add_query_arg( 'json','1', $url );
$response = wp_remote_get( $url );
if( !$response ) return $content;
$post = json_decode( $response['body'] );
//echo '<pre>'. print_r($post,1) . '</pre>';
if( isset( $post->page->content ) ) {
return $post->page->content;
}else{
return $content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment