I'm pretty new to Joomla, so sorry if this sounds silly.
I am using Extra Field "Date of Birth" from UserProfile in this code:
jimport( 'joomla.user.helper' );
$user = JFactory::getUser();
$userId = $user->id;
$userProfile = JUserHelper::getProfile( $userId );
$dob = $userProfile->profile['dob'];
echo "dob = " . $dob ;
echo "authorise =" . $user->authorise('core.admin', 'com_component');
Although $dob
displays fine when logged in as a Super User, it won't show when logged in as a registered user.
So I'd like to display this field at a "basic non-administrator" level if it's possible.
Is there a way to do it? Or shall I temporarily change the User type to be able to access this field (I would obviously prefer not to...)?
Following the responses from mickmackusa and Sharky : Thank you so much for your answers. I'm pretty sure the registered user has a date set up, since it shows when turned into "Super User".
To help see better what's happening, I've changes the code a little :
jimport( 'joomla.user.helper' );
$user = JFactory::getUser();
echo "<br>--debug--";
echo "<br> id = " . $user->id ;
echo "<br> name = " . $user->name ;
echo "<br> username = " . $user->username ;
$isAdmin = $user->get('isRoot');
if ($isAdmin) {
echo '<br>You are an Administrator';
}
else {
echo '<br>You are not Administrator';
}
$userId = $user->id;
$userProfile = JUserHelper::getProfile( $userId );
$dob = $userProfile->profile['dob'];
echo "<br> dob = " . $dob ;
echo "<br> authorise =" . $user->authorise('core.admin', 'com_component');
echo "<br>var_dump = " . $userProfile; //var_dump(JUserHelper::getProfile( $userId ));
echo "<br>--debug--<br>";
And here's what I get:
- When logged as Super User:
This code displays:
- When logged as Adherent:
The same code displays:
When logged in as a SuperUser, var_dump(JUserHelper::getProfile( $userId ));
says:
object(Joomla\CMS\Object\CMSObject)#656 (3) { ["_errors":protected]=> array(0) { } ["id"]=> string(4) "2399" ["profile"]=> array(1) { ["dob"]=> string(19) "2020-07-28 00:00:00" } }
When logged as Adherent, the same code says:
object(Joomla\CMS\Object\CMSObject)#1412 (2) { ["_errors":protected]=> array(0) { } ["id"]=> string(4) "2399" }
var_dump(JUserHelper::getProfile( $userId ));
say?