diff --git a/lib/badgeslib.php b/lib/badgeslib.php index 9724bf79f60cf..70ba3ba7cacbf 100644 --- a/lib/badgeslib.php +++ b/lib/badgeslib.php @@ -723,7 +723,7 @@ function badges_notify_badge_award(badge $badge, $userid, $issued, $filepathhash // Notify recipient. $eventdata = new \core\message\message(); - $eventdata->courseid = $badge->courseid; + $eventdata->courseid = is_null($badge->courseid) ? SITEID : $badge->courseid; // Profile/site come with no courseid. $eventdata->component = 'moodle'; $eventdata->name = 'badgerecipientnotice'; $eventdata->userfrom = $userfrom;