This question has been answered by wiseguydigital. See the first response.
<?php
if ($modx->event->name == 'OnContextSave') {
$setting = $modx->newObject('modContextSetting');
$setting->set('context_key', 'my_new_context');
$setting->set('key', 'base_url');
$setting->set('value', '/');
$setting->set('xtype', 'textfield');
$setting->set('namespace', 'core');
$setting->set('area', 'Lexicon and Language');
$setting->save();
// Clear the cache:
$modx->cacheManager->refresh(array(
'context_settings' => array('contexts' => array('my_new_context'))
));
}
if ($modx == modSystemEvent::MODE_UPD) return;
Once you have them all set, you can add this at the top of the plugin so it will only act on new ones:
if ($modx == modSystemEvent::MODE_UPD) return;
Also, if OnContextSave is the only event the plugin is connected to, there's no need for the "if" statement at the top, since it will always be true.
