I've used the snippets provided by Krileon to include the CB API and to establish the $user object. The issue I'm having is I can only retrieve user data for Administrators, not Registered Users.
Code:
/* start: set up access to CB API */
global $_CB_framework, $mainframe;
if (defined('JPATH_ADMINISTRATOR')) {
if (!file_exists(JPATH_ADMINISTRATOR.'/components/com_comprofiler/plugin.foundation.php')) {
echo 'CB not installed!';
return;
}
include_once(JPATH_ADMINISTRATOR.'/components/com_comprofiler/plugin.foundation.php');
}
else {
if (!file_exists($mainframe->getCfg('absolute_path').'/administrator/components/com_comprofiler/plugin.foundation.php')){
echo 'CB not installed!';
return;
}
include_once($mainframe->getCfg('absolute_path').'/administrator/components/com_comprofiler/plugin.foundation.php');
}
/* end */
/* start: establish $user */
$myId = $_CB_framework->myId();
$cbUser =& CBuser::getInstance( $myId );
if ( ! $cbUser ) {
$cbUser =& CBuser::getInstance( null );
}
$user =& $cbUser->getUserData();
/* end */
/* start: set variables for pdf */
$userFirstName = $user->cb_firstname;
$userLastName = $user->cb_lastname;
echo $userFirstName;
echo $userLastName;
If I'm logged into my site with a regular, registered user those last two echo lines do not produce the user's first and last name, but if I'm logged in as an administrator they do. Why is this?