| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace UserAccessManager; |
| 6 |
|
| 7 |
use UserAccessManager\Access\AccessHandler; |
| 8 |
use UserAccessManager\Cache\Cache; |
| 9 |
use UserAccessManager\Cache\CacheProviderFactory; |
| 10 |
use UserAccessManager\Config\ConfigFactory; |
| 11 |
use UserAccessManager\Config\ConfigParameterFactory; |
| 12 |
use UserAccessManager\Config\MainConfig; |
| 13 |
use UserAccessManager\Controller\Backend\DynamicGroupsController; |
| 14 |
use UserAccessManager\Controller\Backend\PostObjectController; |
| 15 |
use UserAccessManager\Controller\Backend\TermObjectController; |
| 16 |
use UserAccessManager\Controller\Backend\UserObjectController; |
| 17 |
use UserAccessManager\Controller\ControllerFactory; |
| 18 |
use UserAccessManager\Database\Database; |
| 19 |
use UserAccessManager\File\FileHandler; |
| 20 |
use UserAccessManager\File\FileObjectFactory; |
| 21 |
use UserAccessManager\File\FileProtectionFactory; |
| 22 |
use UserAccessManager\Object\ObjectHandler; |
| 23 |
use UserAccessManager\ObjectMembership\ObjectMembershipHandlerFactory; |
| 24 |
use UserAccessManager\Setup\SetupHandler; |
| 25 |
use UserAccessManager\User\UserHandler; |
| 26 |
use UserAccessManager\UserGroup\UserGroupFactory; |
| 27 |
use UserAccessManager\UserGroup\UserGroupHandler; |
| 28 |
use UserAccessManager\Util\Util; |
| 29 |
use UserAccessManager\Widget\WidgetFactory; |
| 30 |
use UserAccessManager\Wrapper\Php; |
| 31 |
use UserAccessManager\Wrapper\Wordpress; |
| 32 |
|
| 33 |
class UserAccessManager |
| 34 |
{ |
| 35 |
public const VERSION = '2.3.15'; |
| 36 |
public const DB_VERSION = '1.6.2'; |
| 37 |
|
| 38 |
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 |
| 60 |
) { |
| 61 |
$this->cache->setActiveCacheProvider($this->config->getActiveCacheProvider()); |
| 62 |
} |
| 63 |
|
| 64 |
public function getPhp(): Php |
| 65 |
{ |
| 66 |
return $this->php; |
| 67 |
} |
| 68 |
|
| 69 |
public function getWordpress(): Wordpress |
| 70 |
{ |
| 71 |
return $this->wordpress; |
| 72 |
} |
| 73 |
|
| 74 |
public function getUtil(): Util |
| 75 |
{ |
| 76 |
return $this->util; |
| 77 |
} |
| 78 |
|
| 79 |
public function getCache(): Cache |
| 80 |
{ |
| 81 |
return $this->cache; |
| 82 |
} |
| 83 |
|
| 84 |
public function getConfig(): MainConfig |
| 85 |
{ |
| 86 |
return $this->config; |
| 87 |
} |
| 88 |
|
| 89 |
public function getDatabase(): Database |
| 90 |
{ |
| 91 |
return $this->database; |
| 92 |
} |
| 93 |
|
| 94 |
public function getObjectHandler(): ObjectHandler |
| 95 |
{ |
| 96 |
return $this->objectHandler; |
| 97 |
} |
| 98 |
|
| 99 |
public function getUserHandler(): UserHandler |
| 100 |
{ |
| 101 |
return $this->userHandler; |
| 102 |
} |
| 103 |
|
| 104 |
public function getUserGroupHandler(): UserGroupHandler |
| 105 |
{ |
| 106 |
return $this->userGroupHandler; |
| 107 |
} |
| 108 |
|
| 109 |
public function getAccessHandler(): AccessHandler |
| 110 |
{ |
| 111 |
return $this->accessHandler; |
| 112 |
} |
| 113 |
|
| 114 |
public function getFileHandler(): FileHandler |
| 115 |
{ |
| 116 |
return $this->fileHandler; |
| 117 |
} |
| 118 |
|
| 119 |
public function getSetupHandler(): SetupHandler |
| 120 |
{ |
| 121 |
return $this->setupHandler; |
| 122 |
} |
| 123 |
|
| 124 |
public function getUserGroupFactory(): UserGroupFactory |
| 125 |
{ |
| 126 |
return $this->userGroupFactory; |
| 127 |
} |
| 128 |
|
| 129 |
public function getObjectMembershipHandlerFactory(): ObjectMembershipHandlerFactory |
| 130 |
{ |
| 131 |
return $this->membershipHandlerFactory; |
| 132 |
} |
| 133 |
|
| 134 |
public function getControllerFactory(): ControllerFactory |
| 135 |
{ |
| 136 |
return $this->controllerFactory; |
| 137 |
} |
| 138 |
|
| 139 |
public function getWidgetFactory(): WidgetFactory |
| 140 |
{ |
| 141 |
return $this->widgetFactory; |
| 142 |
} |
| 143 |
|
| 144 |
public function getCacheProviderFactory(): CacheProviderFactory |
| 145 |
{ |
| 146 |
return $this->cacheProviderFactory; |
| 147 |
} |
| 148 |
|
| 149 |
public function getConfigFactory(): ConfigFactory |
| 150 |
{ |
| 151 |
return $this->configFactory; |
| 152 |
} |
| 153 |
|
| 154 |
public function getConfigParameterFactory(): ConfigParameterFactory |
| 155 |
{ |
| 156 |
return $this->configParameterFactory; |
| 157 |
} |
| 158 |
|
| 159 |
public function getFileProtectionFactory(): FileProtectionFactory |
| 160 |
{ |
| 161 |
return $this->fileProtectionFactory; |
| 162 |
} |
| 163 |
|
| 164 |
public function getFileObjectFactory(): FileObjectFactory |
| 165 |
{ |
| 166 |
return $this->fileObjectFactory; |
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 170 |
* Resister the administration menu. |
| 171 |
*/ |
| 172 |
public function registerAdminMenu(): void |
| 173 |
{ |
| 174 |
if ($this->userHandler->checkUserAccess() === true) { |
| 175 |
//TODO |
| 176 |
/** |
| 177 |
* --- BOF --- |
| 178 |
* Not the best way to handle full user access. Capabilities seem |
| 179 |
* to be the right way, but it is way challenging. |
| 180 |
*/ |
| 181 |
//Admin main menu |
| 182 |
$this->wordpress->addMenuPage( |
| 183 |
'User Access Manager', |
| 184 |
'UAM', |
| 185 |
'manage_options', |
| 186 |
'uam_user_group', |
| 187 |
null, |
| 188 |
'div' |
| 189 |
); |
| 190 |
|
| 191 |
//Admin sub menus |
| 192 |
$backendUserGroupController = $this->controllerFactory->createBackendUserGroupController(); |
| 193 |
$this->wordpress->addSubmenuPage( |
| 194 |
'uam_user_group', |
| 195 |
TXT_UAM_MANAGE_GROUP, |
| 196 |
TXT_UAM_MANAGE_GROUP, |
| 197 |
'read', |
| 198 |
'uam_user_group', |
| 199 |
[$backendUserGroupController, 'render'] |
| 200 |
); |
| 201 |
|
| 202 |
$backendSettingsController = $this->controllerFactory->createBackendSettingsController(); |
| 203 |
$this->wordpress->addSubmenuPage( |
| 204 |
'uam_user_group', |
| 205 |
TXT_UAM_SETTINGS, |
| 206 |
TXT_UAM_SETTINGS, |
| 207 |
'read', |
| 208 |
'uam_settings', |
| 209 |
[$backendSettingsController, 'render'] |
| 210 |
); |
| 211 |
|
| 212 |
$backendSetupController = $this->controllerFactory->createBackendSetupController(); |
| 213 |
$this->wordpress->addSubmenuPage( |
| 214 |
'uam_user_group', |
| 215 |
TXT_UAM_SETUP, |
| 216 |
TXT_UAM_SETUP, |
| 217 |
'read', |
| 218 |
'uam_setup', |
| 219 |
[$backendSetupController, 'render'] |
| 220 |
); |
| 221 |
|
| 222 |
$backendAboutController = $this->controllerFactory->createBackendAboutController(); |
| 223 |
$this->wordpress->addSubmenuPage( |
| 224 |
'uam_user_group', |
| 225 |
TXT_UAM_ABOUT, |
| 226 |
TXT_UAM_ABOUT, |
| 227 |
'read', |
| 228 |
'uam_about', |
| 229 |
[$backendAboutController, 'render'] |
| 230 |
); |
| 231 |
|
| 232 |
$this->wordpress->doAction('uam_add_sub_menu'); |
| 233 |
|
| 234 |
/** |
| 235 |
* --- EOF --- |
| 236 |
*/ |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
private function addAdminActions( |
| 241 |
DynamicGroupsController $dynamicGroupController, |
| 242 |
PostObjectController $postObjectController, |
| 243 |
TermObjectController $termObjectController, |
| 244 |
UserObjectController $userObjectController, |
| 245 |
array $taxonomies |
| 246 |
): void { |
| 247 |
$this->wordpress->addAction( |
| 248 |
'manage_posts_custom_column', |
| 249 |
[$postObjectController, 'addPostColumn'], |
| 250 |
10, |
| 251 |
2 |
| 252 |
); |
| 253 |
$this->wordpress->addAction( |
| 254 |
'manage_pages_custom_column', |
| 255 |
[$postObjectController, 'addPostColumn'], |
| 256 |
10, |
| 257 |
2 |
| 258 |
); |
| 259 |
$this->wordpress->addAction('save_post', [$postObjectController, 'savePostData']); |
| 260 |
$this->wordpress->addAction('add_attachment', [$postObjectController, 'addAttachment']); |
| 261 |
$this->wordpress->addAction('edit_user_profile', [$userObjectController, 'showUserProfile']); |
| 262 |
$this->wordpress->addAction('user_new_form', [$userObjectController, 'showUserProfile']); |
| 263 |
$this->wordpress->addAction('user_register', [$userObjectController, 'saveUserData']); |
| 264 |
$this->wordpress->addAction('profile_update', [$userObjectController, 'saveUserData']); |
| 265 |
|
| 266 |
$this->wordpress->addAction('bulk_edit_custom_box', [$postObjectController, 'addBulkAction']); |
| 267 |
$this->wordpress->addAction('create_term', [$termObjectController, 'saveTermData']); |
| 268 |
$this->wordpress->addAction('edit_term', [$termObjectController, 'saveTermData']); |
| 269 |
|
| 270 |
//Taxonomies |
| 271 |
foreach ($taxonomies as $taxonomy) { |
| 272 |
$this->wordpress->addAction( |
| 273 |
'manage_'.$taxonomy.'_custom_column', |
| 274 |
[$termObjectController, 'addTermColumn'], |
| 275 |
10, |
| 276 |
3 |
| 277 |
); |
| 278 |
$this->wordpress->addAction( |
| 279 |
$taxonomy.'_add_form_fields', |
| 280 |
[$termObjectController, 'showTermEditForm'] |
| 281 |
); |
| 282 |
$this->wordpress->addAction( |
| 283 |
$taxonomy.'_edit_form_fields', |
| 284 |
[$termObjectController, 'showTermEditForm'] |
| 285 |
); |
| 286 |
} |
| 287 |
|
| 288 |
if ($this->config->lockFile() === true) { |
| 289 |
$this->wordpress->addAction( |
| 290 |
'manage_media_custom_column', |
| 291 |
[$postObjectController, 'addPostColumn'], |
| 292 |
10, |
| 293 |
2 |
| 294 |
); |
| 295 |
$this->wordpress->addAction( |
| 296 |
'attachment_fields_to_edit', |
| 297 |
[$postObjectController, 'showMediaFile'], |
| 298 |
10, |
| 299 |
2 |
| 300 |
); |
| 301 |
$this->wordpress->addAction( |
| 302 |
'wp_ajax_save-attachment-compat', |
| 303 |
[$postObjectController, 'saveAjaxAttachmentData'], |
| 304 |
1, |
| 305 |
9 |
| 306 |
); |
| 307 |
} |
| 308 |
|
| 309 |
//Admin ajax actions |
| 310 |
$this->wordpress->addAction( |
| 311 |
'wp_ajax_uam-get-dynamic-group', |
| 312 |
[$dynamicGroupController, 'getDynamicGroupsForAjax'] |
| 313 |
); |
| 314 |
} |
| 315 |
|
| 316 |
private function addAdminFilters( |
| 317 |
PostObjectController $postObjectController, |
| 318 |
TermObjectController $termObjectController, |
| 319 |
UserObjectController $userObjectController, |
| 320 |
array $taxonomies |
| 321 |
): void { |
| 322 |
//The filter we use instead of add|edit_attachment action, reason see top |
| 323 |
$this->wordpress->addFilter('attachment_fields_to_save', [$postObjectController, 'saveAttachmentData']); |
| 324 |
|
| 325 |
$this->wordpress->addFilter('manage_posts_columns', [$postObjectController, 'addPostColumnsHeader']); |
| 326 |
$this->wordpress->addFilter('manage_pages_columns', [$postObjectController, 'addPostColumnsHeader']); |
| 327 |
|
| 328 |
$this->wordpress->addFilter('manage_users_columns', [$userObjectController, 'addUserColumnsHeader']); |
| 329 |
$this->wordpress->addFilter( |
| 330 |
'manage_users_custom_column', |
| 331 |
[$userObjectController, 'addUserColumn'], |
| 332 |
10, |
| 333 |
3 |
| 334 |
); |
| 335 |
|
| 336 |
foreach ($taxonomies as $taxonomy) { |
| 337 |
$this->wordpress->addFilter( |
| 338 |
'manage_edit-'.$taxonomy.'_columns', |
| 339 |
[$termObjectController, 'addTermColumnsHeader'] |
| 340 |
); |
| 341 |
} |
| 342 |
|
| 343 |
if ($this->config->lockFile() === true) { |
| 344 |
$this->wordpress->addFilter('manage_media_columns', [$postObjectController, 'addPostColumnsHeader']); |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
private function addAdminMetaBoxes(PostObjectController $postObjectController): void |
| 349 |
{ |
| 350 |
$postTypes = $this->objectHandler->getPostTypes(); |
| 351 |
|
| 352 |
foreach ($postTypes as $postType) { |
| 353 |
// there is no need for a meta box for attachments if files are locked |
| 354 |
if ($postType === ObjectHandler::ATTACHMENT_OBJECT_TYPE && $this->config->lockFile() !== true) { |
| 355 |
continue; |
| 356 |
} |
| 357 |
|
| 358 |
$this->wordpress->addMetaBox( |
| 359 |
'uam_post_access', |
| 360 |
TXT_UAM_COLUMN_ACCESS, |
| 361 |
[$postObjectController, 'editPostContent'], |
| 362 |
$postType, |
| 363 |
'side' |
| 364 |
); |
| 365 |
} |
| 366 |
} |
| 367 |
|
| 368 |
/** |
| 369 |
* @throws UserGroup\UserGroupTypeException |
| 370 |
*/ |
| 371 |
public function registerAdminActionsAndFilters(): void |
| 372 |
{ |
| 373 |
$backendController = $this->controllerFactory->createBackendController(); |
| 374 |
$this->wordpress->addAction('admin_enqueue_scripts', [$backendController, 'enqueueStylesAndScripts']); |
| 375 |
$this->wordpress->addAction('wp_dashboard_setup', [$backendController, 'setupAdminDashboard']); |
| 376 |
$this->wordpress->addAction('admin_notices', [$backendController, 'showAdminNotice']); |
| 377 |
|
| 378 |
$taxonomies = $this->objectHandler->getTaxonomies(); |
| 379 |
$taxonomy = $backendController->getRequestParameter('taxonomy'); |
| 380 |
|
| 381 |
if ($taxonomy !== null) { |
| 382 |
$taxonomies[$taxonomy] = $taxonomy; |
| 383 |
} |
| 384 |
|
| 385 |
$objectController = $this->controllerFactory->createBackendObjectController(); |
| 386 |
$postObjectController = $this->controllerFactory->createBackendPostObjectController(); |
| 387 |
$termObjectController = $this->controllerFactory->createBackendTermObjectController(); |
| 388 |
$userObjectController = $this->controllerFactory->createBackendUserObjectController(); |
| 389 |
$dynamicGroupController = $this->controllerFactory->createBackendDynamicGroupsController(); |
| 390 |
|
| 391 |
if ($this->userHandler->checkUserAccess() === true |
| 392 |
|| $this->config->authorsCanAddPostsToGroups() === true |
| 393 |
) { |
| 394 |
//Admin actions |
| 395 |
$this->addAdminActions( |
| 396 |
$dynamicGroupController, |
| 397 |
$postObjectController, |
| 398 |
$termObjectController, |
| 399 |
$userObjectController, |
| 400 |
$taxonomies |
| 401 |
); |
| 402 |
|
| 403 |
//Admin filters |
| 404 |
$this->addAdminFilters( |
| 405 |
$postObjectController, |
| 406 |
$termObjectController, |
| 407 |
$userObjectController, |
| 408 |
$taxonomies |
| 409 |
); |
| 410 |
|
| 411 |
//Admin meta boxes |
| 412 |
$this->addAdminMetaBoxes($postObjectController); |
| 413 |
} |
| 414 |
|
| 415 |
//Clean up at deleting should always be done. |
| 416 |
$this->wordpress->addAction('delete_post', [$postObjectController, 'removePostData']); |
| 417 |
$this->wordpress->addAction('delete_attachment', [$postObjectController, 'removePostData']); |
| 418 |
$this->wordpress->addAction('delete_user', [$userObjectController, 'removeUserData']); |
| 419 |
$this->wordpress->addAction('delete_term', [$termObjectController, 'removeTermData']); |
| 420 |
|
| 421 |
$objectController->checkRightsToEditContent(); |
| 422 |
} |
| 423 |
|
| 424 |
public function addActionsAndFilters(): void |
| 425 |
{ |
| 426 |
//Actions |
| 427 |
$this->wordpress->addAction('admin_menu', [$this, 'registerAdminMenu']); |
| 428 |
$this->wordpress->addAction('admin_init', [$this, 'registerAdminActionsAndFilters']); |
| 429 |
$this->wordpress->addAction('registered_post_type', [$this->objectHandler, 'registeredPostType'], 10, 2); |
| 430 |
$this->wordpress->addAction('registered_taxonomy', [$this->objectHandler, 'registeredTaxonomy'], 10, 3); |
| 431 |
$this->wordpress->addAction('registered_post_type', [$this->config, 'flushConfigParameters']); |
| 432 |
$this->wordpress->addAction('registered_taxonomy', [$this->config, 'flushConfigParameters']); |
| 433 |
|
| 434 |
// General frontend controller |
| 435 |
$frontendController = $this->controllerFactory->createFrontendController(); |
| 436 |
|
| 437 |
$this->wordpress->addAction('wp_enqueue_scripts', [$frontendController, 'enqueueStylesAndScripts']); |
| 438 |
$this->wordpress->addFilter('get_ancestors', [$frontendController, 'showAncestors'], 20, 4); |
| 439 |
$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 |
|
| 450 |
return $data; |
| 451 |
}, |
| 452 |
10, |
| 453 |
2 |
| 454 |
); |
| 455 |
|
| 456 |
// Post controller |
| 457 |
$frontendPostController = $this->controllerFactory->createFrontendPostController(); |
| 458 |
|
| 459 |
$this->wordpress->addFilter('posts_pre_query', [$frontendPostController, 'postsPreQuery'], 10, 2); |
| 460 |
$this->wordpress->addFilter('the_posts', [$frontendPostController, 'showPosts'], 9); |
| 461 |
$this->wordpress->addFilter('get_attached_file', [$frontendPostController, 'getAttachedFile'], 10, 2); |
| 462 |
$this->wordpress->addFilter('posts_where_paged', [$frontendPostController, 'showPostSql']); |
| 463 |
$this->wordpress->addFilter('comments_array', [$frontendPostController, 'showComment']); |
| 464 |
$this->wordpress->addFilter('the_comments', [$frontendPostController, 'showComment']); |
| 465 |
$this->wordpress->addFilter('get_pages', [$frontendPostController, 'showPages'], 20); |
| 466 |
$this->wordpress->addFilter('get_next_post_where', [$frontendPostController, 'showNextPreviousPost']); |
| 467 |
$this->wordpress->addFilter('get_previous_post_where', [$frontendPostController, 'showNextPreviousPost']); |
| 468 |
$this->wordpress->addFilter('edit_post_link', [$frontendPostController, 'showEditLink'], 10, 2); |
| 469 |
$this->wordpress->addFilter('parse_query', [$frontendPostController, 'parseQuery']); |
| 470 |
$this->wordpress->addFilter('getarchives_where', [$frontendPostController, 'showPostSql']); |
| 471 |
$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 |
|
| 496 |
// Short code controller |
| 497 |
$frontendShortCodeController = $this->controllerFactory->createFrontendShortCodeController(); |
| 498 |
|
| 499 |
$this->wordpress->addShortCode('LOGIN_FORM', [$frontendShortCodeController, 'loginFormShortCode']); // Legacy |
| 500 |
$this->wordpress->addShortCode('uam_login_form', [$frontendShortCodeController, 'loginFormShortCode']); |
| 501 |
$this->wordpress->addShortCode('uam_public', [$frontendShortCodeController, 'publicShortCode']); |
| 502 |
$this->wordpress->addShortCode('uam_private', [$frontendShortCodeController, 'privateShortCode']); |
| 503 |
|
| 504 |
// Term controller |
| 505 |
$frontendTermController = $this->controllerFactory->createFrontendTermController(); |
| 506 |
|
| 507 |
$this->wordpress->addFilter('get_terms_args', [$frontendTermController, 'getTermArguments']); |
| 508 |
$this->wordpress->addFilter('get_terms', [$frontendTermController, 'showTerms'], 20); |
| 509 |
$this->wordpress->addFilter('get_term', [$frontendTermController, 'showTerm'], 20, 2); |
| 510 |
$this->wordpress->addFilter('wp_get_nav_menu_items', [$frontendTermController, 'showCustomMenu']); |
| 511 |
|
| 512 |
// Redirect controller |
| 513 |
$frontendRedirectController = $this->controllerFactory->createFrontendRedirectController(); |
| 514 |
|
| 515 |
$this->wordpress->addFilter('wp_get_attachment_thumb_url', [$frontendRedirectController, 'getFileUrl'], 10, 2); |
| 516 |
$this->wordpress->addFilter('wp_get_attachment_url', [$frontendRedirectController, 'getFileUrl'], 10, 2); |
| 517 |
$this->wordpress->addFilter('post_link', [$frontendRedirectController, 'cachePostLinks'], 10, 2); |
| 518 |
|
| 519 |
$getFile = $frontendController->getRequestParameter('uamgetfile'); |
| 520 |
|
| 521 |
if ($this->config->getRedirect() !== false || $getFile !== null) { |
| 522 |
$this->wordpress->addFilter('wp_headers', [$frontendRedirectController, 'redirect'], 10, 2); |
| 523 |
} |
| 524 |
|
| 525 |
$testXSendFile = $frontendController->getRequestParameter('testXSendFile'); |
| 526 |
|
| 527 |
if ($testXSendFile !== null) { |
| 528 |
$this->wordpress->addFilter('wp_headers', [$frontendRedirectController, 'testXSendFile'], 10, 2); |
| 529 |
} |
| 530 |
|
| 531 |
// Admin object controller |
| 532 |
$backendCacheController = $this->controllerFactory->createBackendCacheController(); |
| 533 |
|
| 534 |
$this->wordpress->addFilter('clean_term_cache', [$backendCacheController, 'invalidateTermCache']); |
| 535 |
$this->wordpress->addFilter('clean_object_term_cache', [$backendCacheController, 'invalidateTermCache']); |
| 536 |
$this->wordpress->addFilter('clean_post_cache', [$backendCacheController, 'invalidatePostCache']); |
| 537 |
$this->wordpress->addFilter('clean_attachment_cache', [$backendCacheController, 'invalidatePostCache']); |
| 538 |
|
| 539 |
// Widgets |
| 540 |
$this->wordpress->addAction('widgets_init', function () { |
| 541 |
$this->wordpress->registerWidget($this->widgetFactory->createLoginWidget()); |
| 542 |
}); |
| 543 |
} |
| 544 |
} |
| 545 |
|