-
-
Save tommcfarlin/ff23ada3e309b8b1719e to your computer and use it in GitHub Desktop.
[WordPress] Retrieve Flickr Photos in WordPress
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 | |
/** | |
* Defines and wrap an instance of the cURL library to retrieve information from | |
* the specified URL. | |
* | |
* @param string $string The URL from which to retrieve information. | |
* @return $data The data retrieved from the incoming URL. | |
*/ | |
function acme_curl( $url ) { | |
$ch = curl_init( $url ); | |
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE ); | |
curl_setopt( $ch, CURLOPT_HEADER, 0 ); | |
curl_setopt( $ch, CURLOPT_USERAGENT, '' ); | |
curl_setopt( $ch, CURLOPT_TIMEOUT, 10 ); | |
$data = curl_exec($ch); | |
if ( 0 !== curl_errno( $ch ) || 200 !== curl_getinfo($ch, CURLINFO_HTTP_CODE ) ) { | |
$data = FALSE; | |
} | |
curl_close( $ch ); | |
return $data; | |
} |
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 | |
/** | |
* @return string $user_id The ID of the user that corresponds to the username specified in the customizer. | |
*/ | |
function acme_get_flickr_user_id() { | |
$flickr_username = get_theme_mod( 'acme_flickr_username' ); | |
$response = acme_curl( 'https://api.flickr.com/services/rest/?method=flickr.people.findByUsername&api_key=YOUR_API_KEY&username=' . $flickr_username ); | |
$oXML = simplexml_load_string( $response ); | |
$user_id = $oXML->user['id']; | |
echo $user_id; | |
} |
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 | |
/** | |
* Renders the most recent photos from the specified Flickr account. | |
* in `index.php`. | |
* | |
* @package Acme | |
*/ | |
?> | |
<div id="flickr"> | |
<script type="text/javascript" src="http://www.flickr.com/badge_code_v2.gne?count=10&display=latest&size=s&layout=x&source=user&user=<?php echo acme_get_flickr_user_id(); ?>"></script> | |
</div><!-- #flickr --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment