get('guest')`. * * #pw-internal * * @return Role * @throws WireException * */ public function getGuestRole() { if($this->guestRole) return $this->guestRole; $this->guestRole = parent::get((int) $this->wire()->config->guestUserRolePageID); return $this->guestRole; } /** * Get a Role by name, numeric ID or selector * * @param string $selectorString Role name or selector * @return Role|NullPage|null * */ public function get($selectorString) { if($selectorString === 'guest') return $this->getGuestRole(); return parent::get($selectorString); } /** * Save a Role * * #pw-group-manipulation * * @param Role|Page $page * @return bool True on success, false on failure * @throws WireException * */ public function ___save(Page $page) { return parent::___save($page); } /** * Permanently delete a Role * * #pw-group-manipulation * * @param Role|Page $page Permission to delete * @param bool $recursive If set to true, then this will attempt to delete any pages below the Permission too. * @return bool True on success, false on failure * @throws WireException * */ public function ___delete(Page $page, $recursive = false) { return parent::___delete($page, $recursive); } /** * Add a new Role with the given name and return it * * #pw-group-manipulation * * @param string $name Name of role you want to add, i.e. "hello-world" * @return Role|NullPage Returns a Role page on success, or a NullPage on error * */ public function ___add($name) { /** @var Role|NullPage $role */ $role = parent::___add($name); return $role; } /** * Ensure that every role has at least 'page-view' permission * * #pw-internal * * @param Page $page * */ protected function loaded(Page $page) { $hasPageView = false; foreach($page->permissions as $permission) { if($permission->name === 'page-view') $hasPageView = true; if($hasPageView) break; } if(!$hasPageView) { $pageView = $this->wire()->permissions->get('page-view'); $page->permissions->add($pageView); } } /** * Hook called when a page and its data have been deleted * * #pw-internal * * @param Page $page * */ public function ___deleted(Page $page) { foreach($this->wire()->templates as $template) { /** @var Template $template */ if(!$template->useRoles) continue; $template->removeRole($page, 'all'); if($template->isChanged()) $template->save(); } parent::___deleted($page); } }