We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1235
    • 2 Posts
    Hello Everyone.

    I would like to be able to allow users to specify a custom user profile fields. For example a twitter url in their profile input page in the modx manager.

    When creating a blog I can use code like this to display a users info:
    [[*createdby:userinfo=`fullname`]]
    

    I would like to be able to do something simple like
    [[*createdby:userinfo=`twitter`]]


    The basic idea is that a blog poster has a little summary about them below their blog post which will include a link to their website and a link to their twitter.

    Modx Version: Revolution 2.0.8
    Server: Linux

    I have tried playing with extended fields and have had no luck. I have also googled for about an hour and a half and have had no luck.
      • 44773
      • 4 Posts
      I just had this same issue and unfortunately found this post to be among the top google results even though it is quite old and unsolved. For others finding this page this is the solution I created.

      [[!getUserExtendedField? &id=`[[+createdby:userinfo=`id`]]` &field=`FIELDNAME`]]

      Then the contents of the snippet are:
      <?php
      $user = $modx->getObject('modUser',$id);
      $profile = $user->getOne('Profile');
      $data = $profile->get('extended');
      return (isset($data[$field])) ? $data[$field] : false ;


      Sorry for bumping a super old post but it is still ranking.
        • 3749
        • 24,544 Posts
        That's a great solution!

        If you had a lot of extended fields, another way to go would be to extend the modUserProfile object and add your extra fields to it.

        A complete solution for the OP's request would be a lot more complicated, since the idea (if I'm reading it right) was to let individual users select custom fields that other users might not have. The only way I can think of to do that would be a single placeholder and a snippet that replaced it with *all* the user's extended fields. You'd have to create a CMP or a front-end form that let users create and set their custom fields, and if some extra was using the extended fields for something, it would get even more complicated. I guess they could have a unique prefix for the field names.

        I have a hard time coming up with a practical use case for this feature. wink

          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
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          The MODx-provided user data placeholders don't work with extended fields? I.e. [[+modx.user.[[*createdby]]:userinfo=`twitter`]]
            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
            • 3749
            • 24,544 Posts
            It never occurred to me that they might. wink I haven't used an output filter in several years and I don't think there's a single one anywhere at Bob's Guides.

            I had to look, and I'd say no, just the profile, though it wouldn't be difficult to add them in (of course making it even slower):

            Here's the existing code:
            case 'userinfo':
                 /* Returns the requested user data (input: userid) */
                 if (!empty($output)) {
                      $key = (!empty($m_val)) ? $m_val : 'username';
                      $userInfo= false;
                      if ($user= $this->modx->getObjectGraph('modUser', '{"Profile":{}}', $output)) {
                          $userInfo= $user->get(array ('username', 'password'));
                          if ($user->getOne('Profile')) {
                              $userInfo= array_merge($userInfo, $user->Profile->toArray());
                          }
                      }
                      $output = $userInfo && isset($userInfo[$key]) ? $userInfo[$key] : null;
                 }
                 break;


            
            Here's my untested guess on the extended version:
            
            /* UserInfoPlus snippet */
                 /* Returns the requested user data (input: userid) */
                 if (!empty($output)) {
                      $key = (!empty($m_val)) ? $m_val : 'username';
                      $userInfo= false;
                      if ($user= $this->modx->getObjectGraph('modUser', '{"Profile":{}}', $output)) {
                          $userInfo= $user->get(array ('username', 'password'));
                          if ($user->getOne('Profile')) {
                              $profile = $user->Profile->toArray();
                              $extended = $user->Profile->get('extended');
                              $userInfo= array_merge($userInfo, $profile, $extended);
                          }
                      }
                      $output = $userInfo && isset($userInfo[$key]) ? $userInfo[$key] : null;
                 }
                 break;

              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
              • 50864
              • 8 Posts
              Прошли годы, но поскольку эта страница выдается гуглом, то дам простое решение. Это работает))
              [[*createdby:userinfo=`extended.twitter`]]

              ---------
              GTranslate:
              Years have passed, but since this page is issued by Google, I'll give a simple solution. It works))