Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Franz Josef Kaiser committed Oct 8, 2015
2 parents 6a578d7 + 61c2e09 commit d883d17
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/Services/AvatarReplacementService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function __construct( $key )


/**
* @param string $html
* @param int|string $id_or_email
* @param array $args
* @param string $html
* @param int|string|\stdClass $id_or_email ID, email or Comment object
* @param array $args
* @return null|string Return NULL to abort and replace nothing
*/
public function setup( $html = '', $id_or_email = -1, Array $args = [ ] )
Expand All @@ -44,9 +44,7 @@ public function setup( $html = '', $id_or_email = -1, Array $args = [ ] )
return '';

/** @var \WP_User|bool $user */
$user = is_numeric( $id_or_email )
? get_userdata( $id_or_email )
: get_user_by( 'email', $id_or_email );
$user = $this->getUser( $id_or_email );

if ( ! $user instanceof \WP_User )
return '';
Expand Down Expand Up @@ -118,6 +116,24 @@ public function setup( $html = '', $id_or_email = -1, Array $args = [ ] )
}


/**
* @param int|string|\stdClass $alot ID, email or Comment object
* @return false|\WP_User
*/
private function getUser( $alot )
{
if (
is_object( $alot )
and isset( $alot->comment_author )
)
return get_userdata( $alot->comment_author );

return is_numeric( $alot )
? get_userdata( $alot )
: get_user_by( 'email', $alot );
}


/**
* @param int $att_id
* @param array $args
Expand Down

0 comments on commit d883d17

Please sign in to comment.