PluginProbe
User Access Manager / trunk
User Access Manager vtrunk
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
user-access-manager / src / Controller / Frontend / Content / AdminOutputControllerTrait.php

AdminOutputControllerTrait.php in User Access Manager trunk, at src/Controller/Frontend/Content/AdminOutputControllerTrait.php

52 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace UserAccessManager\Controller\Frontend\Content;
6
7 use UserAccessManager\Config\MainConfig;
8 use UserAccessManager\Config\WordpressConfig;
9 use UserAccessManager\User\UserHandler;
10 use UserAccessManager\UserGroup\UserGroupHandler;
11 use UserAccessManager\UserGroup\UserGroupTypeException;
12 use UserAccessManager\Util\Util;
13 use UserAccessManager\Wrapper\Wordpress;
14
15 trait AdminOutputControllerTrait
16 {
17 abstract protected function getWordpress(): Wordpress;
18 abstract protected function getWordpressConfig(): WordpressConfig;
19 abstract protected function getMainConfig(): MainConfig;
20 abstract protected function getUtil(): Util;
21 abstract protected function getUserHandler(): UserHandler;
22 abstract protected function getUserGroupHandler(): UserGroupHandler;
23
24 private function showAdminHint(): bool
25 {
26 return $this->getWordpressConfig()->atAdminPanel() === false
27 && $this->getMainConfig()->blogAdminHint() === true;
28 }
29
30 /**
31 * @throws UserGroupTypeException
32 */
33 public function adminOutput(string $objectType, int|string|null $objectId, $text = null): string
34 {
35 if ($this->showAdminHint() === true) {
36 $hintText = $this->getMainConfig()->getBlogAdminHintText();
37
38 if ($text !== null && $this->getUtil()->endsWith($text, $hintText) === true) {
39 return '';
40 }
41
42 if ($this->getUserHandler()->userIsAdmin($this->getWordpress()->getCurrentUser()->ID) === true
43 && count($this->getUserGroupHandler()->getUserGroupsForObject($objectType, $objectId)) > 0
44 ) {
45 return $hintText;
46 }
47 }
48
49 return '';
50 }
51 }
52