Show users with gravatar photo in member directory

This commit is contained in:
champsupertramp
2016-02-24 13:16:44 +08:00
parent 7faf52d18e
commit 65d090a514
2 changed files with 182 additions and 149 deletions
+8
View File
@@ -138,6 +138,11 @@
'key' => 'profile_photo', // from upload form
'value' => '',
'compare' => '!='
),
array(
'key' => 'synced_gravatar_hashed_id', // gravatar
'value' => '',
'compare' => '!='
)
);
@@ -152,6 +157,7 @@
);
}
// show specific usernames
if ( isset( $show_these_users ) && $show_these_users && is_array( $show_these_users ) ) {
foreach( $show_these_users as $username ) {
@@ -176,6 +182,7 @@
if ( isset( $sortby ) ) {
if ( $sortby == 'other' && $sortby_custom ) {
$query_args['meta_key'] = $sortby_custom;
@@ -232,3 +239,4 @@
return $result;
}
+28 -3
View File
@@ -1163,11 +1163,12 @@ function um_fetch_user( $user_id ) {
/***
*** @default avatar
***/
function um_get_default_avatar_uri() {
function um_get_default_avatar_uri( $user_id = '' ) {
$uri = um_get_option('default_avatar');
$uri = $uri['url'];
if ( !$uri )
$uri = um_url . 'assets/img/default_avatar.jpg';
return $uri;
}
@@ -1329,16 +1330,25 @@ function um_user( $data, $attrs = null ) {
case 'profile_photo':
$has_profile_photo = false;
if ( um_profile('profile_photo') ) {
$avatar_uri = um_get_avatar_uri( um_profile('profile_photo'), $attrs );
$has_profile_photo = true;
} else {
$avatar_uri = um_get_default_avatar_uri();
$avatar_uri = um_get_default_avatar_uri( um_user('ID') );
}
$avatar_uri = apply_filters('um_user_avatar_url_filter', $avatar_uri, um_user('ID') );
if ( $avatar_uri )
return '<img src="' . $avatar_uri . '" class="gravatar avatar avatar-'.$attrs.' um-avatar" width="'.$attrs.'" height="'.$attrs.'" alt="" />';
if( um_get_option('use_gravatars') && ! um_user('synced_profile_photo') && ! $has_profile_photo ){
$avatar_uri = um_get_domain_protocol().'gravatar.com/avatar/'.um_user('synced_gravatar_hashed_id');
$avatar_uri = add_query_arg('s',400, $avatar_uri);
}
return '<img src="' . $avatar_uri . '" class="func-um_user gravatar avatar avatar-'.$attrs.' um-avatar" width="'.$attrs.'" height="'.$attrs.'" alt="" />';
if ( !$avatar_uri )
return '';
@@ -1364,3 +1374,18 @@ function um_user( $data, $attrs = null ) {
}
/**
* Get server protocol
* @return string
*/
function um_get_domain_protocol(){
if ( is_ssl() ) {
$protocol = 'https://';
} else {
$protocol = 'http://';
}
return $protocol;
}