Skip to content

Commit

Permalink
Password protected posts will no longer show the excerpt
Browse files Browse the repository at this point in the history
Fixes #100
  • Loading branch information
ajaydsouza committed May 6, 2020
1 parent df47d81 commit c76efcf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
function tptn_excerpt( $id, $excerpt_length = 0, $use_excerpt = true ) {
$content = '';

$post = get_post( $id );
if ( empty( $post ) ) {
return '';
}
if ( $use_excerpt ) {
$content = get_post( $id )->post_excerpt;
$content = $post->post_excerpt;
}

if ( '' === $content ) {
$content = get_post( $id )->post_content;
if ( empty( $content ) ) {
$content = $post->post_content;
}

$output = wp_strip_all_tags( strip_shortcodes( $content ) );
Expand All @@ -31,6 +34,10 @@ function tptn_excerpt( $id, $excerpt_length = 0, $use_excerpt = true ) {
$output = wp_trim_words( $output, $excerpt_length );
}

if ( post_password_required( $post ) ) {
$output = __( 'There is no excerpt because this is a protected post.', 'top-10' );
}

/**
* Filters excerpt generated by tptn.
*
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ Release post: [https://webberzone.com/blog/top-10-v2-9-0/](https://webberzone.co
* Enhancements:
* Cache now uses MD5 generated keys based on the Top 10 parameters being passed. This means the cache should now work with shortcodes and manual implementations
* Database creation now uses the correct collation
* Password protected posts will no longer show the excerpt

* Bug fixes:
* `include_cat_ids` didn't work with the shortcode
Expand Down

0 comments on commit c76efcf

Please sign in to comment.