We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12958
    • 9 Posts
    Hi Bob,
    thanks a lot. I added the code and a ")" at the end of the first line resulting in this:
       if ($resource->get('published') == false || $resource->get('deleted'))
    {
        $modx->sendErrorPage();
    }
    


    But I now get this error on every pageload of our website:

    Fatal error: Call to a member function get() on a non-object in /core/cache/elements/modplugin/8.include.cache.php on line 37
    
    Fatal error: Undefined class constant 'LOG_LEVEL_ERROR' in /core/model/modx/error/moderrorhandler.class.php on line 108


    Is there anything what should be added to avoid this error?
      • 3749
      • 24,544 Posts
      Sorry, I didn’t notice that the plugin was using $doc instead of $resource.

      It should be this:

         if ($doc->get('published') == false || $doc->get('deleted')) {
          $modx->sendErrorPage();
      }
      


        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
        • 12958
        • 9 Posts
        It works. But now even the Administrator is not able to watch unpublished pages. Do you have any idea what could be the reason for this strange behavior when activating the plugin?

        Many thanks
        Inka
          • 3749
          • 24,544 Posts
          I don’t, but try this:
             if ($doc->get('published') == false || $doc->get('deleted')) {
              If (! $modx->user->hasPermission('view_unpublished') ){
                  $modx->sendErrorPage();
              }
          }
          



            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
            • 12958
            • 9 Posts
            Hi Bob,
            thanks a lot. Just one thing: There seems to be a little mistake in this line:
            if (! $modx->user->hasPermission('view_unpublished')) {

            resulting in this error

            Call to undefined method modUser_mysql::hasPermission()

            Is there anything I still have to adapt?
              • 3749
              • 24,544 Posts
              Quote from: Inka27 at May 22, 2011, 08:49 PM

              Hi Bob,
              thanks a lot. Just one thing: There seems to be a little mistake in this line:
              if (! $modx->user->hasPermission('view_unpublished')) {

              resulting in this error

              Call to undefined method modUser_mysql::hasPermission()

              Is there anything I still have to adapt?

              Oops again. I posted that from my phone when I was half-awake. Try this instead:

              if (! $modx->hasPermission('view_unpublished')) {

                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
                • 12958
                • 9 Posts
                Thank you very much, Bob, you helped us a lot.
                With this solution everything works very well now!!!

                One last question: do you think that this error could be considered as a bug
                and therefore should be reported - or is it rather an individual problem
                which only occurs within our website?

                Again: Thanks a lot, we appreciate your help very much!

                Inka
                  • 3749
                  • 24,544 Posts
                  I would say it’s a bug, but a bug in the plugin rather than MODX. You should report it to the author of the plugin, if possible.
                    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