Skip to content

Instantly share code, notes, and snippets.

@codearachnid
Last active December 16, 2015 03:39
Show Gist options
  • Save codearachnid/5371606 to your computer and use it in GitHub Desktop.
Save codearachnid/5371606 to your computer and use it in GitHub Desktop.
Replace the method get_facebook_photo in the-events-calendar-facebook-importer.php (line 273 in version 1.0.5) to add additional parsing to the Facebook Open Graph picture import.
<?php
// use this method to replace the orininal in v1.0.5 (line 273 in the-events-calendar-facebook-importer.php)
/**
* retrieve a facebook event photo url (after redirect) along with photo data
* example: https://graph.facebook.com/331218348435/?fields=picture&type=large
* @param string $object_id the object to retrieve
* @return array the image url
*/
function get_facebook_photo( $object_id ) {
$photo_error = false;
$api_url = $this->build_url_with_access_token( $object_id . '/', array( 'fields' => 'cover', 'return_ssl_resources' => 1 ) );
$api_request = $this->json_retrieve( $api_url );
if( !empty( $api_request->cover->source ) ) {
$new_path = $api_request->cover->source;
$get_photo = wp_remote_get( $api_request->cover->source );
} else {
$photo_error = true;
}
// hat tip to @jessebrede (github) for suggesting a tweak to import old fb image formats if erroring
if( $photo_error || !empty( $get_photo->errors ) ){
$api_url = $this->build_url_with_access_token( $object_id . '/', array( 'fields' => 'picture', 'type' => 'large', 'return_ssl_resources' => 1 ) );
$api_request = $this->json_retrieve( $api_url );
$new_path = str_replace("_q.", "_n.", $api_request->picture->data->url );
$get_photo = wp_remote_get( $new_path );
}
// setup return object
$photo['url'] = $new_path;
$photo['source'] = $get_photo['body'];
return apply_filters( 'tribe_fb_get_facebook_photo', $photo, $api_url, $api_request );
}
@codearachnid
Copy link
Author

Thanks @jessebrede - have reintegrated the old style lookup so that it pulls both now if needed. This is now integrated in to Facebook Events 1.0.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment