ensure variable is of type string

This commit is contained in:
IanDelMar 2022-07-23 01:55:51 +02:00
parent e5c7ebc7ef
commit 177755c0da
2 changed files with 39 additions and 20 deletions

View File

@ -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 . ' [...]<p><a class="btn btn-secondary understrap-read-more-link" href="' . esc_url( get_permalink( get_the_ID() ) ) . '">' . __(
'Read More...',
'understrap'
) . '<span class="screen-reader-text"> from ' . get_the_title( get_the_ID() ) . '</span></a></p>';
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 . ' [...]<p><a class="btn btn-secondary understrap-read-more-link" href="' . $permalink . '">' . __(
'Read More...',
'understrap'
) . '<span class="screen-reader-text"> from ' . get_the_title( get_the_ID() ) . '</span></a></p>';
}
}

View File

@ -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 = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s"> (%4$s) </time>';
}
$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(
'<span class="posted-on">%1$s <a href="%2$s" rel="bookmark">%3$s</a></span>',
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(
'<span class="byline"> %1$s<span class="author vcard"> <a class="url fn n" href="%2$s">%3$s</a></span></span>',
$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(
'<span class="byline"> %1$s<span class="author vcard"> <a class="url fn n" href="%2$s">%3$s</a></span></span>',
$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
}
}