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.
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.
Don't forget to add $_CB_framework global if it is yet to be established or it won't function and you'll receive an error. You can remove the $user check if you do not wish your code to stop, but keep note that all $user data will be null so be sure to compensate for this in your code!
As a Professional member you get all the Advanced privileges (CB detailed documentation, 17+ CB Add-ons, 11 GroupJive) and access to our same or next business day response time support forum for all your websites and our 26+ Incubator add-ons! That's a lot of add-ons that you can use on all your websites for ever!
Only 119 € for 12 months