Skip to content

Instantly share code, notes, and snippets.

@sepiariver
Created February 6, 2017 00:00
Show Gist options
  • Save sepiariver/a1e693eaf1ecdae12528e94a935e864f to your computer and use it in GitHub Desktop.
Save sepiariver/a1e693eaf1ecdae12528e94a935e864f to your computer and use it in GitHub Desktop.
MODX Client Preview Plugin
<?php
if ($modx->context->get('key') === 'mgr') return;
$key = $modx->getOption('key', $scriptProperties, 'my-secret-key');
$val = $modx->getOption('val', $scriptProperties, 'my-secret-value');
switch ($modx->event->name) {
case 'OnHandleRequest':
if (!$modx->getOption('site_status')) {
if ($_GET[$key] === $val) {
$modx->config['site_status'] = 1;
} else {
$modx->config['site_status'] = 0;
}
}
break;
case 'OnLoadWebDocument':
case 'OnLoadWebPageCache':
if (!$modx->getOption('site_status')) {
if ($_GET[$key] === $val) {
if ($modx->resource instanceof modResource) $modx->resource->set('cacheable', false);
}
}
break;
default:
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment