Last active
January 12, 2026 19:46
-
-
Save matdave/bde6e54c00fcb472f6108a0d1ccb0bdc to your computer and use it in GitHub Desktop.
Cloud Edge userGroupWhitelist Plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin: userGroupWhitelist | |
| * Event: OnLoadWebDocument | |
| * @var modX $modx | |
| * | |
| */ | |
| if (empty($modx->version)) { | |
| $modx->getVersionData(); | |
| } | |
| if ($modx->version['version'] < 3) { | |
| $corePath = $modx->getOption( | |
| 'cloudedge.core_path', | |
| null, | |
| $modx->getOption('core_path', null, MODX_CORE_PATH) . 'components/cloudedge/' | |
| ); | |
| /** @var CloudEdge $cloudEdge */ | |
| $cloudEdge = $modx->getService( | |
| 'cloudedge', | |
| 'CloudEdge', | |
| $corePath . 'model/cloudedge/', | |
| [ | |
| 'core_path' => $corePath | |
| ] | |
| ); | |
| } else { | |
| $cloudEdge = $modx->services->get('cloudedge'); | |
| } | |
| // Replace user group with the one you want to whitelist | |
| if (!$modx->resource || !$modx->user || !$modx->user->isMember('PUT-USER-GROUP-HERE')) { | |
| return; | |
| } | |
| try { | |
| $whoami = (new \CloudEdge\Cloud\Whoami($modx))->get(); | |
| } catch (\Exception $e) { | |
| $whoami = ['error' => $e->getMessage()]; | |
| } | |
| if (!isset($whoami['error'])) { | |
| (new \CloudEdge\Cloud\Cookie($modx))->get(); | |
| } else { | |
| return; | |
| } | |
| $modx->resource->set('cacheable', false); | |
| $modx->regClientStartupHTMLBlock(' | |
| <script> | |
| const cloudEdge = { | |
| config: ' . json_encode($cloudEdge->options) . ', | |
| whoami: ' . json_encode($whoami) . ', | |
| auth: "' . $modx->user->getUserToken($modx->resource->context_key) . '" | |
| }; | |
| </script> | |
| '); | |
| $modx->regClientStartupScript($cloudEdge->getOption('jsUrl') . 'web/cloudedge.js'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment