Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Allow users to edit their profiles?

In profile members can click the preferences button to modify their preferences. Which is great but they can't edit the fields that we added through Profile Extender. However if they modify the url to their profile : https://site.com/forums/profile/edit/Username they can get to the edit screen where they can edit the profile extender fields.

Is there a way I can change that preferences button so that they go to the edit screen instead of the default preferences settings page? Or is there a way that I can add a link to the edit profile page and show it only if the profile page belongs to the logged in user?

«1

Comments

  • Apparently they just need to go to the following link: https://site.com/forums/profile/edit

    Surely there must be a way to display this on their profile if the user browsing is the owner of the profile?

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    They should have a memodule with links to their profile and to edit, you can also add an extra link on the menu for that if it is not visible enough for you.

    there are plugins to add more links to the menu

  • I don't see anything with that menu item. I modified the "me" module to point to edit rather than preferences but that only works for non-mobile versions.

    Hmmm but if I add a link to the menu will others see it? Or is that the user menu?

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    the edit profile link uses permissions to edit and also requires that users be signed in to show. If you add the link to the menu without permissions, it will always show, but only to logged in users.

    Not sure what theme you are using, but if it's outdated it may not have those links ..

  • Moddified default embed theme

  • Oh I used your addon addmenuitem. That works.

  • R_JR_J Ex-Fanboy Munich Admin

    That's really strange and you should try to solve the problem instead of finding ways to live with it.

    The code which determins if a user sees "Preferences" or "Edit Profile" link looks like that:

        if (hasEditProfile(Gdn::session()->UserID)) {
            echo wrap(Anchor(sprite('SpEditProfile').' '.t('Edit Profile'), 'profile/edit', 'EditProfileLink'), 'li', array('class' => 'EditProfileWrap link-editprofile'));
        } else {
            echo wrap(Anchor(sprite('SpEditProfile').' '.t('Preferences'), 'profile/preferences', 'EditProfileLink'), 'li', array('class' => 'EditProfileWrap link-preferences'));
        }
    

    hasEditProfile is a helper function which checks if the user has the appropriate rights to change his profile. The most interesting lines in that functions are the following:

            $result = checkPermission('Garden.Profiles.Edit') && c('Garden.UserAccount.AllowEdit');
    
            $result &= (
                c('Garden.Profile.Titles') ||
                c('Garden.Profile.Locations', false) ||
                c('Garden.Registration.Method') != 'Connect'
            );
    
            return $result;
    

    That means that your users will see the "Edit Profile" link whenever:
    Their user role has the Garden\Profiles\Edit permission checked (also check the Garden\Profiles\View permission) AND in the config there is a line $Configuration['Garden']['UserAccount']['AllowEdit'] = true;

    AND

    Either of the following is true:
    a) You have a line $Configuration['Garden']['Profile']['Titles'] = true; in the config
    OR
    b) You have a line $Configuration['Garden']['Profile']['Locations'] = true; in the config
    OR
    c) Your registration method is not "Connect"

  • Thanks R_J I will dig into it and post my findings here. I am on a family vacation for the 4th so I will need to find time here and there to look.

  • R_J I am digging into this finally. One thing I am not certain of is where to find the code that you reference above? Like which files are they located in.

  • The first bit of code you listed with the profile/edit and profile/preferences links I found at: /applications/dashboard/views/modules/me.php

    In that file I find:
    if (hasEditProfile(Gdn::session()->UserID)) { echo wrap(Anchor(sprite('SpEditProfile').' '.t('Edit Profile'), 'profile/edit', 'EditProfileLink'), 'li', array('class' => 'EditProfileWrap link-editprofile')); } else { echo wrap(Anchor(sprite('SpEditProfile').' '.t('Preferences'), 'profile/preferences', 'EditProfileLink'), 'li', array('class' => 'EditProfileWrap link-preferences')); }

    But I don't know where to find the helperfunction file that contains hasEditProfile

  • Ummm my registration method is connect. I thought it had to be that for SSO to work?

  • R_JR_J Ex-Fanboy Munich Admin

    Correct. But if there is a SSO solution, you have to have one "master" and it appears to me that this is/has to be/should be Wordpress. So I would say that the correct way to do things like that would be to create additional fields in Wordpress, create that same fields in Vanilla, but for editing the fields users would have to go to their "master" profile.

    As a user I would find it confusing to have to edit some fields in my forum profile and others in the cms profile.

  • R_JR_J Ex-Fanboy Munich Admin

    But I would agree that having the Vanilla notification preferenes available in the wordpress profile settings would be very sexy...

  • Ummm R_J was your last two responses to my problem?

  • R_JR_J Ex-Fanboy Munich Admin

    At least I thought so, yes =)

    Your problem is that your users cannot change the fields that have been added with the profile extender, nor?

    I think, they shouldn't edit it. There is a function which checks if your registration method is "connect" and if that is true, your users shouldn't be allowed to edit their profile.

    As a result, they should edit the original profile, which is the Wordpress profile. In order to be able to sync fields available in the Wordpress profile, you have to create those fields with the profile extender in Vanilla.

    The last sentence is assumption, all the rest appears to be obvious to me

  • MikeOlsonMikeOlson
    edited July 2017

    Oh ok I see where you were going now.

    We don't use the wordpress profile for our users. I disable to WP top bar for them because it was just too confusing for a lot of our users. (we are an older forum group)

    I believe this connect registration thing is also why I had to create the role in wordpress when I was having problems assigning people that role in vanilla. Now I just assign the role to them in wordpress and that seems to be fine. Anyways that is a different subject but I think it helps me understand why this profile issue is what it is.

    But I would like users to be able to edit their profile extended field... and you are probably going to eyeroll me bigtime because of this but here goes.....

    The profile extended field allows users to set a field to enable or disable the viewing of discussions from a category we have called Sensitive Topics. I realize I could have just had people put into different groups but people in our forum switch between wanting to view those types of discussions on the fly and then revert back to not wanting to view them. I know it is sort of a crazy thing but our forum users really enjoy it.

    I modified the helperfunctions file in discussions (under my theme) as the following to check the value of the extended profile field and to suppress the discussion from being displayed if the elected to not view those types of discussions. It is just an if statement wrapped around the writeDiscussion function:

    if (!function_exists('WriteDiscussion')) :
        /**
         *
         *
         * @param $Discussion
         * @param $Sender
         * @param $Session
         */
    $disable_sensitive;
    $disable_sensitive = "Disable";
     if ($Session->UserID) {
    $disable_sensitive = "Enable";
    $thisID = $Session->UserID;
    $result = Gdn::sql()
       ->select('value')
       ->from('UserMeta')
       ->where('UserID', $thisID)
       ->where('Name','Profile.DisableSensitiveTopicsDiscussion')
       ->get();
        foreach($result as $row) {
            $disable_sensitive = $row->value;
        }
     }
    
    global $disable_this;
    $disable_this = $disable_sensitive;
    //print $disable_sensitive; 
    
        function writeDiscussion($Discussion, &$Sender, &$Session) {
            global $disable_this;       
    //print "<br />".$Discussion->Category." - ".$disable_this."<br />" ;
     if($Discussion->Category != 'Sensitive Topics' Or $disable_this=='Enable' ){
            $CssClass = CssClass($Discussion);
            $DiscussionUrl = $Discussion->Url;
            $Category = CategoryModel::categories($Discussion->CategoryID);
    
            if ($Session->UserID) {
                $DiscussionUrl .= '#latest';
            }
            $Sender->EventArguments['DiscussionUrl'] = &$DiscussionUrl;
            $Sender->EventArguments['Discussion'] = &$Discussion;
            $Sender->EventArguments['CssClass'] = &$CssClass;
    
            $First = UserBuilder($Discussion, 'First');
            $Last = UserBuilder($Discussion, 'Last');
            $Sender->EventArguments['FirstUser'] = &$First;
            $Sender->EventArguments['LastUser'] = &$Last;
    
            $Sender->fireEvent('BeforeDiscussionName');
    
            $DiscussionName = $Discussion->Name;
            if ($DiscussionName == '') {
                $DiscussionName = t('Blank Discussion Topic');
            }
            $Sender->EventArguments['DiscussionName'] = &$DiscussionName;
    
            static $FirstDiscussion = true;
            if (!$FirstDiscussion) {
                $Sender->fireEvent('BetweenDiscussion');
            } else {
                $FirstDiscussion = false;
            }
    
            $Discussion->CountPages = ceil($Discussion->CountComments / $Sender->CountCommentsPerPage);
            ?>
            <li id="Discussion_<?php echo $Discussion->DiscussionID; ?>" class="<?php echo $CssClass; ?>">
                <?php
                if (!property_exists($Sender, 'CanEditDiscussions')) {
                    $Sender->CanEditDiscussions = val('PermsDiscussionsEdit', CategoryModel::categories($Discussion->CategoryID)) && c('Vanilla.AdminCheckboxes.Use');
                }
                $Sender->fireEvent('BeforeDiscussionContent');
                ?>
                <span class="Options">
          <?php
          echo optionsList($Discussion);
          echo bookmarkButton($Discussion);
          ?>
       </span>
    
                <div class="ItemContent Discussion">
                    <div class="Title">
                    <span class="colorBar">
                        <?php
                echo adminCheck($Discussion, array('', ' ')).anchor($DiscussionName, $DiscussionUrl);
                        $Sender->fireEvent('AfterDiscussionTitle');
                        ?>
                    </span>
                    </div>
                    <div class="Meta Meta-Discussion">
                        <?php
                        writeTags($Discussion);
                        ?>
                        <span class="MItem MCount ViewCount"><?php
                            printf(pluralTranslate($Discussion->CountViews,
                                '%s view html', '%s views html', t('%s view'), t('%s views')),
                                bigPlural($Discussion->CountViews, '%s view'));
                            ?></span>
             <span class="MItem MCount CommentCount"><?php
                 printf(pluralTranslate($Discussion->CountComments,
                     '%s comment html', '%s comments html', t('%s comment'), t('%s comments')),
                     bigPlural($Discussion->CountComments, '%s comment'));
                 ?></span>
             <span class="MItem MCount DiscussionScore Hidden"><?php
                 $Score = $Discussion->Score;
                 if ($Score == '') $Score = 0;
                 printf(plural($Score,
                     '%s point', '%s points',
                     bigPlural($Score, '%s point')));
                 ?></span>
                        <?php
                        echo newComments($Discussion);
    
                        $Sender->fireEvent('AfterCountMeta');
    
                        if ($Discussion->LastCommentID != '') {
                            echo ' <span class="MItem LastCommentBy">'.sprintf(t('Most recent by %1$s'), userAnchor($Last)).'</span> ';
                            echo ' <span class="MItem LastCommentDate">'.Gdn_Format::date($Discussion->LastDate, 'html').'</span>';
                        } else {
                            echo ' <span class="MItem LastCommentBy">'.sprintf(t('Started by %1$s'), userAnchor($First)).'</span> ';
                            echo ' <span class="MItem LastCommentDate">'.Gdn_Format::date($Discussion->FirstDate, 'html');
                            if ($Source = val('Source', $Discussion)) {
                                echo ' '.sprintf(t('via %s'), t($Source.' Source', $Source));
                            }
                            echo '</span> ';
                        }
    
                        if ($Sender->data('_ShowCategoryLink', true) && c('Vanilla.Categories.Use') && $Category) {
                            echo wrap(
                                anchor(htmlspecialchars($Discussion->Category),
                                CategoryUrl($Discussion->CategoryUrlCode)),
                                'span',
                                array('class' => 'MItem Category '.$Category['CssClass'])
                            );
                        }
                        $Sender->fireEvent('DiscussionMeta');
                        ?>
                    </div>
                </div>
                <?php $Sender->fireEvent('AfterDiscussionContent'); ?>
            </li>
        <?php
        }
        }
    endif;
    
  • hmmm well the code formatting broke obviously.

  • R_JR_J Ex-Fanboy Munich Admin
    edited July 2017

    @MikeOlson said:

    But I would like users to be able to edit their profile extended field... and you are probably going to eyeroll me bigtime because of this but here goes.....

    The profile extended field allows users to set a field to enable or disable the viewing of discussions from a category we have called Sensitive Topics.

    Oh dear - if you just have asked...

    Look at that: https://open.vanillaforums.com/categories, hover over one of the categories and you will see a cog wheel which gives you a context menu with the option to "mute" a category.

    Do you still need your construct? ;)

  • R_JR_J Ex-Fanboy Munich Admin

    I have just checked it: in Vanilla 2.3 that feature works similar but it is called "hiding" categories.

  • R_JR_J Ex-Fanboy Munich Admin

    By the way: I fixed your code snippet copy. Enclose longer code blocks with ~~~ like that:

    ~~~
    your
    code
    here
    ~~~

Sign In or Register to comment.