/**
  * Triggered via the user_loggedin event, when a user logs in.
  *
  * @param stdClass $event
  */
 public static function user_loggedin($event)
 {
     global $DB;
     $eventdata = $event->get_data();
     if (!enrol_is_enabled('auto')) {
         return;
     }
     if (is_siteadmin($eventdata['userid'])) {
         // Don't enrol site admins
         return;
     }
     // Get all courses that have an auto enrol plugin, set to auto enrol on login, where the user isn't enrolled yet
     $sql = "SELECT e.courseid\n            FROM {enrol} e\n            LEFT JOIN {user_enrolments} ue ON e.id = ue.enrolid AND ue.userid = ?\n            WHERE e.enrol = 'auto'\n            AND e.status = ?\n            AND e.customint3 = ?\n            AND ue.id IS NULL";
     if (!($courses = $DB->get_records_sql($sql, array($eventdata['userid'], ENROL_INSTANCE_ENABLED, ENROL_AUTO_LOGIN)))) {
         return;
     }
     $autoplugin = enrol_get_plugin('auto');
     foreach ($courses as $course) {
         if (!($instance = $autoplugin->get_instance_for_course($course->courseid))) {
             continue;
         }
         $autoplugin->enrol_user($instance, $eventdata['userid'], $instance->roleid);
         // Send welcome message.
         if ($instance->customint2) {
             $autoplugin = enrol_get_plugin('auto');
             $autoplugin->email_welcome_message($instance, $DB->get_record('user', array('id' => $eventdata['userid'])));
         }
     }
 }
Esempio n. 2
0
 /**
  * Add post meta to REST API response.
  *
  * @since 1.0.0
  *
  * @param stdClass        $response Default API response object.
  * @param WP_Post         $post     Current post.
  * @param WP_REST_Request $request  Current API request.
  *
  * @return stdClass $response Updated response request.
  */
 public function add_rest_api_support_for_post_meta($response, $post, $request)
 {
     // Get initial response data.
     $response_data = $response->get_data();
     // Get post meta based on settings.
     $post_meta = get_post_custom($post->ID);
     $post_meta_checked = $this->get_post_meta_checked();
     $response_post_meta = array_intersect_key($post_meta, $post_meta_checked);
     // Add post meta to response data.
     $response_data = array_merge($response_data, $response_post_meta);
     // Re-assemble response.
     $response->set_data($response_data);
     return $response;
 }