0

I think that Im very close to achieve my goal.. I have this function on my themes but I need a help to find the right way to call simple local avatar function so it will show the local avatar image from simple local avatar pugin instead wordpress gravatar?

$first_img = get_avatar( $post->post_author );

Is there anyone can help?

function get_post_image() {
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  $first_img = $matches [1] [0];

  if(empty($first_img)){ //Defines a default image
    $first_img = get_avatar( $post->post_author );
  }
  return $first_img;
}
  • You are starting and stopping output buffering with nothing in between, which is pointless, but in what context do you want to "call" the function? Are you trying to override the default avatar system? – s_ha_dum Jun 27 '13 at 15:57
  • The actual codes is below.. function get_post_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $first_img = $matches [1] [0]; if(empty($first_img)){ //Defines a default image $img_dir = get_bloginfo('template_directory'); $first_img = $img_dir . '/images/post-default.jpg'; } return $first_img; – user34634 Jun 28 '13 at 5:57
  • That is what you have already posted in the question. How does that help and how does that answer my question? – s_ha_dum Jun 28 '13 at 13:17
0

The get_avatar function is pluggable, meaning that you can define a function of your own having that name and completely overwrite the default function.

If you look at the source for the "Simple Local Avatars" plugin, that is exactly what it has done. get_avatar in your code should be using the function defined by "Simple Local Avatars".

"Simple Local Avatars" provides a simplified function, get_simple_local_avatar, that you can use instead if you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.