How to hide user picture based on the value of a field in their profile This last bug is the only thing between be and launching this site.  Please help!

I have a field called publish photo? that is a checkbox in the user's profile.  For users with this box unchecked, I would like to hide the user picture for users that are not logged in. I would like it to be hidden everywhere, in a display suite view and in the views view.  I had the following in my template.php, which I could have sworn was working, back before I added on display suite, but it seems not to be working now.

function MYMODULE_preprocess_user_picture(&amp;$variables) {
    if ((!isset($variables['account']-&gt;field_user_publish_photo) || $variables['account']-&gt;field_user_publish_photo[LANGUAGE_NONE][0]['value'] == '0') &amp;&amp; $variables['logged_in'] != 1) { // hide user photo when Publish photo is turned off
        $variables['user_picture'] = '';
    }
}


What is the proper way to do this?
template_preprocess_user_picture seems to be fair enough approach to me, the hook should be able to unset profile picture from any instance including views etc.

Only thing I doubt could go wrong in your code is conditional unsetting of images. To make sure could you comment out the condition

function MYMODULE_preprocess_user_picture(&amp;$variables) {
        $variables['user_picture'] = '';
}


If that unset your field than problem can be narrowed to make the condition working.

Probable problem with your condition
Can you check if you are getting fields in $variables['account'] object$variables['account'], if not you might need to object the user account and check the field conditions

$uid = $variables['account']-&gt;uid;
$account = user_load($uid);
function MYMODULE_preprocess_user_picture(&amp;$variables) {
  if ((!isset($account-&gt;field_user_publish_photo) || $account-&gt;field_user_publish_photo[LANGUAGE_NONE][0]['value'] == '0') &amp;&amp; $variables['logged_in'] != 1) { // hide user photo when Publish photo is turned off
      $variables['user_picture'] = '';
  }
}