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

fix: usage of filter for post author footer bio name #1966

Merged
merged 1 commit into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 8 additions & 8 deletions newspack-sacha/template-parts/post/author-bio.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<div>
<h2 class="accent-header">
<?php echo wp_kses( apply_filters( 'newspack_author_bio_name', $author->display_name ), array( 'span' => array( 'class' => array() ) ) ); ?>
<?php echo wp_kses( apply_filters( 'newspack_author_bio_name', $author->display_name, $author->ID ), array( 'span' => array( 'class' => array() ) ) ); ?>
</h2>

<?php if ( true === get_theme_mod( 'show_author_email', false ) && '' !== $author->user_email ) : ?>
Expand Down Expand Up @@ -81,28 +81,28 @@
</div><!-- .author-bio-text -->

</div><!-- .author-bio -->
<?php
<?php
}
}

elseif ( (bool) get_the_author_meta( 'description' ) && is_single() ) :
?>
?>

<div class="author-bio">

<div class="author-bio-text">
<div class="author-bio-header">
<?php
$author_avatar = get_avatar( get_the_author_meta( 'ID' ), 80 );
if ( $author_avatar ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $author_avatar;
}
if ( $author_avatar ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $author_avatar;
}
?>

<div>
<h2 class="accent-header">
<?php echo wp_kses( apply_filters( 'newspack_author_bio_name', get_the_author() ), array( 'span' => array( 'class' => array() ) ) ); ?>
<?php echo wp_kses( apply_filters( 'newspack_author_bio_name', get_the_author(), get_the_author_meta( 'ID' ) ), array( 'span' => array( 'class' => array() ) ) ); ?>
</h2>

<?php if ( true === get_theme_mod( 'show_author_email', false ) ) : ?>
Expand Down
19 changes: 17 additions & 2 deletions newspack-theme/inc/trust-indicators.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function newspack_trust_indicators_output_author_info() {
}
}

$author_phone = get_user_meta( $author->ID, 'public_contact_info_tel', true );
$author_phone = get_user_meta( $author->ID, 'public_contact_info_tel', true );
$author_twitter = get_user_meta( $author->ID, 'twitter', true );
?>
<div class="trust-indicators author-meta">
Expand Down Expand Up @@ -129,6 +129,21 @@ function newspack_trust_indicators_output_author_job_title( $title ) {
}
add_filter( 'get_the_archive_title', 'newspack_trust_indicators_output_author_job_title' );

/**
* Adds author role to author footer.
*
* @param string $author_name string The author name.
* @param int $author_id string The author ID.
*/
function newspack_trust_indicators_author_bio_name( $author_name, $author_id ) {
$role = get_user_meta( $author_id, 'title', true );
if ( $role ) {
$author_name .= '<span class="author-job-title">' . $role . '</span>';
}
return $author_name;
}
add_filter( 'newspack_author_bio_name', 'newspack_trust_indicators_author_bio_name', 10, 2 );

/**
* Gets author role to add to single post author bios.
*/
Expand All @@ -150,7 +165,7 @@ function newspack_trust_indicators_output_author_details() {
$author = get_queried_object();

$all_settings_fields = Trust_Indicators_User_Settings::get_fields();
$fields = [
$fields = [
'location',
'languages_spoken',
'areas_of_expertise',
Expand Down
32 changes: 8 additions & 24 deletions newspack-theme/template-parts/post/author-bio.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,7 @@
<div class="author-bio-header">
<div>
<h2 class="accent-header">
<?php
echo esc_html( $author->display_name );
if ( class_exists( 'Trust_Indicators' ) ) {
$author_role = newspack_trust_indicators_job_title_single( $author->ID );
if ( '' !== $author_role ) {
echo '<span class="author-job-title">' . esc_html( $author_role ) . '</span>';
}
}
?>
<?php echo wp_kses( apply_filters( 'newspack_author_bio_name', $author->display_name, $author->ID ), array( 'span' => array( 'class' => array() ) ) ); ?>
</h2>

<?php if ( ( true === get_theme_mod( 'show_author_email', false ) && '' !== $author->user_email ) || true === get_theme_mod( 'show_author_social', false ) ) : ?>
Expand Down Expand Up @@ -95,37 +87,29 @@
</div><!-- .author-bio-text -->

</div><!-- .author-bio -->
<?php
<?php
}
}

elseif ( (bool) get_the_author_meta( 'description' ) && is_single() ) :
?>
?>

<div class="author-bio">

<?php
$author_avatar = get_avatar( get_the_author_meta( 'ID' ), 80 );
if ( $author_avatar ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $author_avatar;
}
if ( $author_avatar ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $author_avatar;
}
?>

<div class="author-bio-text">
<div class="author-bio-header">

<div>
<h2 class="accent-header">
<?php
echo esc_html( get_the_author() );
if ( class_exists( 'Trust_Indicators' ) ) {
$author_role = newspack_trust_indicators_job_title_single( get_the_author_meta( 'ID' ) );
if ( '' !== $author_role ) {
echo '<span class="author-job-title">' . esc_html( $author_role ) . '</span>';
}
}
?>
<?php echo wp_kses( apply_filters( 'newspack_author_bio_name', get_the_author(), get_the_author_meta( 'ID' ) ), array( 'span' => array( 'class' => array() ) ) ); ?>
</h2>

<?php if ( true === get_theme_mod( 'show_author_email', false ) || true === get_theme_mod( 'show_author_social', false ) ) : ?>
Expand Down