using has_capability() in index.php for use on front page

using has_capability() in index.php for use on front page

by Sam Mathias -
Number of replies: 0
Hi,

I have created a capability for use on the front page which I have put in a lib file for the index.php file.
There is one problem, I get this error on the front page.

Capability "homepage/isguest:view" was not found! This should be fixed in code.

Here is the code I am using

index.php

$context = get_context_instance(CONTEXT_SYSTEM);
if (has_capability('homepage/isnotguest:view', $context)) {
echo 'Not a guest';
} else {
echo 'Is a guest';
}

lib.php

$homepage_capability = array(
'homepage/isnotguest:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array (
'guest' => CAP_PREVENT,
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW,
)
)
);

I get 'Not a guest' when Admin
but 'Is a guest' for everyone else, not just guests

Any help would be greatly appreciated.

Regards
Sam
Average of ratings: -