From 1ea11fbb96203ddab726e408fe5b2fda50cd5b2b Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Wed, 13 Dec 2023 18:21:59 -0300 Subject: [PATCH 1/6] feat: support distributed guest authors Handle guest authors distributed via Newspack Network and Distributor plugins --- newspack-theme/inc/template-tags.php | 23 ++++++--- .../template-parts/post/author-bio.php | 48 ++++++++++++------- 2 files changed, 48 insertions(+), 23 deletions(-) diff --git a/newspack-theme/inc/template-tags.php b/newspack-theme/inc/template-tags.php index 052d48611..d76a00d8e 100755 --- a/newspack-theme/inc/template-tags.php +++ b/newspack-theme/inc/template-tags.php @@ -95,7 +95,8 @@ function newspack_posted_by() { $i = 1; foreach ( $authors as $author ) { - $author_avatar = coauthors_get_avatar( $author, 80 ); + // avatar_url is a property added by Newspack Network plugin to distributed posts. + $author_avatar = $author->avatar_url ?? coauthors_get_avatar( $author, 80 ); echo '' . wp_kses( $author_avatar, newspack_sanitize_avatars() ) . ''; } @@ -117,11 +118,21 @@ function newspack_posted_by() { $sep = ''; endif; + $author_link = ! empty( $author->user_nicename ) ? get_author_posts_url( $author->ID, $author->user_nicename ) : ''; + + if ( ! empty( $author->user_nicename ) ) { + $author_name = sprintf( + '%2$s', + esc_url( get_author_posts_url( $author->ID, $author->user_nicename ) ), + esc_html( $author->display_name ) + ); + } else { + $author_name = esc_html( $author->display_name ); + } + printf( - /* translators: 1: author link. 2: author name. 3. variable seperator (comma, 'and', or empty) */ - '%2$s%3$s ', - esc_url( get_author_posts_url( $author->ID, $author->user_nicename ) ), - esc_html( $author->display_name ), + '%1$s%2$s ', + $author_name, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped above. esc_html( $sep ) ); } @@ -625,7 +636,7 @@ function newspack_tertiary_menu() { description ) { - $author_avatar = coauthors_get_avatar( $author, 80 ); + // avatar_url is a property added by Newspack Network plugin to distributed posts. + $author_avatar = $author->avatar_url ?? coauthors_get_avatar( $author, 80 ); + $author_url = ! empty( $author->user_nicename ) ? get_author_posts_url( $author->ID, $author->user_nicename ) : ''; ?>
- + + +

- + + +

user_email ) || true === get_theme_mod( 'show_author_social', false ) ) : ?> @@ -58,22 +68,26 @@

description ), $author_bio_length ) ); ?> - + + +

description ) ); ?> - + + +
From 71a6c33bff4bed546ce3ede250a2b2b47c61df10 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Thu, 14 Dec 2023 12:12:47 -0300 Subject: [PATCH 2/6] fix: rename user avatar property --- newspack-theme/template-parts/post/author-bio.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/newspack-theme/template-parts/post/author-bio.php b/newspack-theme/template-parts/post/author-bio.php index deb41fe66..650876fd5 100755 --- a/newspack-theme/template-parts/post/author-bio.php +++ b/newspack-theme/template-parts/post/author-bio.php @@ -21,8 +21,8 @@ foreach ( $authors as $author ) { if ( '' !== $author->description ) { - // avatar_url is a property added by Newspack Network plugin to distributed posts. - $author_avatar = $author->avatar_url ?? coauthors_get_avatar( $author, 80 ); + // avatar_img_tag is a property added by Newspack Network plugin to distributed posts. + $author_avatar = $author->avatar_img_tag ?? coauthors_get_avatar( $author, 80 ); $author_url = ! empty( $author->user_nicename ) ? get_author_posts_url( $author->ID, $author->user_nicename ) : ''; ?> From c8a79e2eb58cf861be2f4389fd36965acae2b509 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Thu, 14 Dec 2023 12:17:52 -0300 Subject: [PATCH 3/6] feat: add new param to author_bio_name filter --- newspack-theme/template-parts/post/author-bio.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/newspack-theme/template-parts/post/author-bio.php b/newspack-theme/template-parts/post/author-bio.php index 650876fd5..7161e0864 100755 --- a/newspack-theme/template-parts/post/author-bio.php +++ b/newspack-theme/template-parts/post/author-bio.php @@ -44,7 +44,16 @@ @@ -118,7 +127,8 @@

From 836748285ce6b0e10b3f32389592a0dd8f780d06 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Thu, 21 Dec 2023 16:02:26 -0300 Subject: [PATCH 4/6] fix: avatar property name --- newspack-theme/inc/template-tags.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/newspack-theme/inc/template-tags.php b/newspack-theme/inc/template-tags.php index d76a00d8e..f107f4413 100755 --- a/newspack-theme/inc/template-tags.php +++ b/newspack-theme/inc/template-tags.php @@ -95,8 +95,8 @@ function newspack_posted_by() { $i = 1; foreach ( $authors as $author ) { - // avatar_url is a property added by Newspack Network plugin to distributed posts. - $author_avatar = $author->avatar_url ?? coauthors_get_avatar( $author, 80 ); + // avatar_img_tag is a property added by Newspack Network plugin to distributed posts. + $author_avatar = $author->avatar_img_tag ?? coauthors_get_avatar( $author, 80 ); echo '' . wp_kses( $author_avatar, newspack_sanitize_avatars() ) . ''; } From 1b589ab2ce0e004ba13780c3924dc555ba262d94 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Fri, 22 Dec 2023 12:16:43 -0300 Subject: [PATCH 5/6] feat: update check for a hash link --- newspack-theme/inc/template-tags.php | 6 +++--- newspack-theme/template-parts/post/author-bio.php | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/newspack-theme/inc/template-tags.php b/newspack-theme/inc/template-tags.php index f107f4413..416f8bcac 100755 --- a/newspack-theme/inc/template-tags.php +++ b/newspack-theme/inc/template-tags.php @@ -118,12 +118,12 @@ function newspack_posted_by() { $sep = ''; endif; - $author_link = ! empty( $author->user_nicename ) ? get_author_posts_url( $author->ID, $author->user_nicename ) : ''; + $author_link = get_author_posts_url( $author->ID, $author->user_nicename ); - if ( ! empty( $author->user_nicename ) ) { + if ( '#' !== $author_link ) { $author_name = sprintf( '%2$s', - esc_url( get_author_posts_url( $author->ID, $author->user_nicename ) ), + esc_url( $author_link ), esc_html( $author->display_name ) ); } else { diff --git a/newspack-theme/template-parts/post/author-bio.php b/newspack-theme/template-parts/post/author-bio.php index 7161e0864..076c328ca 100755 --- a/newspack-theme/template-parts/post/author-bio.php +++ b/newspack-theme/template-parts/post/author-bio.php @@ -23,16 +23,16 @@ if ( '' !== $author->description ) { // avatar_img_tag is a property added by Newspack Network plugin to distributed posts. $author_avatar = $author->avatar_img_tag ?? coauthors_get_avatar( $author, 80 ); - $author_url = ! empty( $author->user_nicename ) ? get_author_posts_url( $author->ID, $author->user_nicename ) : ''; + $author_url = get_author_posts_url( $author->ID, $author->user_nicename ); ?>
- + @@ -41,7 +41,7 @@

- +

@@ -77,7 +77,7 @@

description ), $author_bio_length ) ); ?> - +