Hello Amir. Welcome to Moodle development. For the start, you may find the "Moodle Plugin Development Basics" course at https://learn.moodle.org/ useful for you. Beware that after_require_login hook would be called pretty frequently. Basically on almost every page request. There might be more effective way to implement this. Event subscription for the core\event\user_loggedin comes to my mind as a good candidate. There are a few plugins already that seem to implement automatic enrolment once a certain event occurs - please browse through https://moodle.org/plugins/?q=type:enrol Some of they may be a good starting point for your functionality.