We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28626
    • 87 Posts
    Hi I managed to set up members only pages and it seems to work fine. My site has 3 modules, one is for everyone, and two for registered members only. In wayfinder it shows a dropdown menu with the 3 modules next to eachother.

    | module1 | module2 | module 3 |


    Since setting up the members-only restriction it only shows one module in the dropdownmenu to the non-registered users, which makes sense since they are not allowed to access the 2 other modules.

    | module 1 |

    I want the menu including the two restricted modules to be visible and clickable but when a non-registered user tries to go to a page from the restricted menu he/she should be redirected to the registration page.

    How should I proceed?

    kind regards,

    Kristof
      • 3749
      • 24,544 Posts
      There’s probably a way to do it with Wayfinder, but you could also put a simple snippet at the top of pages (or in the template) that redirects not-logged-in users to the registration page. Something like this:

      [[!CheckStatus]]

      <?php
      /* CheckStatus snippet */
      if (! $modx->user->hasSessionContext('web') ) {
          $modx->sendRedirect($modx->makeUrl(##));
      }
      ?>

      Where ## is the ID of your registration page.

      AFAIK, you’d have to give anonymous users rights to the documents in order to have Wayfinder show them, though (or take the docs out of the resource group).

      If you have multiple front-end contexts, you’d do it this way:
      <?php
      /* CheckStatus snippet */
      $ctx = $modx->context->get('key')
      $isAuthenticated = $modx->user->hasSessionContext($ctx);
      if (! isAuthenticated) {
          $modx->sendRedirect($modx->makeUrl(##));
      }
      ?>

        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
        • 22295
        • 153 Posts
        AFAIK, you’d have to give anonymous users rights to the documents in order to have Wayfinder show them, though (or take the docs out of the resource group).

        ’load’ permission to anonymous
          • 28626
          • 87 Posts
          I already tried the first suggestion and that works great for the purpose of what I need it for.

          Thank you for your input guys