Created
April 27, 2016 00:24
-
-
Save ryanscherler/383626015b290da29ad0ece2d73a8d64 to your computer and use it in GitHub Desktop.
Gets Recent Instagrams and sets as WP transient.
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 | |
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