2014-02-06 70 views
0

我需要創建新用戶(僅限編輯器)後創建一個新的帖子(的自定義帖子類型)。 我想我必須使用像這樣的鉤:WordPress的:函數創建新用戶後創建新帖子

do_action('user_register', $user_id); 
add_action ('user_register', "create_post"); 
function create_post() 
{ 
// Create the post 
} 

但我不知道如何創建這個功能後。 我在新的用戶表單一些自定義字段...

感謝 紀堯姆

回答

0

嘗試使用參數與這裏的ADD_ACTION是簡單的例子

add_action('user_register', 'create_post', 10, 1); 

function create_post($user_id) { 

    if (isset($_POST['first_name'])) 
     ..... your code here 

} 

和惰性職位在給定鏈接中使用此功能http://codex.wordpress.org/Function_Reference/wp_insert_post

0

來自wordpress codex user_register

你可以做這樣的代碼

add_action('user_register', 'myplugin_registration_save', 10, 1); 

function myplugin_registration_save($user_id) { 
    //Here you can update user information after they registered 
    if (isset($_POST['first_name'])) { 
     update_user_meta($user_id, 'first_name', $_POST['first_name']); 
    } 

} 

要插入後後用戶註冊嘗試擴展代碼:

add_action('user_register', 'myplugin_registration_save', 10, 1); 

function myplugin_registration_save($user_id) { 
    //Here you can update user information after they registered 
    if (isset($_POST['first_name'])) { 
     update_user_meta($user_id, 'first_name', $_POST['first_name']); 
    } 

    // Here you can insert new post for registered users 
    $my_post = array(
     'post_title' => 'Title', 
     'post_content' => 'some content', 
     'post_status' => 'publish', 
     'post_author' => $user_id, //If to assign post to the currently registered user otherwise put 1 
     'post_type' => 'post' 
    ); 

    // Insert the post into the database 
    $_post_id = wp_insert_post($my_post); 
    if ($_post_id) { 
     return 'post inserted'; 
    } 
} 

update_user_meta允許您更新用戶的其他信息,他們註冊
wp_insert_post後,您可以將帖子以編程方式