Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability to retrieve avatar with WP_Post object #47

Merged
merged 1 commit into from
Jun 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions simple-local-avatars.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public function __construct() {
}

/**
* Retrieve the local avatar for a user who provided a user ID or email address.
* Retrieve the local avatar for a user who provided a user ID, email address or post/comment object.
*
* @param string $avatar Avatar return by original function
* @param int|string|object $id_or_email A user ID, email address, or comment object
* @param int|string|object $id_or_email A user ID, email address, or post/comment object
* @param int $size Size of the avatar image
* @param string $default URL to a default image to use if no avatar is available
* @param string $alt Alternative text to use in image tag. Defaults to blank
Expand All @@ -69,7 +69,9 @@ public function get_avatar( $avatar = '', $id_or_email = '', $size = 96, $defaul
$user_id = $user->ID;
elseif ( is_object( $id_or_email ) && ! empty( $id_or_email->user_id ) )
$user_id = (int) $id_or_email->user_id;

elseif ( $id_or_email instanceof WP_Post && ! empty( $id_or_email->post_author ) )
$user_id = (int) $id_or_email->post_author;

if ( empty( $user_id ) )
return $avatar;

Expand Down Expand Up @@ -592,9 +594,9 @@ function get_simple_local_avatar( $id_or_email, $size = 96, $default = '', $alt
if ( ! function_exists( 'get_avatar' ) && ( $simple_local_avatars_options = get_option('simple_local_avatars') ) && ! empty( $simple_local_avatars_options['only'] ) ) :

/**
* Retrieve the avatar for a user who provided a user ID or email address.
* Retrieve the avatar for a user who provided a user ID, post/comment object or email address.
*
* @param int|string|object $id_or_email A user ID, email address, or comment object
* @param int|string|object $id_or_email A user ID, email address, or post/comment object
* @param int $size Size of the avatar image
* @param string $default URL to a default image to use if no avatar is available
* @param string $alt Alternative text to use in image tag. Defaults to blank
Expand Down