I'm not sure what the appropriate event is (OnHandleRequest?), since if site_status is off, your plugin may not execute. You might have to put the code in index.php. I'd experiment with this before bothering with the code.
Even if it works, though, there's a problem: once you've set the setting, it will remain on for visitors who come later. I can't think of an easy way to turn it off when the visitor leaves. If you want it always to be off, except when the preview is in the URL, this might work:
$setting = $modx->getObject('modContextSetting', array('context_key' => 'ContextName', 'key' => 'site_status'));
if (! $setting) {
$modx->log(modX::LOG_LEVEL_ERROR, 'Plugin could not get Setting');
return;
}
if (isset($_GET['preview']) && $_GET['preview'] == 1) {
$setting->set('value', '1');
} else {
$setting->set('value', '0');
}
$setting->save();
return;