I have a Drupal 7 site, and I would like to print out inside the profile page some field content, according to the role of the profile user (not the logged in user). I need to show a specific field only if the profile owner does not have role autor:
<?php
if (!in_array('autor', array_values($user->roles))) {
print drupal_render(field_view_field('profile2', $profile['main'], 'field_nombrecompleto1', 'value'));
}
else {print "yada yada";}
Note: The profile field in question, is a rofile2 field and not a core profile one.
What´s wrong with that code? Because it will print out the field in question in any case, regardless of the role of the profile owner.
I´ve tried this other code, and in this case the field won´t print out in any case:
<?php
if (is_array($user->roles) &&
in_array('authenticated user', $user->roles) &&
!in_array('autor', $user->roles)) {
print drupal_render(field_view_field('profile2', $profile['main'], 'field_nombrecompleto1', 'value'));
}
?>