Home › Forums › Legacy Support › Support queries › How-to & Troubleshooting › Adding courses to a specific USER role automatically.
- This topic has 18 replies, 2 voices, and was last updated 5 years, 7 months ago by logan.
-
AuthorPosts
-
May 3, 2019 at 11:38 am #207447jsnmrkSpectatorHI 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.May 4, 2019 at 7:24 am #207596loganMemberHello, 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.May 4, 2019 at 10:01 am #207615jsnmrkSpectatorHi 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.May 6, 2019 at 9:51 am #207736jsnmrkSpectatorThis reply has been marked as private.May 6, 2019 at 11:00 am #207755loganMemberHello, 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); } } }May 7, 2019 at 6:14 am #207913jsnmrkSpectatorHi, 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.May 7, 2019 at 8:46 am #207952loganMemberHello, 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 itMay 7, 2019 at 10:16 am #207974jsnmrkSpectatorThanks 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?May 7, 2019 at 10:20 am #207976loganMemberSorry i forgot to mention that these steps will be performed on your site. i need your credentials in a private reply :P My mistake lolMay 7, 2019 at 11:20 am #207991jsnmrkSpectatorHi 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.May 8, 2019 at 7:22 am #208154loganMemberHello, 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.May 8, 2019 at 12:14 pm #208213jsnmrkSpectatorHi 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.May 9, 2019 at 5:52 am #208319loganMemberHello, 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.May 10, 2019 at 10:05 am #208580jsnmrkSpectatorHi 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); } } }May 11, 2019 at 8:34 am #208715loganMemberHello, 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. -
AuthorPosts
- The topic ‘Adding courses to a specific USER role automatically.’ is closed to new replies.