Adding courses to a specific USER role automatically.

Home Forums Legacy Support Support queries How-to & Troubleshooting Adding courses to a specific USER role automatically.

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #207447
    jsnmrk
    Spectator
    HI There, We have implemented SSO (single sign on) on our site with an idp. This company is going to be taking specific courses on our platform not available to other users. When they sign on currently they are automatically added to our user DB as a (role) student, however, I have made another role called "Student-SSO" using User Role Editor plugin https://wordpress.org/plugins/user-role-editor/ - so they are automatically added to the DB via SSO but as this new user role. This part was easy. I want to know a way I can add specific courses to this new user role by default. So when a new user is added to the DB and assigned this new role "Student-SSO" they have certain courses available to them on their dashboard. (i.e They are added to certain courses by default) How can we achieve this? Thanks in advance.
    #207596
    logan
    Member
    Hello, No that is not available in wplms as of now. but you can do one thing. you have to create free courses. if courses are free then you can directly assign the after user sign in automatically. there is a setting in wp-admin >> lms >> setting >> general setting >>  here: http://prntscr.com/nk81hh you need to enable this checkbox.
    #207615
    jsnmrk
    Spectator
    Hi again Logan, I know its not currently possible in WPLMS functionality. That however was not my question. My question is how am I able to achieve my desired result of adding specific courses to a custom user role I have made. Is there perhaps some code etc I can add to the WPLMS customization plugin that will help me achieve this desired result I’m looking for. If if you’re unable to help me please can you ask someone else on the WPLMS team to chime in here. Perhaps Alex - he was very helpful in the past. I’ve been a long time user of WPLMS and always renew my support. A solution would be greatly appreciated. Thanks.
    #207736
    jsnmrk
    Spectator
    This reply has been marked as private.
    #207755
    logan
    Member
    Hello, Please paste this snippets in your wp-admin >> plugins >> editor >> wplms-customizer plugin >> wplms-customizer.php add_action('user_register','add_mah_custom_curses'); function add_mah_custom_curses($user_id){ $courses = [50,51,52,53];//enter your course ids here     //checking user role $user = get_userdata( $user_id ); $roles = (array)$user->roles; if(in_array('mah_custom_role',$roles)){ foreach ($courses as $key => $course) { bp_course_add_user_to_course($user_id,$course); } } }
    #207913
    jsnmrk
    Spectator
    Hi, thanks for the reply. I’ve not tested it yet but will do so shortly. However before I do I’m just looking at the code and can see where custom course ID’s should be entered. But where in this code is the <u>custom user role</u> identified? I’d like only a certain USER ROLE to be assigned specific courses not all user roles. So where do I add in my custom user role I created, which I called “Student-SSO” ? Finally I just want to make sure there’s no spelling error in your code  you used “curses” in the first few lines of code, is this correct or should it be “courses” thanks.
    #207952
    logan
    Member
    Hello, No thats just a function i have written no grammatical mistake. i need to check wp-admin -> users.php -> select and edit any user in the site role option -> select dropdown : inspect it and find the value param in option tag in that select box. that will be placed here: http://prntscr.com/nlfwff that will be the slug of it
    #207974
    jsnmrk
    Spectator
    Thanks Logan. So am I waiting for more feedback from you on how to do this? An example snippet perhaps and where to find the correct user role ID etc?
    #207976
    logan
    Member
    Sorry i forgot to mention that these steps will be performed on your site. i need your credentials in a private reply :P My mistake lol
    #207991
    jsnmrk
    Spectator
    Hi Logan. Are you perhaps able to explain in detail the steps you would take to find the user role ID, so that I can perhaps do this part myself? Maybe it would also benefit the others reading this to know these steps. We have strict rules about who has administrative access to our site backend so would like to investigate this route first. Thank you.
    #208154
    logan
    Member
    Hello, i have already told you the steps. Goto wp-admin >> users >> select a user >> goto site role option >> select dropdown >> inspect it >> check the value of param attribute in option tag. then use this param value as slug in your code.
    #208213
    jsnmrk
    Spectator
    Hi Logan, Thanks I found the param value. Found it easily using your steps outlined above. I just want to make sure that when a NEW user registers they will still be registered at the 'default' role of STUDENT. It's ONLY the users signing on via SSO from our partner that will be signed up (using the code above) to this custom user role of SSO_STUDENT In other words, will what we are doing here NOT EFFECT the normal users registering on our site - they will still be registered at the default "student" role. Right? Thank for your help. I'm sure this post is going to be very helpful for others too.
    #208319
    logan
    Member
    Hello, The above code is only for the new registered users. role will be the same as student. please apply the codes and test the scenarios. if anything goes wrong let me know.
    #208580
    jsnmrk
    Spectator
    Hi Logan, I have added the code as you suggested to the WPLMS customizer plugin, replaced with course ID's I needed added as well as the user role, but when a new user gets signed up to this role I created it IS NOT adding the courses to their profile. I have pasted below the exact code I am using. Please can you help here as to why this is not working? Thanks.  
    //SSO adding courses to custom created user role// add_action('user_register','add_mah_custom_curses'); function add_mah_custom_curses($user_id){ $courses = [7309]; //<---- enter your course ids here separated by commas//   //checking user role// $user = get_userdata( $user_id ); $roles = (array)$user->roles; if(in_array('mdlz_student',$roles)){ foreach ($courses as $key => $course) { bp_course_add_user_to_course($user_id,$course); } } }
    #208715
    logan
    Member
    Hello, i really don't understand this: "I have added the code as you suggested to the WPLMS customizer plugin, replaced with course ID's I needed added as well as the user role, but when a new user gets signed up to this role I created it IS NOT adding the courses to their profile. I have pasted below the exact code I am using. Please, can you help here as to why this is not working? Thanks." i don't know what is your field, how it works, how are you adding users. it could be anything. if i cant see steps or related data. this could be anything, maybe something i and you are skipping. i cant take steps towards debugging. i hope you understand what i mean. it would be great if you share the video of the steps you are following so that i can replicate the issue at our end, test it then will share a working solution for it.
Viewing 15 posts - 1 through 15 (of 19 total)
  • The topic ‘Adding courses to a specific USER role automatically.’ is closed to new replies.