title: Trying to get property of non-object Notice in custom avatar function for Wordpress
body: <p>The following custom avatar functions works fine, but I get the following notice</p>
  
  <blockquote>
    <p>"Trying to get property of non-object in..."</p>
  </blockquote>
  
  <p>The notice says the problem is on the last part of the function I pasted here - I marked it in the code (look for <code>&lt;-- Notice mentions this line</code>)</p>
  
  <p>Any idea how to fix this? I am stuck...</p>
  
  <pre><code>function test_get_avatar($avatar, $id_or_email, $size, $default, $alt) {
  if (!is_numeric($id_or_email)) {
      if (is_string($id_or_email)) {
          $user = get_user_by('email', $id_or_email);
          $id_or_email = $user-&gt;ID;
      } else if (is_object($id_or_email)) {
          if (!empty($id_or_email-&gt;ID)) {
              $id_or_email = $id_or_email-&gt;ID;
          }
  
          if (!empty( $id_or_email-&gt;comment_author_email)) {
              $user = get_user_by('email', $id_or_email-&gt;comment_author_email);
              $id_or_email = $user-&gt;ID; &lt;-- Notice mentions this line
          }
      }
  }
  
  $avatar_id = get_user_meta($id_or_email, 'nicobartes_user_avatar', true);
  ...
  </code></pre>