有个钩子叫user_register() 你可以用的。它发生在创建新用户的过程中-就在他们被添加到数据库并具有ID之后,但在保存类似usermeta的first\\u名称之前。然后您可以使用wp_insert_post() 添加新帖子并将其指定为“作者”
<?php
// When a user first registers, run our function
add_action(\'user_register\', \'wpse_293428_create_user_post\', 10, 1);
function wpse_293428_create_user_post($user_id) {
// Set up a simple post array
$sample_post = array(
// Set to desired post type: post, page, etc.
\'post_type\' => \'post\',
\'post_title\' => \'Sample Post\',
// Post content can get much more complex if you need html etc.
\'post_content\' => \'This is a test post\',
// Choose post status you want: could be a draft, or could be published
\'post_status\' => \'publish\',
// Use the User ID that WP just created for this user
\'post_author\' => $user_id,
// Only if it\'s a Post, set Category - requires an array
\'post_category\' => array(1)
);
wp_insert_post($sample_post);
}
?>
您可能需要更改新帖子出现的类别,或者如果切换到创建页面,请确保删除
post_category. 根据您的需要,填写更复杂的
post_content 可能会有点棘手,所以从简单开始,然后慢慢构建出你想要的东西。