admin管理员组文章数量:1335854
Can anyone help me to create a custom post type content when a new user is registered? But the user should be of specific role only.
I have been searching but couldn't find any solution.
Can anyone help me to create a custom post type content when a new user is registered? But the user should be of specific role only.
I have been searching but couldn't find any solution.
Share Improve this question edited May 27, 2020 at 9:30 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked May 27, 2020 at 8:20 user3626802user3626802 11 Answer
Reset to default 0Try below code:
add_action( 'user_register', 'create_new_post_onuser_registration', 10, 1 );
function create_new_post_onuser_registration( $user_id ){
// Get user info
$user_meta = get_userdata( $user_id );
$user_roles = $user_meta->roles;
// Update the role here
if ( in_array( 'subscriber', $user_roles ) ) {
// Do something.
// Create a new post
$subscriber_post = array(
'post_title' => $user_meta->nickname;
'post_content' => $user_meta->description,
'post_type' => 'custom_post_type', // Update to your custom post type
);
$post_id = wp_insert_post( $subscriber_post );
// Add custom data
add_post_meta( $post_id, 'user_email', $user_meta->user_email );
}
}
本文标签: Creating a custom post type upon registration for a specific user role
版权声明:本文标题:Creating a custom post type upon registration for a specific user role 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742397797a2467273.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论