Skip to content
Open
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
6 changes: 4 additions & 2 deletions newspack-sacha/template-parts/post/author-bio.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
}

$author_bio_length = get_theme_mod( 'author_bio_length', 200 );
// Shared avatar image size for author archive + author bio templates.
$author_avatar_size = get_theme_mod( 'author_avatar_size', 120 );

if ( function_exists( 'coauthors_posts_links' ) && is_single() && ! empty( get_coauthors() ) ) : // phpcs:ignore PHPCompatibility.LanguageConstructs.NewEmptyNonVariable.Found

Expand All @@ -20,7 +22,7 @@

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_avatar = $author->avatar_img_tag ?? coauthors_get_avatar( $author, absint( $author_avatar_size ) );
$author_url = get_author_posts_url( $author->ID, $author->user_nicename );

/**
Expand Down Expand Up @@ -109,7 +111,7 @@
<div class="author-bio-text">
<div class="author-bio-header">
<?php
$author_avatar = get_avatar( get_the_author_meta( 'ID' ), 80 );
$author_avatar = get_avatar( get_the_author_meta( 'ID' ), absint( $author_avatar_size ) );
if ( $author_avatar ) {
?>
<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
Expand Down
6 changes: 4 additions & 2 deletions newspack-theme/archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

$feature_latest_post = get_theme_mod( 'archive_feature_latest_post', true );
$show_excerpt = get_theme_mod( 'archive_show_excerpt', false );
// Shared avatar image size for author archive + author bio templates.
$author_avatar_size = get_theme_mod( 'author_avatar_size', 120 );

// Hide author on collection category archives.
if ( class_exists( '\Newspack\Optional_Modules\Collections' ) &&
Expand All @@ -35,10 +37,10 @@
$author_avatar = '';

if ( function_exists( 'coauthors_posts_links' ) ) {
$author_avatar = coauthors_get_avatar( $queried, 120 );
$author_avatar = coauthors_get_avatar( $queried, absint( $author_avatar_size ) );
} else {
$author_id = get_query_var( 'author' );
$author_avatar = get_avatar( $author_id, 120 );
$author_avatar = get_avatar( $author_id, absint( $author_avatar_size ) );
}

if ( $author_avatar ) {
Expand Down
44 changes: 44 additions & 0 deletions newspack-theme/inc/customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,29 @@ function newspack_customize_register( $wp_customize ) {
)
);

// Shared avatar image size for author archive and author bio templates.
$wp_customize->add_setting(
'author_avatar_size',
array(
'default' => 120,
'sanitize_callback' => 'newspack_sanitize_author_avatar_size',
)
);
$wp_customize->add_control(
'author_avatar_size',
array(
'type' => 'number',
'label' => esc_html__( 'Author Avatar Size', 'newspack-theme' ),
'description' => esc_html__( 'One shared setting for author archive and author bio avatars. Values are saved in the 32-512px range. This controls the requested image size; final on-screen size is still controlled by CSS.', 'newspack-theme' ),
'input_attrs' => array(
'min' => 32,
'max' => 512,
'step' => 1,
),
'section' => 'author_bio_options',
)
);

/**
* Template Settings
*/
Expand Down Expand Up @@ -1692,6 +1715,27 @@ function newspack_sanitize_checkbox( $input ) {
}
}

/**
* Sanitize author avatar image size.
*
* @param int|string $input Requested avatar size.
*
* @return int Clamped avatar size.
*/
function newspack_sanitize_author_avatar_size( $input ) {
$size = absint( $input );

if ( $size < 32 ) {
return 32;
}

if ( $size > 512 ) {
return 512;
}

return $size;
}

/**
* Sanitize the radio buttons.
*/
Expand Down
6 changes: 4 additions & 2 deletions newspack-theme/template-parts/post/author-bio.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
}

$author_bio_length = get_theme_mod( 'author_bio_length', 200 );
// Shared avatar image size for author archive + author bio templates.
$author_avatar_size = get_theme_mod( 'author_avatar_size', 120 );

if ( function_exists( 'coauthors_posts_links' ) && is_single() && ! empty( get_coauthors() ) ) : // phpcs:ignore PHPCompatibility.LanguageConstructs.NewEmptyNonVariable.Found

Expand All @@ -20,7 +22,7 @@

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_avatar = $author->avatar_img_tag ?? coauthors_get_avatar( $author, absint( $author_avatar_size ) );
$author_url = get_author_posts_url( $author->ID, $author->user_nicename );

/**
Expand Down Expand Up @@ -113,7 +115,7 @@
}

elseif ( (bool) get_the_author_meta( 'description' ) && is_single() ) :
$author_avatar = get_avatar( get_the_author_meta( 'ID' ), 80 );
$author_avatar = get_avatar( get_the_author_meta( 'ID' ), absint( $author_avatar_size ) );
?>

<div class="author-bio">
Expand Down