From 7e7b4cd65105c5dab3d5ea9f6dc4bce957d2a7e0 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Fri, 9 Nov 2018 20:27:32 -0500 Subject: [PATCH] Error-free author bio output when a post has no author metadata. Cherry-picks some stuff from https://github.com/INN/largo/pull/1568/ Part of the https://github.com/INN/largo/issues/1492 whack-a-mole --- inc/avatars.php | 14 ++++++++------ inc/widgets/largo-author-bio.php | 8 ++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/inc/avatars.php b/inc/avatars.php index 88769241e..78a9a44f4 100644 --- a/inc/avatars.php +++ b/inc/avatars.php @@ -40,13 +40,15 @@ function largo_has_gravatar( $email ) { */ function largo_has_avatar( $email ) { $user = get_user_by( 'email', $email ); - $result = largo_get_user_avatar_id( $user->ID ); - if ( ! empty ( $result ) ) { - return true; - } else { - if ( largo_has_gravatar( $email ) ) { + if ( ! empty( $user ) ) { + $result = largo_get_user_avatar_id( $user->ID ); + if ( ! empty ( $result ) ) { return true; - } + } else { + if ( largo_has_gravatar( $email ) ) { + return true; + } + } } return false; } diff --git a/inc/widgets/largo-author-bio.php b/inc/widgets/largo-author-bio.php index 5cac8bb51..013bfc328 100644 --- a/inc/widgets/largo-author-bio.php +++ b/inc/widgets/largo-author-bio.php @@ -48,8 +48,12 @@ function widget( $args, $instance ) { // make sure we have at least one bio before we show the widget foreach ( $authors as $key => $author ) { - $bio = trim( $author->description ); - if ( !is_author() && empty( $bio ) ) { + if ( is_object( $author ) && isset( $author->description ) ) { + $bio = trim( $author->description ); + } else { + $bio = ''; + } + if ( ! is_author() && empty( $bio ) ) { unset( $authors[$key] ); } else { $bios .= $bio;