您可以使用wp_update_user
更新新创建用户的角色。
if ( !username_exists( \'mytestuser\' ) ) {
$user_id = wp_create_user(\'mytestuser\', \'testpass345\',\'[email protected]\');
$user_id = wp_update_user( array( \'ID\' => $user_id, \'role\' => \'author\' ) );
}
进一步阅读
WordPress Codex.
或者,您可以删除当前角色并分配新角色:
if ( !username_exists( \'mytestuser\' ) ) {
$user_id = wp_create_user(\'mytestuser\', \'testpass345\',\'[email protected]\');
$user = new WP_User( $user_id );
$user->remove_role( \'subscriber\' );
$user->add_role( \'author\' );
}