最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

customization - Is it possible assign a secondary existing role to already existing one?

programmeradmin0浏览0评论

Im interested to know if it possible Assign a secondary role IF the user it register by a specific role.

For example:

If the user register as "OWNER" wordpress must assign the existing user role "TEACHER".

I found different funtions online but nobody works, so i was wondering this specific needed its not implemented by wordpress.

Thank you!

EDIT:

I try to manage by myself a code but still i have some issue to compare the current user role at the moment of the registration:

add_action( 'user_register', 'add_secondary_role', 10, 1 );

function add_secondary_role( $user_id ) {

    $user = get_user_by('id', $user_id);

if ( in_array( $roles, 'owner' ) ) {
    
    $user->add_role('teacher');

} else if ( in_array( $roles, 'guest' ) ) {
    
    $user->add_role('student');

}

}
发布评论

评论列表(0)

  1. 暂无评论