PluginProbe
User Access Manager / 2.1.11
User Access Manager v2.1.11
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
← All changes | src/UserAccessManager.php +312 -97 2.3.17 → 2.1.11 View file →
@@ -1,8 +1,18 @@
1 1 <?php
2 -
3 -declare(strict_types=1);
4 -
2 +/**
3 + * UserAccessManager.php
4 + *
5 + * The UserAccessManager class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <[email protected]>
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 + */
5 15 namespace UserAccessManager;
6 16
7 17 use UserAccessManager\Access\AccessHandler;
8 18 use UserAccessManager\Cache\Cache;
@@ -7,12 +17,13 @@
7 17 use UserAccessManager\Access\AccessHandler;
8 18 use UserAccessManager\Cache\Cache;
9 19 use UserAccessManager\Cache\CacheProviderFactory;
10 20 use UserAccessManager\Config\ConfigFactory;
21 +use UserAccessManager\Config\MainConfig;
11 22 use UserAccessManager\Config\ConfigParameterFactory;
12 -use UserAccessManager\Config\MainConfig;
13 23 use UserAccessManager\Controller\Backend\DynamicGroupsController;
14 24 use UserAccessManager\Controller\Backend\PostObjectController;
25 +use UserAccessManager\Controller\Backend\SetupController;
15 26 use UserAccessManager\Controller\Backend\TermObjectController;
16 27 use UserAccessManager\Controller\Backend\UserObjectController;
17 28 use UserAccessManager\Controller\ControllerFactory;
18 29 use UserAccessManager\Database\Database;
@@ -21,10 +32,10 @@
21 32 use UserAccessManager\File\FileProtectionFactory;
22 33 use UserAccessManager\Object\ObjectHandler;
23 34 use UserAccessManager\ObjectMembership\ObjectMembershipHandlerFactory;
24 35 use UserAccessManager\Setup\SetupHandler;
36 +use UserAccessManager\UserGroup\UserGroupFactory;
25 37 use UserAccessManager\User\UserHandler;
26 -use UserAccessManager\UserGroup\UserGroupFactory;
27 38 use UserAccessManager\UserGroup\UserGroupHandler;
28 39 use UserAccessManager\Util\Util;
29 40 use UserAccessManager\Widget\WidgetFactory;
30 41 use UserAccessManager\Wrapper\Php;
@@ -29,140 +40,357 @@
29 40 use UserAccessManager\Widget\WidgetFactory;
30 41 use UserAccessManager\Wrapper\Php;
31 42 use UserAccessManager\Wrapper\Wordpress;
32 43
44 +/**
45 + * Class UserAccessManager
46 + *
47 + * @package UserAccessManager
48 + */
33 49 class UserAccessManager
34 50 {
35 - public const VERSION = UAM_VERSION;
36 - public const DB_VERSION = '1.6.3';
51 + const VERSION = '2.1.11';
52 + const DB_VERSION = '1.6.1';
37 53
54 + /**
55 + * @var Php
56 + */
57 + private $php;
58 +
59 + /**
60 + * @var Wordpress
61 + */
62 + private $wordpress;
63 +
64 + /**
65 + * @var Util
66 + */
67 + private $util;
68 +
69 + /**
70 + * @var Cache
71 + */
72 + private $cache;
73 +
74 + /**
75 + * @var MainConfig
76 + */
77 + private $config;
78 +
79 + /**
80 + * @var Database
81 + */
82 + private $database;
83 +
84 + /**
85 + * @var ObjectHandler
86 + */
87 + private $objectHandler;
88 +
89 + /**
90 + * @var UserHandler
91 + */
92 + private $userHandler;
93 +
94 + /**
95 + * @var UserGroupHandler
96 + */
97 + private $userGroupHandler;
98 +
99 + /**
100 + * @var AccessHandler
101 + */
102 + private $accessHandler;
103 +
104 + /**
105 + * @var FileHandler
106 + */
107 + private $fileHandler;
108 +
109 + /**
110 + * @var SetupHandler
111 + */
112 + private $setupHandler;
113 +
114 + /**
115 + * @var UserGroupFactory
116 + */
117 + private $userGroupFactory;
118 +
119 + /**
120 + * @var ObjectMembershipHandlerFactory
121 + */
122 + private $membershipHandlerFactory;
123 +
124 + /**
125 + * @var ControllerFactory
126 + */
127 + private $controllerFactory;
128 +
129 + /**
130 + * @var WidgetFactory
131 + */
132 + private $widgetFactory;
133 +
134 + /**
135 + * @var CacheProviderFactory
136 + */
137 + private $cacheProviderFactory;
138 +
139 + /**
140 + * @var ConfigFactory
141 + */
142 + private $configFactory;
143 +
144 + /**
145 + * @var ConfigParameterFactory
146 + */
147 + private $configParameterFactory;
148 +
149 + /**
150 + * @var FileProtectionFactory
151 + */
152 + private $fileProtectionFactory;
153 +
154 + /**
155 + * @var FileObjectFactory
156 + */
157 + private $fileObjectFactory;
158 +
159 + /**
160 + * UserAccessManager constructor.
161 + *
162 + * @param Php $php
163 + * @param Wordpress $wordpress
164 + * @param Util $util
165 + * @param Cache $cache
166 + * @param MainConfig $config
167 + * @param Database $database
168 + * @param ObjectHandler $objectHandler
169 + * @param UserHandler $userHandler
170 + * @param UserGroupHandler $userGroupHandler
171 + * @param AccessHandler $accessHandler
172 + * @param FileHandler $fileHandler
173 + * @param SetupHandler $setupHandler
174 + * @param UserGroupFactory $userGroupFactory
175 + * @param ObjectMembershipHandlerFactory $membershipHandlerFactory
176 + * @param ControllerFactory $controllerFactory
177 + * @param WidgetFactory $widgetFactory
178 + * @param CacheProviderFactory $cacheProviderFactory
179 + * @param ConfigFactory $configFactory
180 + * @param ConfigParameterFactory $configParameterFactory
181 + * @param FileProtectionFactory $fileProtectionFactory
182 + * @param FileObjectFactory $fileObjectFactory
183 + */
38 184 public function __construct(
39 - private Php $php,
40 - private Wordpress $wordpress,
41 - private Util $util,
42 - private Cache $cache,
43 - private MainConfig $config,
44 - private Database $database,
45 - private ObjectHandler $objectHandler,
46 - private UserHandler $userHandler,
47 - private UserGroupHandler $userGroupHandler,
48 - private AccessHandler $accessHandler,
49 - private FileHandler $fileHandler,
50 - private SetupHandler $setupHandler,
51 - private UserGroupFactory $userGroupFactory,
52 - private ObjectMembershipHandlerFactory $membershipHandlerFactory,
53 - private ControllerFactory $controllerFactory,
54 - private WidgetFactory $widgetFactory,
55 - private CacheProviderFactory $cacheProviderFactory,
56 - private ConfigFactory $configFactory,
57 - private ConfigParameterFactory $configParameterFactory,
58 - private FileProtectionFactory $fileProtectionFactory,
59 - private FileObjectFactory $fileObjectFactory
185 + Php $php,
186 + Wordpress $wordpress,
187 + Util $util,
188 + Cache $cache,
189 + MainConfig $config,
190 + Database $database,
191 + ObjectHandler $objectHandler,
192 + UserHandler $userHandler,
193 + UserGroupHandler $userGroupHandler,
194 + AccessHandler $accessHandler,
195 + FileHandler $fileHandler,
196 + SetupHandler $setupHandler,
197 + UserGroupFactory $userGroupFactory,
198 + ObjectMembershipHandlerFactory $membershipHandlerFactory,
199 + ControllerFactory $controllerFactory,
200 + WidgetFactory $widgetFactory,
201 + CacheProviderFactory $cacheProviderFactory,
202 + ConfigFactory $configFactory,
203 + ConfigParameterFactory $configParameterFactory,
204 + FileProtectionFactory $fileProtectionFactory,
205 + FileObjectFactory $fileObjectFactory
60 206 ) {
207 + $this->php = $php;
208 + $this->wordpress = $wordpress;
209 + $this->util = $util;
210 + $this->cache = $cache;
211 + $this->config = $config;
212 + $this->database = $database;
213 + $this->objectHandler = $objectHandler;
214 + $this->userHandler = $userHandler;
215 + $this->userGroupHandler = $userGroupHandler;
216 + $this->accessHandler = $accessHandler;
217 + $this->fileHandler = $fileHandler;
218 + $this->setupHandler = $setupHandler;
219 + $this->userGroupFactory = $userGroupFactory;
220 + $this->membershipHandlerFactory = $membershipHandlerFactory;
221 + $this->controllerFactory = $controllerFactory;
222 + $this->widgetFactory = $widgetFactory;
223 + $this->cacheProviderFactory = $cacheProviderFactory;
224 + $this->configFactory = $configFactory;
225 + $this->configParameterFactory = $configParameterFactory;
226 + $this->fileProtectionFactory = $fileProtectionFactory;
227 + $this->fileObjectFactory = $fileObjectFactory;
228 +
61 229 $this->cache->setActiveCacheProvider($this->config->getActiveCacheProvider());
62 230 }
63 231
64 - public function getPhp(): Php
232 + /**
233 + * @return Php
234 + */
235 + public function getPhp()
65 236 {
66 237 return $this->php;
67 238 }
68 239
69 - public function getWordpress(): Wordpress
240 + /**
241 + * @return Wordpress
242 + */
243 + public function getWordpress()
70 244 {
71 245 return $this->wordpress;
72 246 }
73 247
74 - public function getUtil(): Util
248 + /**
249 + * @return Util
250 + */
251 + public function getUtil()
75 252 {
76 253 return $this->util;
77 254 }
78 255
79 - public function getCache(): Cache
256 + /**
257 + * @return Cache
258 + */
259 + public function getCache()
80 260 {
81 261 return $this->cache;
82 262 }
83 263
84 - public function getConfig(): MainConfig
264 + /**
265 + * @return MainConfig
266 + */
267 + public function getConfig()
85 268 {
86 269 return $this->config;
87 270 }
88 271
89 - public function getDatabase(): Database
272 + /**
273 + * @return Database
274 + */
275 + public function getDatabase()
90 276 {
91 277 return $this->database;
92 278 }
93 279
94 - public function getObjectHandler(): ObjectHandler
280 + /**
281 + * @return ObjectHandler
282 + */
283 + public function getObjectHandler()
95 284 {
96 285 return $this->objectHandler;
97 286 }
98 287
99 - public function getUserHandler(): UserHandler
288 + /**
289 + * @return UserHandler
290 + */
291 + public function getUserHandler()
100 292 {
101 293 return $this->userHandler;
102 294 }
103 295
104 - public function getUserGroupHandler(): UserGroupHandler
296 + public function getUserGroupHandler()
105 297 {
106 298 return $this->userGroupHandler;
107 299 }
108 300
109 - public function getAccessHandler(): AccessHandler
301 + /**
302 + * @return AccessHandler
303 + */
304 + public function getAccessHandler()
110 305 {
111 306 return $this->accessHandler;
112 307 }
113 308
114 - public function getFileHandler(): FileHandler
309 + /**
310 + * @return FileHandler
311 + */
312 + public function getFileHandler()
115 313 {
116 314 return $this->fileHandler;
117 315 }
118 316
119 - public function getSetupHandler(): SetupHandler
317 + /**
318 + * @return SetupHandler
319 + */
320 + public function getSetupHandler()
120 321 {
121 322 return $this->setupHandler;
122 323 }
123 324
124 - public function getUserGroupFactory(): UserGroupFactory
325 + /**
326 + * @return UserGroupFactory
327 + */
328 + public function getUserGroupFactory()
125 329 {
126 330 return $this->userGroupFactory;
127 331 }
128 332
129 - public function getObjectMembershipHandlerFactory(): ObjectMembershipHandlerFactory
333 + /**
334 + * @return ObjectMembershipHandlerFactory
335 + */
336 + public function getObjectMembershipHandlerFactory()
130 337 {
131 338 return $this->membershipHandlerFactory;
132 339 }
133 340
134 - public function getControllerFactory(): ControllerFactory
341 + /**
342 + * @return ControllerFactory
343 + */
344 + public function getControllerFactory()
135 345 {
136 346 return $this->controllerFactory;
137 347 }
138 348
139 - public function getWidgetFactory(): WidgetFactory
349 + /**
350 + * @return WidgetFactory
351 + */
352 + public function getWidgetFactory()
140 353 {
141 354 return $this->widgetFactory;
142 355 }
143 356
144 - public function getCacheProviderFactory(): CacheProviderFactory
357 + /**
358 + * @return CacheProviderFactory
359 + */
360 + public function getCacheProviderFactory()
145 361 {
146 362 return $this->cacheProviderFactory;
147 363 }
148 364
149 - public function getConfigFactory(): ConfigFactory
365 + /**
366 + * @return ConfigFactory
367 + */
368 + public function getConfigFactory()
150 369 {
151 370 return $this->configFactory;
152 371 }
153 372
154 - public function getConfigParameterFactory(): ConfigParameterFactory
373 + /**
374 + * @return ConfigParameterFactory
375 + */
376 + public function getConfigParameterFactory()
155 377 {
156 378 return $this->configParameterFactory;
157 379 }
158 380
159 - public function getFileProtectionFactory(): FileProtectionFactory
381 + /**
382 + * @return FileProtectionFactory
383 + */
384 + public function getFileProtectionFactory()
160 385 {
161 386 return $this->fileProtectionFactory;
162 387 }
163 388
164 - public function getFileObjectFactory(): FileObjectFactory
389 + /**
390 + * @return FileObjectFactory
391 + */
392 + public function getFileObjectFactory()
165 393 {
166 394 return $this->fileObjectFactory;
167 395 }
168 396
@@ -168,16 +396,16 @@
168 396
169 397 /**
170 398 * Resister the administration menu.
171 399 */
172 - public function registerAdminMenu(): void
400 + public function registerAdminMenu()
173 401 {
174 402 if ($this->userHandler->checkUserAccess() === true) {
175 403 //TODO
176 404 /**
177 405 * --- BOF ---
178 - * Not the best way to handle full user access. Capabilities seem
179 - * to be the right way, but it is way challenging.
406 + * Not the best way to handle full user access. Capabilities seems
407 + * to be the right way, but it is way difficult.
180 408 */
181 409 //Admin main menu
182 410 $this->wordpress->addMenuPage(
183 411 'User Access Manager',
@@ -236,8 +464,17 @@
236 464 */
237 465 }
238 466 }
239 467
468 + /**
469 + * Adds the backend filters.
470 + *
471 + * @param DynamicGroupsController $dynamicGroupController
472 + * @param PostObjectController $postObjectController
473 + * @param TermObjectController $termObjectController
474 + * @param UserObjectController $userObjectController
475 + * @param array $taxonomies
476 + */
240 477 private function addAdminActions(
241 478 DynamicGroupsController $dynamicGroupController,
242 479 PostObjectController $postObjectController,
243 480 TermObjectController $termObjectController,
@@ -242,9 +479,9 @@
242 479 PostObjectController $postObjectController,
243 480 TermObjectController $termObjectController,
244 481 UserObjectController $userObjectController,
245 482 array $taxonomies
246 - ): void {
483 + ) {
247 484 $this->wordpress->addAction(
248 485 'manage_posts_custom_column',
249 486 [$postObjectController, 'addPostColumn'],
250 487 10,
@@ -312,14 +549,22 @@
312 549 [$dynamicGroupController, 'getDynamicGroupsForAjax']
313 550 );
314 551 }
315 552
553 + /**
554 + * Adds the admin filters.
555 + *
556 + * @param PostObjectController $postObjectController
557 + * @param TermObjectController $termObjectController
558 + * @param UserObjectController $userObjectController
559 + * @param array $taxonomies
560 + */
316 561 private function addAdminFilters(
317 562 PostObjectController $postObjectController,
318 563 TermObjectController $termObjectController,
319 564 UserObjectController $userObjectController,
320 565 array $taxonomies
321 - ): void {
566 + ) {
322 567 //The filter we use instead of add|edit_attachment action, reason see top
323 568 $this->wordpress->addFilter('attachment_fields_to_save', [$postObjectController, 'saveAttachmentData']);
324 569
325 570 $this->wordpress->addFilter('manage_posts_columns', [$postObjectController, 'addPostColumnsHeader']);
@@ -324,9 +569,9 @@
324 569
325 570 $this->wordpress->addFilter('manage_posts_columns', [$postObjectController, 'addPostColumnsHeader']);
326 571 $this->wordpress->addFilter('manage_pages_columns', [$postObjectController, 'addPostColumnsHeader']);
327 572
328 - $this->wordpress->addFilter('manage_users_columns', [$userObjectController, 'addUserColumnsHeader']);
573 + $this->wordpress->addFilter('manage_users_columns', [$userObjectController, 'addUserColumnsHeader'], 10);
329 574 $this->wordpress->addFilter(
330 575 'manage_users_custom_column',
331 576 [$userObjectController, 'addUserColumn'],
332 577 10,
@@ -344,9 +589,14 @@
344 589 $this->wordpress->addFilter('manage_media_columns', [$postObjectController, 'addPostColumnsHeader']);
345 590 }
346 591 }
347 592
348 - private function addAdminMetaBoxes(PostObjectController $postObjectController): void
593 + /**
594 + * Adds the admin meta boxes.
595 + *
596 + * @param PostObjectController $postObjectController
597 + */
598 + private function addAdminMetaBoxes(PostObjectController $postObjectController)
349 599 {
350 600 $postTypes = $this->objectHandler->getPostTypes();
351 601
352 602 foreach ($postTypes as $postType) {
@@ -365,11 +615,11 @@
365 615 }
366 616 }
367 617
368 618 /**
369 - * @throws UserGroup\UserGroupTypeException
619 + * Register the admin actions and filters
370 620 */
371 - public function registerAdminActionsAndFilters(): void
621 + public function registerAdminActionsAndFilters()
372 622 {
373 623 $backendController = $this->controllerFactory->createBackendController();
374 624 $this->wordpress->addAction('admin_enqueue_scripts', [$backendController, 'enqueueStylesAndScripts']);
375 625 $this->wordpress->addAction('wp_dashboard_setup', [$backendController, 'setupAdminDashboard']);
@@ -420,9 +670,12 @@
420 670
421 671 $objectController->checkRightsToEditContent();
422 672 }
423 673
424 - public function addActionsAndFilters(): void
674 + /**
675 + * Adds the actions and filers.
676 + */
677 + public function addActionsAndFilters()
425 678 {
426 679 //Actions
427 680 $this->wordpress->addAction('admin_menu', [$this, 'registerAdminMenu']);
428 681 $this->wordpress->addAction('admin_init', [$this, 'registerAdminActionsAndFilters']);
@@ -436,24 +689,9 @@
436 689
437 690 $this->wordpress->addAction('wp_enqueue_scripts', [$frontendController, 'enqueueStylesAndScripts']);
438 691 $this->wordpress->addFilter('get_ancestors', [$frontendController, 'showAncestors'], 20, 4);
439 692 $this->wordpress->addFilter('wpseo_sitemap_entry', [$frontendController, 'getWpSeoUrl'], 1, 3);
440 - $this->wordpress->addFilter(
441 - 'elementor/frontend/builder_content_data',
442 - function ($data, $postId) use ($frontendController) {
443 - if ($this->wordpress->getQueriedObjectId() === $postId) {
444 - $this->wordpress->addAction(
445 - 'elementor/frontend/the_content',
446 - [$frontendController, 'getElementorContent']
447 - );
448 - }
449 693
450 - return $data;
451 - },
452 - 10,
453 - 2
454 - );
455 -
456 694 // Post controller
457 695 $frontendPostController = $this->controllerFactory->createFrontendPostController();
458 696
459 697 $this->wordpress->addFilter('posts_pre_query', [$frontendPostController, 'postsPreQuery'], 10, 2);
@@ -468,31 +706,8 @@
468 706 $this->wordpress->addFilter('edit_post_link', [$frontendPostController, 'showEditLink'], 10, 2);
469 707 $this->wordpress->addFilter('parse_query', [$frontendPostController, 'parseQuery']);
470 708 $this->wordpress->addFilter('getarchives_where', [$frontendPostController, 'showPostSql']);
471 709 $this->wordpress->addFilter('wp_count_posts', [$frontendPostController, 'showPostCount'], 10, 3);
472 -
473 - $this->wordpress->addAction('rest_api_init', function () use ($frontendPostController) {
474 - //Runs first, so that no access check caches the context before the guard.
475 - $this->wordpress->addFilter(
476 - 'rest_pre_dispatch',
477 - [$frontendPostController, 'restrictRestRequest'],
478 - 1,
479 - 3
480 - );
481 -
482 - foreach ((array) $this->objectHandler->getPostTypes() as $postType) {
483 - $this->wordpress->addFilter(
484 - "rest_prepare_$postType",
485 - [$frontendPostController, 'restrictRestResponse'],
486 - 10,
487 - 3
488 - );
489 - $this->wordpress->addFilter(
490 - "rest_{$postType}_query",
491 - [$frontendPostController, 'excludeRestrictedPostsFromRestQuery']
492 - );
493 - }
494 - });
495 710
496 711 // Short code controller
497 712 $frontendShortCodeController = $this->controllerFactory->createFrontendShortCodeController();
498 713