We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • ManagersOnly
    A snippet based on Adam Crownoble’s LoginLogoutLink (8/3/2005) and MemberCheck by Ryan Thrash, Jason Coward (3/4/2007) .

    Purpose
    The purpose of ManagersOnly is to offer very light way to show/place content to/for Manager Users. This snippet doesn’t check group memberships, it will only check to see if the manager is logged in and return the contents of a chunk.

    Note: If you would like a snippet that also checks group membership try Susan Otwell’s modified MemberCheck, ManagerCheck.

    If logged in the manager user will see the chunk content where called. If not logged in no one else will see the links.

    Usage

    1. Place this text into a new snippet and name it ManagersOnly

    2. Create a Chunk with the contents for managers only such as links or text.

    3. Place snippet call into template or document. Where `chunkname` is the name of your chunk:

    [!ManagersOnly? &chunk=`chunkname`!]

    Important: Do not place the normal chunk call into your page or template as it will be publicly accessible.


    Parameters
    &chunk - Name of Chunk containing content to display [String] (REQUIRED)
    &debug - Turns on Debugging to see what the problem is [0|1] (REQUIRED) Default = 0

    Current Version: 0.1.1
    Last Update: 06-01-2008 (Usage info update. No change to actual snippet code)

    Note:

    Looking for people to see how it works on their stacks. Especially PHP5. Any simple suggestions are welcomed.

      Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. BlogTwitterLinkedInGitHub
      • 4310
      • 2,310 Posts
      What a clever little snippet!
      PHP Version 5.2.2 works fine.
      Can I just point out you don’t need to add the chunk to the page, only to the snippet call.

      Thanks

      David
        • 7231
        • 4,205 Posts
        This is nice. Thanks.
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don't know what it is.
          Do you, Mr. Jones? - [bob dylan]
        • Quote from: bunk58 at Jan 05, 2008, 09:04 PM

          What a clever little snippet!
          Thanks. I am learning more and more PHP and trying to extend some other snippets. This one enabled me to see how to get a template from a chunk. I want to add that to FDM so that it can have a default field set.

          Quote from: bunk58 at Jan 05, 2008, 09:04 PM

          Can I just point out you don’t need to add the chunk to the page, only to the snippet call.

          Thanks

          David
          Yes. I should mention that in the instructions. The chunk call should not be in the page call or it will be accessible to the public. It should only be in the snippet call.

          Quote from: dev_cw at Jan 05, 2008, 11:04 PM

          This is nice. Thanks.

          Thanks also.
            Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. BlogTwitterLinkedInGitHub
            • 33337
            • 3,975 Posts
            Nice snippet. smiley

            Thanks for sharing.
              Zaigham R - MODX Professional | Skype | Email | Twitter

              Digging the interwebs for #MODX gems and bringing it to you. modx.link
              • 3749
              • 24,544 Posts
              If I could make a suggestion . . .

              $outputchunk = $modx->getChunk($chunk);


              Should be the first line inside the if statement. Otherwise, you’re fetching the chunk every time the page is accessed whether there’s a manager user on or not. IOW:

              if($_SESSION['mgrValidated']){
              
                      $outputchunk = $modx->getChunk($chunk);
              
                      //Check to see if there is a chunk to output
                          if ($outputchunk){
                              return $outputchunk;
                          }
                          // If Debug is turned on, output error. (kind of overkill for a small snippet like this--did it for practice.)
                          elseif ($debug == '1'){
                              return 'The chunkname '.$chunk.' doesn\'t appear to be valid or exist.';
                          }
                  }   else {
                      //End the script
                      return false;
                  }
                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
              • Bob, you certainly may make the suggestion. I am hardly a programmer as I say here regularly. I do php to get stuff done. I always like to be told the better way to do things. I’ll check this out to ensure it works and repost the updated version. I may just add it to the repo since it works as expected.

                Cheers,

                Jay
                  Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. BlogTwitterLinkedInGitHub
                  • 7327
                  • 195 Posts
                  Hi,

                  Is the snippet that Bob posted above the actual snippet code, or it's just a part? I noticed there's no attachment in this thread.
                    • 48681
                    • 2 Posts
                    To every who finds the same snippet for MODX Revo:

                    <?php
                    if($modx->user->isAuthenticated('mgr')) {
                        return $html;
                    } else {
                        return false;
                    }
                    


                    Snippet using:
                    [[!ManagersOnly? &html=`<button>My hidden button</button>`]]