來自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後,您可以將帖子以編程方式