add alt images to profile images

This commit is contained in:
Evan Mullins 2023-01-23 18:32:21 -05:00
parent 669f4d5665
commit 5f88efda2c
5 changed files with 15 additions and 33 deletions

View file

@ -1408,15 +1408,18 @@ function wasmo_get_user_image_url( $userid ) {
*/
function wasmo_get_user_image( $userid ) {
$userimg = get_field( 'photo', 'user_' . $userid );
$user = get_userdata( $userid );
$alt = $user->display_name . ' profile image for wasmormon.org';
if ( $userimg ) {
return wp_get_attachment_image( $userimg, 'medium' );
} else {
$user = get_userdata( $userid );
return wp_get_attachment_image( $userimg, 'medium', false, array(
'alt' => $alt
) );
} else {
$hash = md5( strtolower( trim( $user->user_email ) ) );
$default_img = urlencode( 'https://raw.githubusercontent.com/circlecube/wasmo-theme/main/img/default.png' );
$gravatar = $hash . '?s=300&d='.$default_img;
return '<img src="https://www.gravatar.com/avatar/' . $gravatar . '" alt="' . $user->display_name . ' wasmormon.org profile image">';
return '<img src="https://www.gravatar.com/avatar/' . $gravatar . '" alt="' . $alt . '">';
}
}

View file

@ -5,7 +5,7 @@
Author: Evan Mullins
Author URI: https://circlecube.com
Template: twentynineteen
Version: 1.12.2
Version: 1.12.3
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: wasmo

View file

@ -72,28 +72,15 @@ if ( false === ( $the_answers = get_transient( $transient_name ) ) ) {
'website' === $in_directory ||
( 'private' === $in_directory && is_user_logged_in() )
) {
$userimg = get_field( 'photo', 'user_' . $userid );
$username = esc_html( $user->nickname );
$the_answers .= '<cite>';
$the_answers .= '<a class="person person-' . esc_attr( $userid ) . '" href="' . get_author_posts_url( $userid ) . '">';
$the_answers .= '<span class="directory-img">';
$userimg = get_field( 'photo', 'user_' . $userid );
if ( $userimg ) {
$the_answers .= wp_get_attachment_image( $userimg, 'thumbnail' );
} else {
$hash = md5( strtolower( trim( $user->user_email ) ) );
$default_img = urlencode( 'https://raw.githubusercontent.com/circlecube/wasmo-theme/main/img/default.png' );
$gravatar = $hash . '?s=150&d='.$default_img;
$the_answers .= '<img src="https://www.gravatar.com/avatar/' . $gravatar . '">';
}
$the_answers .= wasmo_get_user_image( $userid );
$the_answers .= '</span>';
$the_answers .= '<span class="directory-name">' . $username . '</span>';
$the_answers .= '</a>';
$the_answers .= '</cite>';
}
$the_answers .= '</div>';

View file

@ -35,28 +35,28 @@ $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('a
<?php if ( $links['facebook'] ) {
$svg = twentynineteen_get_social_link_svg( $links['facebook'], 26 );
?>
<li class="facebook"><a target="_blank" rel="noopener noreferrer" href="<?php
<li class="facebook"><a target="_blank" rel="nofollow ugc noopener noreferrer" href="<?php
echo esc_url( $links['facebook'] );
?>"><span class="screen-reader-text">Facebook</span><?php echo $svg; ?></a></li>
<?php } ?>
<?php if ( $links['instagram'] ) {
$svg = twentynineteen_get_social_link_svg( $links['instagram'], 26 );
?>
<li class="instagram"><a target="_blank" rel="noopener noreferrer" href="<?php
<li class="instagram"><a target="_blank" rel="nofollow ugc noopener noreferrer" href="<?php
echo esc_url( $links['instagram'] );
?>"><span class="screen-reader-text">instagram</span><?php echo $svg; ?></a></li>
<?php } ?>
<?php if ( $links['reddit'] ) {
$svg = twentynineteen_get_social_link_svg( $links['reddit'], 26 );
?>
<li class="reddit"><a target="_blank" rel="noopener noreferrer" href="<?php
<li class="reddit"><a target="_blank" rel="nofollow ugc noopener noreferrer" href="<?php
echo esc_url( $links['reddit'] );
?>"><span class="screen-reader-text">reddit</span><?php echo $svg; ?></a></li>
<?php } ?>
<?php if ( $links['twitter'] ) {
$svg = twentynineteen_get_social_link_svg( $links['twitter'], 26 );
?>
<li class="twitter"><a target="_blank" rel="noopener noreferrer" href="<?php
<li class="twitter"><a target="_blank" rel="nofollow ugc noopener noreferrer" href="<?php
echo esc_url( $links['twitter'] );
?>"><span class="screen-reader-text">twitter</span><?php echo $svg; ?></a></li>
<?php } ?>
@ -66,7 +66,7 @@ $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('a
$svg = wasmo_get_icon_svg( 'link' );
}
?>
<li class="other"><a target="_blank" rel="noopener noreferrer" href="<?php
<li class="other"><a target="_blank" rel="ugc noopener noreferrer" href="<?php
echo esc_url( $links['other'] );
?>"><span class="screen-reader-text">other</span><?php echo $svg; ?></a></li>
<?php } ?>

View file

@ -57,23 +57,15 @@ get_header();
'website' === $in_directory ||
( 'private' === $in_directory && is_user_logged_in() )
) {
$userimg = get_field( 'photo', 'user_' . $userid );
$username = esc_html( $user->nickname );
$the_answers .= '<cite>';
$the_answers .= '<a class="person person-' . esc_attr( $userid ) . '" href="' . get_author_posts_url( $userid ) . '">';
$the_answers .= '<span class="directory-img">';
if ( $userimg ) {
$the_answers .= wp_get_attachment_image( $userimg, 'medium' );
} else {
$the_answers .= '<img src="' . get_stylesheet_directory_uri() . '/img/default.svg">';
}
$the_answers .= wasmo_get_user_image( $userid );
$the_answers .= '</span>';
$the_answers .= '<span class="directory-name">' . $username . '</span>';
$the_answers .= '</a>';
$the_answers .= '</cite>';
}
$the_answers .= '</div>';