Skip to content

Commit

Permalink
Merge pull request #46 from dparker1005/master
Browse files Browse the repository at this point in the history
Now pulling avatar from WP User Avatar if we don't have one yet
  • Loading branch information
ideadude authored May 19, 2021
2 parents cac260a + 0c74c6a commit ace3932
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
18 changes: 14 additions & 4 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Basic User Avatars
* Plugin URI: https://wordpress.org/plugins/basic-user-avatars/
* Description: Adds an avatar upload field to user profiles. Also provides front-end avatar management via a shortcode and bbPress support. No frills. Fork of Simple Local Avatars 1.3.
* Version: 1.0.4
* Version: 1.0.5
* Author: Stranger Studios
* Author URI: https://www.strangerstudios.com/
*
Expand Down Expand Up @@ -31,7 +31,7 @@
* along with Basic User Avatars. If not, see <http://www.gnu.org/licenses/>.
*
* @author Stranger Studios
* @version 1.0.4
* @version 1.0.5
* @package JA_BasicLocalAvatars
* @copyright Copyright (c) 2015, Jared Atchison, 2020 Stranger Studios
* @link https://www.strangerstudios.com/
Expand Down Expand Up @@ -138,6 +138,7 @@ public function sanitize_options( $input ) {
* @return string
*/
public function get_avatar( $avatar = '', $id_or_email, $size = 96, $default = '', $alt = false ) {
global $wpdb;

// Determine if we recive an ID or string
if ( is_numeric( $id_or_email ) )
Expand All @@ -152,8 +153,17 @@ public function get_avatar( $avatar = '', $id_or_email, $size = 96, $default = '

$local_avatars = get_user_meta( $user_id, 'basic_user_avatar', true );

if ( empty( $local_avatars ) || empty( $local_avatars['full'] ) )
return $avatar;
if ( empty( $local_avatars ) || empty( $local_avatars['full'] ) ) {
// Try to pull avatar from WP User Avatar.
$wp_user_avatar_id = get_user_meta( $user_id, $wpdb->get_blog_prefix() . 'user_avatar', true );
if ( ! empty( $wp_user_avatar_id ) ) {
$wp_user_avatar_url = wp_get_attachment_url( intval( $wp_user_avatar_id ) );
$local_avatars = array( 'full' => $wp_user_avatar_url );
update_user_meta( $user_id, 'basic_user_avatar', $local_avatars );
} else {
return $avatar;
}
}

$size = (int) $size;

Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ If things are still not functioning properly then proceed to reporting an issue.
1. Option on the bbPress user profile edit page.

== Changelog ==
= 1.0.5 - 2021-05-19 =
* ENHANCEMENT: Now pulling avatar from WP User Avatar if we don't have one yet

= 1.0.4 - 2020-01-12 =
* BUG FIX: Fixed typos on readme.txt - Thanks @fred-pedro
* ENHANCEMENT: Added translation for Spanish - Thanks @ricardpriet
Expand Down

0 comments on commit ace3932

Please sign in to comment.