admin管理员组文章数量:1332359
I have built my own frontend user avatar upload script. Now the avatars show fine in the user section in admin and in the top panel. However I can't seem to get them showing in the comments and author sections of the site.
I use the following get_avatar code
add_filter ('get_avatar', function($avatar_html, $id_or_email, $size, $default, $alt) {
$avatar = get_user_meta($id_or_email,'avatar',true);
if( $avatar ) {
return '<img src="'.$avatar.'" width="96" height="96" alt="Avatar" class="img-fluid rounded-circle" id="wad_profile_avatar" />';
} else {
return $avatar_html;
}
}, 10, 5);
Any ideas how I can get it to show in comments also?
I have built my own frontend user avatar upload script. Now the avatars show fine in the user section in admin and in the top panel. However I can't seem to get them showing in the comments and author sections of the site.
I use the following get_avatar code
add_filter ('get_avatar', function($avatar_html, $id_or_email, $size, $default, $alt) {
$avatar = get_user_meta($id_or_email,'avatar',true);
if( $avatar ) {
return '<img src="'.$avatar.'" width="96" height="96" alt="Avatar" class="img-fluid rounded-circle" id="wad_profile_avatar" />';
} else {
return $avatar_html;
}
}, 10, 5);
Any ideas how I can get it to show in comments also?
Share Improve this question edited Jun 25, 2020 at 12:24 David James Coxsell asked Jun 24, 2020 at 22:54 David James CoxsellDavid James Coxsell 12 bronze badges1 Answer
Reset to default 0I found a solution and now my frontend avatar script is fully functioning.
Happy days :)
I ended up scrapping the above code and using this.
add_filter( 'pre_get_avatar_data', 'wad_avatar_meta', 10, 2 );
function wad_avatar_meta( $args, $id_or_email ){
$user_avatar_meta_key = 'avatar';
if( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ){
$id_or_email = get_comment( $id_or_email );
}
if( $id_or_email instanceof WP_Post ){
$user_id = $id_or_email->post_author;
}
if( $id_or_email instanceof WP_Comment ){
if( ! empty( $id_or_email->user_id ) ){
$user_id = $id_or_email->user_id;
} elseif( ! empty( $id_or_email->comment_author_email ) ){
// If user_id not available, set as email address to handle below
$id_or_email = $id_or_email->comment_author_email;
}
}
if( is_numeric( $id_or_email ) ){
$user_id = $id_or_email;
} elseif( is_string( $id_or_email ) && strpos( $id_or_email, '@' ) ){
$id_or_email = get_user_by( 'email', $id_or_email );
}
if( $id_or_email instanceof WP_User ){
$user_id = $id_or_email->ID;
}
if( ! empty( $user_id ) && is_numeric( $user_id ) ){
$meta_val = maybe_unserialize( get_user_meta( $user_id, $user_avatar_meta_key, TRUE ) );
if( ! empty( $meta_val ) ){
if( is_array( $meta_val ) && ! empty( $meta_val[0] ) ){
$meta_val = $meta_val[0];
}
if( filter_var( $meta_val, FILTER_VALIDATE_URL ) ){
$args['url'] = $meta_val;
}
}
}
return $args;
}
本文标签: authorWordpress Custom Local Avatar not showing in comments
版权声明:本文标题:author - Wordpress Custom Local Avatar not showing in comments 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742318032a2452204.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论