admin管理员组

文章数量:1296276

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;
}

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;
}
Share Improve this question asked Jun 27, 2013 at 15:19 user34634user34634 1 3
  • 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 Commented Jun 27, 2013 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 Commented Jun 28, 2013 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 Commented Jun 28, 2013 at 13:17
Add a comment  | 

1 Answer 1

Reset to default 1

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.

本文标签: imagesSimple Local Avatar Plugin