I use the module Rules link event to trigger a rule based on visited path. The problem I have that in condition I need to use user variables but get an error - variable user is not defined. If I try php condition and use global $user, I get Notice: Trying to get property of non-object in eval() and Warning: in_array() expects parameter 2 to be array, null given in eval()

What could be the problem here?

  • try a first condition on the user, for example a user of a specific role, or with the permission to view content, etc. This should make the variable available for future conditions
    – Geoff
    May 21, 2015 at 20:47
  • @Geoff I tried it as my first option. I checked if current user is member of xy group. But rules gave error - variable user is not defined.
    – loparr
    May 21, 2015 at 21:52
  • 1
    are you using it with Commerce? that's what it was designed for - if not, take a look at Rules Link instead
    – Geoff
    May 22, 2015 at 5:51

1 Answer 1


Not sure what the reason might be that is causing your problem. But something that you could do to make this work, for sure, is like so:

  • Add a Rules Action "Fetch entity by id", whereas you want to fetch the user entity, and where you use the uid of the "current-user". For any subsequent Rules Action, you then have all fields of that user available as tokens.
  • Enable the Conditional Rules module, which allows you to specify Rules Conditions as part of Rules Actions. Using that technique, you can then like "move" any of your existing Rules Conditions (ie the ones where you need those user variables, as per your question). In doing so, you can then use any of the tokens that you made avaiable via the preceeding Rules Action "Entity has field".

BTW, no dangerous PHP code (stored in your database) needed to get this to work ...

Easy, no?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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