We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    What’s it doing or not doing?

    Are you sure you checked the OnPageUnauthorized checkbox in the plugin’s system events tab?

    Check the plugin to make sure there’s no typos or extra <?php tags or any other PHP errors like that; an error in the plugin will most likely just skip it and send you to your default unauthorized page.

    Are you sure you have the template IDs correct? The pages you want to use as unauthorized pages exist, are not themselves protected and are published?

    To debug, you can echo various values followed by exit() to see what is happening.
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 14536
      • 22 Posts
      I have OnPageUnauthorized checked... and here is the entirety of my code:
      <?
      $rs = $modx->db->select('template', $modx->getFullTableName('site_content'), 'id = ' . $modx->documentIdentifier);
      $tpl = $modx->db->getValue($rs);
      if($tpl == 3) {
          $modx->config['unauthorized_page'] = 7; 
      }
      ?>


      The default login page is 5, and that is the one that keeps on being the destination. I tried throwing
      echo $tpl;
      exit();
      

      in there, but that doesn’t even show. It seems almost as though the plugin isn’t doing anything? Or perhaps my exit isn’t done correctly?
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Try getting rid of the <? and ?> tags; in the first place you should never use short open tags (<? as opposed to <?php).
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 14536
          • 22 Posts
          Thanks, that was perfect! Any idea why you need to include the open tags in snippets but not plugins?
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            With snippets the tags are included in the source automatically in the form textarea field as a convenience, to assist with syntax coloring editors. The code is passed as a parameter to the eval() function, so the tags actually don’t exist in the database.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 14536
              • 22 Posts
              Hm. I guess that makes sense? I just assumed it was a standard across all resources. Thanks.