Skip to content

Commit

Permalink
feat: add ability to turn off author bio truncation and allow HTML (#862
Browse files Browse the repository at this point in the history
)
  • Loading branch information
laurelfulford authored Apr 3, 2020
1 parent dfdcf28 commit 6c6d9bf
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 25 deletions.
5 changes: 4 additions & 1 deletion newspack-sacha/sass/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,11 @@ cite {

h2 {
color: $color__text-main;
text-align: left;
margin: 0;

@include media( tablet ) {
text-align: left;
}
}

.avatar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,27 @@
</div>
</div><!-- .author-bio-header -->

<p>
<?php echo esc_html( newspack_truncate_text( $author->description, $author_bio_length ) ); ?>
<?php if ( get_theme_mod( 'author_bio_truncate', true ) ) : ?>
<p>
<?php echo esc_html( wp_strip_all_tags( newspack_truncate_text( $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>
</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 ) );
?>
<?php
/* translators: %s is the current author's name. */
printf( esc_html__( 'More by %s', 'newspack' ), esc_html( $author->display_name ) );
?>
</a>
</p><!-- .author-description -->
<?php endif; ?>

</div><!-- .author-bio-text -->

</div><!-- .author-bio -->
Expand Down Expand Up @@ -87,15 +99,27 @@
</div>
</div><!-- .author-bio-header -->

<p>
<?php echo esc_html( newspack_truncate_text( get_the_author_meta( 'description' ), $author_bio_length ) ); ?>
<a class="author-link" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
<?php if ( get_theme_mod( 'author_bio_truncate', true ) ) : ?>
<p>
<?php echo esc_html( wp_strip_all_tags( newspack_truncate_text( get_the_author_meta( 'description' ), $author_bio_length ) ) ); ?>
<a class="author-link" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
<?php
/* translators: %s is the current author's name. */
printf( esc_html__( 'More by %s', 'newspack' ), esc_html( get_the_author() ) );
?>
</a>
</p>
<?php else : ?>
<?php echo wp_kses_post( wpautop( get_the_author_meta( '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( get_the_author() ) );
?>
</a>
</p><!-- .author-description -->
<?php endif; ?>

</div><!-- .author-bio-text -->
</div><!-- .author-bio -->
<?php endif; ?>
8 changes: 7 additions & 1 deletion newspack-theme/archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@
<span>
<?php
the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="taxonomy-description">', '</div>' );
if ( '' !== get_the_archive_description() ) :
?>
<div class="taxonomy-description">
<?php echo wp_kses_post( wpautop( get_the_archive_description() ) ); ?>
</div>
<?php
endif;
?>
</span>

Expand Down
20 changes: 19 additions & 1 deletion newspack-theme/inc/customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,24 @@ function newspack_customize_register( $wp_customize ) {
)
);

// Add option to hide author email address.
$wp_customize->add_setting(
'author_bio_truncate',
array(
'default' => true,
'sanitize_callback' => 'newspack_sanitize_checkbox',
)
);
$wp_customize->add_control(
'author_bio_truncate',
array(
'type' => 'checkbox',
'label' => esc_html__( 'Truncate Author Bio', 'newspack' ),
'description' => esc_html__( 'Set a specific length for author bios displayed on single posts.', 'newspack' ),
'section' => 'author_bio_options',
)
);

// Add option to hide the whole author bio.
$wp_customize->add_setting(
'author_bio_length',
Expand All @@ -392,7 +410,7 @@ function newspack_customize_register( $wp_customize ) {
array(
'type' => 'number',
'label' => esc_html__( 'Author Bio Length (in characters)', 'newspack' ),
'description' => esc_html__( 'Truncates the author bio on single posts to this approximate character length, but without breaking a word. The full bio appears on the author archive page.', 'newspack' ),
'description' => esc_html__( 'Truncates the author bio on single posts to this approximate character length, but without breaking a word.', 'newspack' ),
'section' => 'author_bio_options',
)
);
Expand Down
15 changes: 15 additions & 0 deletions newspack-theme/js/src/customize-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@
} );
} );

// Only show Author Bio truncate options when enabled.
wp.customize( 'author_bio_truncate', function( setting ) {
wp.customize.control( 'author_bio_length', function( control ) {
const visibility = function() {
if ( true === setting.get() ) {
control.container.slideDown( 180 );
} else {
control.container.slideUp( 180 );
}
};
visibility();
setting.bind( visibility );
} );
} );

// Lets you jump to specific sections in the Customizer
$( [ 'control', 'section', 'panel' ] ).each( function( i, type ) {
$( 'a[rel="goto-' + type + '"]' ).click( function( e ) {
Expand Down
8 changes: 8 additions & 0 deletions newspack-theme/sass/site/primary/_archives.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@
.taxonomy-description {
color: $color__text-light;
font-style: italic;

a {
text-decoration: underline;

&:hover {
text-decoration: none;
}
}
}

.search {
Expand Down
9 changes: 9 additions & 0 deletions newspack-theme/sass/site/primary/_posts-and-pages.scss
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@ body.page {
}
}

a {
text-decoration: underline;

&:hover {
text-decoration: none;
}
}

.author-bio-text {
width: calc( 100% - 60px - 1em );
@include media( mobile ) {
Expand Down Expand Up @@ -416,6 +424,7 @@ body.page {
.author-link {
color: $color__primary;
font-weight: bold;
text-decoration: none;
&:hover {
color: $color__primary-variation;
}
Expand Down
46 changes: 35 additions & 11 deletions newspack-theme/template-parts/post/author-bio.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,27 @@
</div>
</div><!-- .author-bio-header -->

<p>
<?php echo esc_html( newspack_truncate_text( $author->description, $author_bio_length ) ); ?>
<?php if ( get_theme_mod( 'author_bio_truncate', true ) ) : ?>
<p>
<?php echo esc_html( wp_strip_all_tags( newspack_truncate_text( $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>
</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 ) );
?>
<?php
/* translators: %s is the current author's name. */
printf( esc_html__( 'More by %s', 'newspack' ), esc_html( $author->display_name ) );
?>
</a>
</p><!-- .author-description -->
<?php endif; ?>

</div><!-- .author-bio-text -->

</div><!-- .author-bio -->
Expand Down Expand Up @@ -109,15 +121,27 @@
</div>
</div><!-- .author-bio-header -->

<p>
<?php echo esc_html( newspack_truncate_text( get_the_author_meta( 'description' ), $author_bio_length ) ); ?>
<a class="author-link" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
<?php if ( get_theme_mod( 'author_bio_truncate', true ) ) : ?>
<p>
<?php echo esc_html( wp_strip_all_tags( newspack_truncate_text( get_the_author_meta( 'description' ), $author_bio_length ) ) ); ?>
<a class="author-link" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
<?php
/* translators: %s is the current author's name. */
printf( esc_html__( 'More by %s', 'newspack' ), esc_html( get_the_author() ) );
?>
</a>
</p>
<?php else : ?>
<?php echo wp_kses_post( wpautop( get_the_author_meta( '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( get_the_author() ) );
?>
</a>
</p><!-- .author-description -->
<?php endif; ?>

</div><!-- .author-bio-text -->
</div><!-- .author-bio -->
<?php endif; ?>

0 comments on commit 6c6d9bf

Please sign in to comment.