diff --git a/class-MenuEntry.php b/class-MenuEntry.php index 489155f..ca8b0c4 100644 --- a/class-MenuEntry.php +++ b/class-MenuEntry.php @@ -1,126 +1,129 @@ . /** * Define a menu entry * * Some menu entries define a menu tree and can be displayed later. */ class MenuEntry { /** * Menu user identifier * * e.g. 'home' * * @var string */ public $uid; /** * Identifier of the parent menu * * @var array|string|null */ public $parentUid; /** * URI of the menu * * @var string */ public $url; /** * Menu title * * @var string */ public $name; /** * Permission to show this menu * * @var string */ public $permission; /** * Extra metadata */ public $extra; /** * Constructor * * @param string $uid Menu user identifier e.g. 'home' * @param string $url Page URL e.g. 'home.html' * @param string $name Page name * @param string $parent_uid Parent menu user identifier - * @param string $permission Permission required to see this page + * @param string $permission Permission required to see this page (true: always, false: never, string: check the permission name) * @param string $extram Extra metadata */ - function __construct( $uid, $url = null, $name = null, $parent_uid = null, $permission = null, $extra = null ) { + function __construct( $uid, $url = null, $name = null, $parent_uid = null, $permission = true, $extra = null ) { $this->uid = $uid; $this->url = $url; $this->name = $name; $this->parentUid = $parent_uid; // backward compatibility if( is_array( $permission ) ) { error( "deprecated use of MenuEntry: now the #5 argument is \$permission and not $extra" ); $extra = $permission; $permission = null; } $this->permission = $permission; $this->extra = $extra; } /** * Call site_page() on the URL * * @param $full_url boolean * @return string * @see site_page() */ public function getSitePage( $full_url = false ) { return site_page( $this->url, $full_url ); } /** * Check if the user has the permission to see this page * * @return boolean */ public function isVisible() { - return $this->permission ? has_permission( $this->permission ) : true; + if( is_string( $this->permission ) ) { + return has_permission( $this->permission ); + } + return $this->permission; } /** * Get a metadata by name (alias) */ public function getExtra( $arg, $default = null ) { return $this->get($arg, $default); } public function get( $arg, $default = null ) { if( isset( $this->extra[ $arg ] ) ) { return $this->extra[ $arg ]; } return $default; } }