Updating Joomla User Custom Fields

pastvne

Bruce Decker
I can't seem to contribute to the wiki any longer but thought this might be useful for others:

In this example, I needed to create a list plug-in to update certain Joomla User Custom fields. Here's the code I developed to perform this task:


Code:
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
JLoader::import('joomla.application.component.model');
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_fields/models', 'FieldsModel');
$fieldModel = JModelLegacy::getInstance('Field', 'FieldsModel', array('ignore_request' => true));

#userId     = 605;             // set to your preferred Joomla user id
$fieldName  = "company-name";  // using the 'name' property of the cutomer fieldModel
$fieldValue = 'ACME, Inc.';    // assigning a value to the field
$result = csp_setCustomFieldByName($userId, $fieldName, $fieldValue, $fieldModel);

Function csp_setCustomFieldByName($userId, $fieldName, $fieldValue, $fieldModel){
 $customFields = FieldsHelper::getFields('com_users.user', $userId, true);
    foreach($customFields as $customField){
       if ($customField->name == $fieldName){
           $fieldModel->setFieldValue($customField->id, $userId, $fieldValue);
           return true;
       }
   }
return false;
}
 
Hmm, you should be able to edit the wiki. I just checked the permission settings.

I'll dig deeper, see if I can find the issue.

-- hugh
 
Thanks Hugh:
I just tried again and I think I may not understand how to properly login. If I go to forum (here) where I'm obviously logged in and choose the 'wiki' tab at the top of the forum, then I am taken here:

https://www.fabrikar.com/forums/index.php?wiki/index/

Where there is my picture and profile shown at the right and not a login button. But, if I scroll down to Developers > Common PHP Tasks where I thought my snip might be most relevant, my profile is no longer shown on the right and I'm asked to login. I notice that this part of the wiki is not secure (http) instead of https and I'm wondering if that's causes the authentication session token to be invalid?

Just spit ballin.
-BD
 
Is seems at least Chrome and Opera don't let you login on sites with http resp. kick you off after switching to http.
I've seen this, too, with http links.
So always make sure to have https set in your URL. Probably there are a lot of "hardcoded" http links inside the WIKI which then will show you as not logged in. As soon as https is added to the URL the profile is showing again (no new login necessary).
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top