Skip to Content Skip to Menu

🌟Discover the Joomla AI Plugin that wrote its own story! - CB Editor Assistant 1.1now for Joomla 3, 4 & 5!
✍️ 5-Day Free Trial, then 🎯 save up to 30% with our 🛍️ Intro Offer (First 50 users, ends Dec. 25th)
🌲 Merry Christmas! Great savings on Professional and Developer Memberships! Get 25% off now with code XMAS-2024!

Sometimes $user has yet to be establish in your code; especially if you're using an external code from Community Builder such as a module, but $user is needed for many Community Builder API usages. So you'll need to establish the $user of the logged in user. To do this add the following to your code, which will generate $user as used in Community Builder Plugins.

// Specific User
$user = CBuser::getUserDataInstance( USER_ID_HERE );

// My User
$user = CBuser::getMyUserDataInstance();

The above is great for establishing the $user object if this is the very basic you need. However with just the object you can't perform typical CBUser API such as replacement API to allow substitutions on a text string to be parsed. The below will allow usage of CBUser API as well as establish the $user object.

// Specific User
$cbUser = CBuser::getInstance( USER_ID_HERE, false );

// My User
$cbUser = CBuser::getMyInstance();

To access the user data from an established CBuser object you'd use the below.

$user = $cbUser->getUserData();