Skip to content

Instantly share code, notes, and snippets.

@ryanscherler
Created April 27, 2016 00:24
Show Gist options
  • Save ryanscherler/383626015b290da29ad0ece2d73a8d64 to your computer and use it in GitHub Desktop.
Save ryanscherler/383626015b290da29ad0ece2d73a8d64 to your computer and use it in GitHub Desktop.
Gets Recent Instagrams and sets as WP transient.
<?php
namespace Starter\Extras;
function instagramUserMedia($token, $count = 6, $minutes = 5) {
$results = [];
$transient_key = __NAMESPACE__ . 'instagram';
if (!$results = get_transient($transient_key)) {
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => "https://api.instagram.com/v1/users/self/media/recent/?access_token={$token}&count={$count}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2
));
$results = curl_exec($ch);
curl_close($ch);
set_transient($transient_key, $results, (int) $minutes * MINUTE_IN_SECONDS);
}
return json_decode($results, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment