You can now append some JSON URL to that URL like so … https://yourserver.com/cors.php?url=https://someurl.com/data.json and it returns drama-free JSON for your use and enjoyment. Assuming you have HTTPs on your server it should also deal with HTTP/HTTPS conflicts as well which is very handy at times.
header("Access-Control-Allow-Origin: *");//let the people in
header("content-type: application/json");//make the return all JSON-Y
$url = htmlspecialchars($_GET["url"]);//get the URL parameter from the . . . URL
echo file_get_contents($url);//spit it back out
1 Or name it whatever you want. I’m going using bossiness as a shortcut to clarity.
I am playing around with unfurling1open graph data in the WordPress TinyMCE editor. You can see what that looks like in the video above. It’s a lot like the oEmbed experience in WordPress but with the open graph information driving it.
I want the data to go into the post body but I don’t want a title that links to a post because these types of posts are more about getting people out to that original content. People could still manually enter a title and that’d work but if they choose not to I thought it’d be nice if it was just removed from the equation.
That’s pretty nice on the front end but on the backend you end up with a maze of posts with the title (no title). That seemed irritating so I cobbled together the following function which creates a mini excerpt from the post content but only applies the filter when you’re in the backend/dashboard. Nothing fancy but a nice little pattern that I expect I’ll use again.