diff --git a/inc/extras.php b/inc/extras.php index b34cfe5b..b79f7dcd 100644 --- a/inc/extras.php +++ b/inc/extras.php @@ -281,12 +281,16 @@ if ( ! function_exists( 'understrap_all_excerpts_get_more_link' ) ) { * @return string */ function understrap_all_excerpts_get_more_link( $post_excerpt ) { - if ( ! is_admin() ) { - $post_excerpt = $post_excerpt . ' [...]

' . __( - 'Read More...', - 'understrap' - ) . ' from ' . get_the_title( get_the_ID() ) . '

'; + if ( is_admin() || ! get_the_ID() ) { + return $post_excerpt; } - return $post_excerpt; + + $permalink = esc_url( get_permalink( (int) get_the_ID() ) ); // @phpstan-ignore-line -- post exists + + return $post_excerpt . ' [...]

' . __( + 'Read More...', + 'understrap' + ) . ' from ' . get_the_title( get_the_ID() ) . '

'; + } } diff --git a/inc/template-tags.php b/inc/template-tags.php index 9bd4367e..da7d9e62 100644 --- a/inc/template-tags.php +++ b/inc/template-tags.php @@ -15,35 +15,50 @@ if ( ! function_exists( 'understrap_posted_on' ) ) { * Prints HTML with meta information for the current post-date/time and author. */ function understrap_posted_on() { + $post = get_post(); + if ( ! $post ) { + return; + } + $time_string = ''; + if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { $time_string = ''; } + $time_string = sprintf( $time_string, - esc_attr( get_the_date( 'c' ) ), - esc_html( get_the_date() ), - esc_attr( get_the_modified_date( 'c' ) ), - esc_html( get_the_modified_date() ) + esc_attr( get_the_date( 'c' ) ), // @phpstan-ignore-line -- post exists + esc_html( get_the_date() ), // @phpstan-ignore-line -- post exists + esc_attr( get_the_modified_date( 'c' ) ), // @phpstan-ignore-line -- post exists + esc_html( get_the_modified_date() ) // @phpstan-ignore-line -- post exists ); + $posted_on = apply_filters( 'understrap_posted_on', sprintf( '%1$s %3$s', esc_html_x( 'Posted on', 'post date', 'understrap' ), - esc_url( get_permalink() ), + esc_url( get_permalink() ), // @phpstan-ignore-line -- post exists apply_filters( 'understrap_posted_on_time', $time_string ) ) ); - $byline = apply_filters( - 'understrap_posted_by', - sprintf( - ' %1$s %3$s', - $posted_on ? esc_html_x( 'by', 'post author', 'understrap' ) : esc_html_x( 'Posted by', 'post author', 'understrap' ), - esc_url( get_author_posts_url( (int) get_the_author_meta( 'ID' ) ) ), - esc_html( get_the_author() ) - ) - ); + + $author_id = (int) get_the_author_meta( 'ID' ); + if ( 0 === $author_id ) { + $byline = ''; + } else { + $byline = apply_filters( + 'understrap_posted_by', + sprintf( + ' %1$s %3$s', + $posted_on ? esc_html_x( 'by', 'post author', 'understrap' ) : esc_html_x( 'Posted by', 'post author', 'understrap' ), + esc_url( get_author_posts_url( $author_id ) ), + esc_html( get_the_author_meta( 'display_name', $author_id ) ) + ) + ); + } + echo $posted_on . $byline; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } }