Just change the permission check to:
$context = get_context_instance(CONTEXT_SYSTEM);
if (!has_capability('moodle/site:config',$context)) {
Just change the permission check to:
$context = get_context_instance(CONTEXT_SYSTEM);
if (!has_capability('moodle/site:config',$context)) {