public function try_guestaccess(stdClass $instance) {
        global $USER, $CFG;

        $allow = false;

        if ($instance->password === '') {
            $allow = true;

        } else if (isset($USER->enrol_guest_passwords[$instance->id])) { // this is a hack, ideally we should not add stuff to $USER...
            if ($USER->enrol_guest_passwords[$instance->id] === $instance->password) {
                $allow = true;
            }
        }

        if ($allow) {
            // Temporarily assign them some guest role for this context
            $context = context_course::instance($instance->courseid);
            load_temp_course_role($context, $CFG->guestroleid);
            return ENROL_MAX_TIMESTAMP;
        }

        return false;
    }
public function try_guestaccess(stdClass $instance) {
        global $USER, $CFG;

        $allow = false;

        if ($instance->password === '') {
            $allow = true;

        } else if (isset($USER->enrol_guest_passwords[$instance->id])) { // this is a hack, ideally we should not add stuff to $USER...
            if ($USER->enrol_guest_passwords[$instance->id] === $instance->password) {
                $allow = true;
            }
        }

        if ($allow) {
            // Temporarily assign them some guest role for this context
            $context = context_course::instance($instance->courseid);
            load_temp_course_role($context, $CFG->guestroleid);
            return ENROL_MAX_TIMESTAMP;
        }

        return false;
    }
public function try_guestaccess ( stdClass $ instance ) { global $ USER , $ CFG ; $ allow = false ; if ( $ instance -> password === '' ) { $ allow = true ; } else if ( isset ( $ USER -> enrol_guest_passwords [ $ instance -> id ] ) ) { // this is a hack, ideally we should not add stuff to $USER... if ( $ USER -> enrol_guest_passwords [ $ instance -> id ] === $ instance -> password ) { $ allow = true ; } } if ( $ allow ) { // Temporarily assign them some guest role for this context $ context = context_course :: instance ( $ instance -> courseid ) ; load_temp_course_role ( $ context , $ CFG -> guestroleid ) ; return ENROL_MAX_TIMESTAMP ; } return false ; }
Attempt to automatically gain temporary guest access to course,
calling code has to make sure the plugin and instance are active.

@param stdClass $instance course enrol instance
@return bool|int false means no guest access, integer means end of cached time
Attempt to automatically gain temporary guest access to course calling code has to make sure the plugin and instance are active .