0

I have a piece of text in a custom page--front.tpl.php file. I would like to wrap this in a php if statement so that it is displayed only to two of my site roles. I have the below but it only displays for the "client" role whereas I would also like to display it for the"consultants" role.

<?php if (in_array('client', $GLOBALS['user']->roles)):?>

Client profile

Salmon
  • 19
  • 5

1 Answers1

0

in_array function should accept multiple search parameters if they are passed as an array. So it should be something like:

<?php if (in_array(array('client','consultants'), $GLOBALS['user']->roles)):?>

But if that's not working (and it should) you can always use or statement:

<?php if (in_array('client', $GLOBALS['user']->roles) || in_array('consultants', $GLOBALS['user']->roles)):?>

Update: it seems that in_array() can't accept an array for first (needle) parameter. Check out this thread on stack overflow:

Checking to see if one array's elements are in another array in PHP

So array_intersect() function should be what you are looking for.

Community
  • 1
  • 1
MilanG
  • 6,994
  • 2
  • 35
  • 64
  • Hi Milan thanks for the reply. Unfortunate the first option didn't work. I tried the second one and it seems to do the tricky. If i need to make the text display for a large range of user roles though, it might become quite lengthy. – Salmon Mar 06 '17 at 13:31
  • Updated my answer. – MilanG Mar 07 '17 at 07:43