Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 2139

Administration Joomla! 3.x • Re: Restrict ability to edit-profile on front-end to specific user groups

$
0
0
Create a template override for the Profile view of Users. Go to Extensions - Templates - Templates - (for example) Protostar Details and files. Go to the tab Create Overrides and click com_users - profile from the column Components.

The override files are written into the folder templates/protostar/html/com_users/profile. Delete all the files except edit.php that needs to be customised. The following example has Author as the user group where members are allowed to change the password. Tested in Joomla 3.10.12.

Part 1 - insert the lines after the two lines loading the plugin language:

Code:

// Load user_profile plugin language$lang = JFactory::getLanguage();$lang->load('plg_user_profile', JPATH_ADMINISTRATOR);// mod allow only Author group to update password$author= 3;// user group id $user = JFactory::getUser();// current user$userId = $user->get('id');// user id$groups = JAccess::getGroupsByUser($userId); // user's user groups$allow = in_array($author, $groups);
Part 2 - find the lines from 'Iterate through the fields' and make the changes:

Code:

<?php // Iterate through the fields in the set and display them. ?><?php foreach ($fields as $field) : ?><?php // If the field is hidden, just display the input. ?><?php // display password only to allowed group ?><?php if (($field->hidden) OR (($field->fieldname === 'password1' OR $field->fieldname === 'password2') AND !$allow)) : ?><?php // echo $field->input; ?><?php else : ?>

Statistics: Posted by toivo — Fri Apr 19, 2024 7:58 am



Viewing all articles
Browse latest Browse all 2139

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>