2013-04-23 28 views
1

我使用AWD Facebook wordpress插件允許我的訪問者使用他們的Facebook帳戶信息登錄。當訪問者在我的網站上註冊時,我會自動創建一個標題爲他們的用戶名的新帖子,並將他們的Facebook個人資料圖片作爲內容。代碼如下:添加額外的字段以使用AWD Facebook WordPress插件登錄

function my_create_page($user_id){ 
$fbuide = 0; 
$the_user = get_userdata($user_id); 
$new_user_name = $the_user->user_login; 
$new_user_avatar = get_avatar($the_user->user_email); 

global $AWD_facebook; 
$fbuide = $AWD_facebook->uid; 

$headers = get_headers('http://graph.facebook.com/' . $fbuide . '/picture?type=large',1); 

    if(isset($headers['Location'])) { 
     $url = $headers['Location']; // string 
    } else { 
     $url = false; 
    } 

$my_avatar = "<img src='" . $url . "' class='avatar AWD_fbavatar' alt='" . $alt . "' height='" . $size . "' />"; 
    $my_post = array(); 
    $my_post['post_title'] = $new_user_name; 
    $my_post['post_type'] = 'post'; 
    $my_post['post_content'] = $my_avatar; 
    $my_post['post_status'] = 'publish'; 
    wp_insert_post($my_post); 
} 
add_action('user_register', 'my_create_page'); 

我想要完成的是有點不同,雖然。我也想包括關於用戶的簡要傳記(目前這篇文章只是他們的照片)。所以當訪客使用AWD Facebook登錄時,他們需要成爲一個額外的領域,讓用戶輸入他們的生物。然後,我可以從他們的用戶個人資料中獲取該信息並將其包含在帖子中。有關我如何完成此任何想法?有沒有不同的方式來做到這一點?

回答

0

我建議將他們的Facebook圖片存儲爲元數據,並將內容區域用作自動生成帖子的生物。所以,這樣的事情應該讓你開始:

$my_post = array(
    'post_title'=>$new_user_name, 
    'post_type'=>'post', 
    'post_content'=>'', 
    'post_status'=>'publish' 
); 
if($id = wp_insert_post($my_post)){ 
    update_post_meta($id, 'avatar', $url); 
} 

然後你就可以產生像這樣的循環:

if (have_posts()) : while (have_posts()) : the_post(); 
    //... stuff here 
    $avatar = get_post_meta($post->ID, 'avatar', 'true'); 
    the_content(); 
    echo '<img class="avatar AWD_fbavatar" src="'.$avatar.'" alt="'.$alt.'" height="'.$size.'" />'; 
endwhile;endif; 
+0

你需要確保的是,如果用戶不登記,你爲他們提供用某種前端UI將他們的生物信息作爲POST數據發送來更新帖子。否則,您需要爲新註冊的用戶授予更新帖子內容的權限。 – maiorano84 2013-04-23 23:39:30

相關問題