Skip to content

Instantly share code, notes, and snippets.

@kain-jy
Created September 27, 2011 18:58
Show Gist options
  • Save kain-jy/1245914 to your computer and use it in GitHub Desktop.
Save kain-jy/1245914 to your computer and use it in GitHub Desktop.
wordpress action snipped for posting facebook page when published any post.
function post_facebook($post_ID){
$thumbnail = wp_get_attachment_image_src ( get_post_thumbnail_id ( $post_ID ));
$thumbnail = $thumbnail[0];
$permalink = get_permalink($post_ID);
$title = get_the_title($post_ID);
$ch = curl_init("https://graph.facebook.com/{FACEBOOK_PAGE_ID}/feed");
$params = array(
"access_token"=>"{FACEBOOK_PAGES_ACCESS_TOKEN}",
"message" => "[update] ".$title,
"link" => $permalink,
"picture" => $thumbnail,
"name" => $title,
"caption" => "{CAPTION}",
);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params );
$data = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
return $post_ID;
}
add_action('publish_post','post_facebook');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment