来自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 可让您以编程方式插入帖子