How to display specific button for certain user? I have a simple Drupal 7 page with 3 buttons. Page is only accessible by logged-in users.
I have 3 roles - role 1, role 2 &amp; role 3
What I would like to do is to show only button 1 when a user with role 1 logged in, hide the other 2.
How can I achieve this, please?
To hide and show buttons by role you can use the $GLOBALS to get the user and check on user role, something like.
 &lt;?php if (in_array('role 1', $GLOBALS[&quot;user&quot;]-&gt;roles)): ?&gt;
    &lt;button value=&quot;button 1&quot;&gt;button 1&lt;/button&gt;
  &lt;?php else: ?&gt;
    &lt;button value=&quot;button 2&quot;&gt;button 2&lt;/button&gt;
    &lt;button value=&quot;button 3&quot;&gt;button 3&lt;/button&gt;
  &lt;?php endif; ?&gt;