I'm trying to show or hide a button based on if a user has permission to post content to a group or not, but I don't seem to be able to call the og_user_access function from my custom module.

I've tried calling it directly while loading the module file:

module_load_include('module', 'og'); 
$allowed = og_user_access('group', $group->nid, 'create resource content');

Doing this crashes the page with no Apache error just a watchdog error of:

Error: Class name must be a valid object or a string in entity_get_controller() (line 8066 of /data/home/rsdev/www/content/lnsres.rsdev.ca/web/includes/common.inc).

I've also tried using module_invoke like so:

$allowed = module_invoke('og', 'og_user_access', 'group', $group->nid, 'create resource content');

Calling the module like this doesn't crash the page, but it also doesn't return anything and if I add some dpm() calls in the contrib module function I notice it's not even being called. Doing some reading about module_invoke appears like it's mostly used to call hooks, which I don't think og_user_access is, so I'm not sure if that's even the correct path to take.

How should I check group permissions in OG from my custom module's code ?

EDIT: This is not a duplicate of Display data basing on the group permission because I'm not trying to use a permission I created. Also the only answer in that question doesn't work for me because as I explained, I can't call og_user_access without an error.

  • 1
    Possible duplicate of Display data basing on the group permission
    – mradcliffe
    Commented Jul 3, 2019 at 14:41
  • I think Clive's answer there could be clarified to define what $group_type is because it may not be clear. $group_type means "group entity type", not "bundle". If that helps you please update (if you have enough karma) the answer there.
    – mradcliffe
    Commented Jul 3, 2019 at 14:42
  • @mradcliffe changing the $group_type variable from 'group' to 'node' didn't change anything. I don't know if this is necessarily a duplicate but the answer given in that question also doesn't work for me like I said in the description of this question. Commented Jul 3, 2019 at 15:06

1 Answer 1


if your group entity is a node which I'm guessing it should be change your code to:

$gid // your group's node id.
$allowed = og_user_access('node', $gid, 'create resource content');
  • I thought I had tried using 'node' before with the same parameters, but apparently hadn't. This fixed my issue ! Commented Jul 4, 2019 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.