Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for distributed guest authors #2215

Merged
merged 6 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions newspack-theme/inc/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<span class="author-avatar">' . wp_kses( $author_avatar, newspack_sanitize_avatars() ) . '</span>';
}
Expand All @@ -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(
'<a class="url fn n" href="%1$s">%2$s</a>',
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) */
'<span class="author vcard"><a class="url fn n" href="%1$s">%2$s</a></span>%3$s ',
esc_url( get_author_posts_url( $author->ID, $author->user_nicename ) ),
esc_html( $author->display_name ),
'<span class="author vcard">%1$s</span>%2$s ',
$author_name, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped above.
esc_html( $sep )
);
}
Expand Down Expand Up @@ -625,7 +636,7 @@ function newspack_tertiary_menu() {
</nav>
<?php
}
endif;
endif;

if ( ! function_exists( 'newspack_social_menu_settings' ) ) :
/**
Expand Down
62 changes: 43 additions & 19 deletions newspack-theme/template-parts/post/author-bio.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,42 @@
foreach ( $authors as $author ) {

if ( '' !== $author->description ) {
$author_avatar = 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 ) : '';
?>

<div class="author-bio">
<?php if ( $author_avatar ) : ?>
<a href="<?php echo esc_url( get_author_posts_url( $author->ID, $author->user_nicename ) ); ?>" rel="author">
<?php if ( $author_url ) : ?>
<a href="<?php echo esc_url( $author_url ); ?>" rel="author">
<?php endif; ?>
<?php echo wp_kses( $author_avatar, newspack_sanitize_avatars() ); ?>
</a>
<?php if ( $author_url ) : ?>
</a>
<?php endif; ?>
<?php endif; ?>

<div class="author-bio-text">
<div class="author-bio-header">
<div>
<h2 class="accent-header">
<a href="<?php echo esc_url( get_author_posts_url( $author->ID, $author->user_nicename ) ); ?>" rel="author">
<?php echo wp_kses( apply_filters( 'newspack_author_bio_name', $author->display_name, $author->ID ), array( 'span' => array( 'class' => array() ) ) ); ?>
</a>
<?php if ( $author_url ) : ?>
<a href="<?php echo esc_url( $author_url ); ?>" rel="author">
<?php endif; ?>
<?php
/**
* Filters the author name in the author bio.
*
* @param string $author_name The author name.
* @param int $author_id The author ID.
* @param object $author The author object. Can be a WP_User object or a Co-Authors Plus Guest Author object.
*/
echo wp_kses( apply_filters( 'newspack_author_bio_name', $author->display_name, $author->ID, $author ), array( 'span' => array( 'class' => array() ) ) );
?>
<?php if ( $author_url ) : ?>
</a>
<?php endif; ?>
</h2>

<?php if ( ( true === get_theme_mod( 'show_author_email', false ) && '' !== $author->user_email ) || true === get_theme_mod( 'show_author_social', false ) ) : ?>
Expand All @@ -58,22 +77,26 @@
<?php if ( get_theme_mod( 'author_bio_truncate', true ) ) : ?>
<p>
<?php echo esc_html( newspack_truncate_text( wp_strip_all_tags( $author->description ), $author_bio_length ) ); ?>
<a class="author-link" href="<?php echo esc_url( get_author_posts_url( $author->ID, $author->user_nicename ) ); ?>" rel="author">
<?php
/* translators: %s is the current author's name. */
printf( esc_html__( 'More by %s', 'newspack' ), esc_html( $author->display_name ) );
?>
</a>
<?php if ( $author_url ) : ?>
<a class="author-link" href="<?php echo esc_url( $author_url ); ?>" rel="author">
<?php
/* translators: %s is the current author's name. */
printf( esc_html__( 'More by %s', 'newspack' ), esc_html( $author->display_name ) );
?>
</a>
<?php endif; ?>
</p>
<?php else : ?>
<?php echo wp_kses_post( wpautop( $author->description ) ); ?>

<a class="author-link" href="<?php echo esc_url( get_author_posts_url( $author->ID, $author->user_nicename ) ); ?>" rel="author">
<?php
/* translators: %s is the current author's name. */
printf( esc_html__( 'More by %s', 'newspack' ), esc_html( $author->display_name ) );
?>
</a>
<?php if ( $author_url ) : ?>
<a class="author-link" href="<?php echo esc_url( $author_url ); ?>" rel="author">
<?php
/* translators: %s is the current author's name. */
printf( esc_html__( 'More by %s', 'newspack' ), esc_html( $author->display_name ) );
?>
</a>
<?php endif; ?>
<?php endif; ?>

</div><!-- .author-bio-text -->
Expand Down Expand Up @@ -104,7 +127,8 @@
<div>
<h2 class="accent-header">
<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
<?php echo wp_kses( apply_filters( 'newspack_author_bio_name', get_the_author(), get_the_author_meta( 'ID' ) ), array( 'span' => array( 'class' => array() ) ) ); ?>
<?php // This filter is documented above. ?>
<?php echo wp_kses( apply_filters( 'newspack_author_bio_name', get_the_author(), get_the_author_meta( 'ID' ), get_user_by( 'id', get_the_author_meta( 'ID' ) ) ), array( 'span' => array( 'class' => array() ) ) ); ?>
</a>
</h2>

Expand Down