We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 52064
    • 120 Posts
    how can I force using a plugin the context site_status = On?

    To show a preview of the site if the customer add ?preview=1 to the url

      FerX - Developer at Eracom s.r.l.
      • 3749
      • 24,544 Posts
      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;
      





        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 52064
        • 120 Posts
        thanks for the reply but I would not change the value in the database.
          FerX - Developer at Eracom s.r.l.
          • 3749
          • 24,544 Posts
          In that case, this might work:

          $modx->config['site_status'] = 1; // or '1'


          If that doesn't work, you might be able to rewrite the core/cache/context_settings/web/context.cache.php file, though I'm not sure whether that would persist for later users.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting