PluginProbe
User Access Manager / 2.2.21
User Access Manager v2.2.21
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 / AdminOutputControllerTrait.php

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

102 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * FrontendAdminOutputControllerTrait.php
4 *
5 * The FrontendTermController trait file.
6 *
7 * PHP versions 5
8 *
9 * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 * @copyright 2008-2017 Alexander Schneider
11 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 * @version SVN: $id$
13 * @link http://wordpress.org/extend/plugins/user-access-manager/
14 */
15
16 declare(strict_types=1);
17
18 namespace UserAccessManager\Controller\Frontend;
19
20 use UserAccessManager\Config\MainConfig;
21 use UserAccessManager\Config\WordpressConfig;
22 use UserAccessManager\User\UserHandler;
23 use UserAccessManager\UserGroup\UserGroupHandler;
24 use UserAccessManager\UserGroup\UserGroupTypeException;
25 use UserAccessManager\Util\Util;
26 use UserAccessManager\Wrapper\Wordpress;
27
28 /**
29 * Trait FrontendAdminOutputControllerTrait
30 *
31 * @package UserAccessManager\Controller
32 */
33 trait AdminOutputControllerTrait
34 {
35 /**
36 * @return Wordpress
37 */
38 abstract protected function getWordpress(): Wordpress;
39
40 /**
41 * @return WordpressConfig
42 */
43 abstract protected function getWordpressConfig(): WordpressConfig;
44
45 /**
46 * @return MainConfig
47 */
48 abstract protected function getMainConfig(): MainConfig;
49
50 /**
51 * @return Util
52 */
53 abstract protected function getUtil(): Util;
54
55 /**
56 * @return UserHandler
57 */
58 abstract protected function getUserHandler(): UserHandler;
59
60 /**
61 * @return UserGroupHandler
62 */
63 abstract protected function getUserGroupHandler(): UserGroupHandler;
64
65 /**
66 * Returns true if the hint text should be shown.
67 * @return bool
68 */
69 private function showAdminHint(): bool
70 {
71 return $this->getWordpressConfig()->atAdminPanel() === false
72 && $this->getMainConfig()->blogAdminHint() === true;
73 }
74
75 /**
76 * Returns the admin hint.
77 * @param string $objectType The object type.
78 * @param int|string $objectId The object id we want to check.
79 * @param null $text The text on which we want to append the hint.
80 * @return string
81 * @throws UserGroupTypeException
82 */
83 public function adminOutput(string $objectType, $objectId, $text = null): string
84 {
85 if ($this->showAdminHint() === true) {
86 $hintText = $this->getMainConfig()->getBlogAdminHintText();
87
88 if ($text !== null && $this->getUtil()->endsWith($text, $hintText) === true) {
89 return '';
90 }
91
92 if ($this->getUserHandler()->userIsAdmin($this->getWordpress()->getCurrentUser()->ID) === true
93 && count($this->getUserGroupHandler()->getUserGroupsForObject($objectType, $objectId)) > 0
94 ) {
95 return $hintText;
96 }
97 }
98
99 return '';
100 }
101 }
102