diff --git a/badges/external.php b/badges/external.php index e9c4ab3580e..f18883bf42b 100644 --- a/badges/external.php +++ b/badges/external.php @@ -51,8 +51,17 @@ if (!empty($CFG->forceloginforprofiles)) { // Get all external badges of a user. $out = get_backpack_settings($userid); + +// If we didn't find any badges then print an error. +if (is_null($out)) { + print_error('error:externalbadgedoesntexist', 'badges'); +} + $badges = $out->badges; +// The variable to store the badge we want. +$badge = ''; + // Loop through the badges and check if supplied badge hash exists in user external badges. foreach ($badges as $b) { if ($hash == hash("md5", $b->hostedUrl)) { @@ -61,9 +70,9 @@ foreach ($badges as $b) { } } -// If we didn't find the badge, a user might be trying to replace userid parameter. -if (is_null($badge)) { - print_error(get_string('error:externalbadgedoesntexist', 'badges')); +// If we didn't find the badge a user might be trying to replace the userid parameter. +if (empty($badge)) { + print_error('error:externalbadgedoesntexist', 'badges'); } $PAGE->set_context(context_system::instance());