Skip to content

Commit

Permalink
Don't display a byline if the page has an invalid author
Browse files Browse the repository at this point in the history
Posts having post_author ids that refer to deleted users cause
problems - even if co-authors is populated.

In the short term, don't attempt to resolve the author, and
independently find posts with

a) deleted authors
b) populated co-authors

and switch them to be user 0
  • Loading branch information
leedxw committed Dec 12, 2024
1 parent cdf8b66 commit 7c85d9a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/byline.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
function gds_byline()
{
?>
<span class="govuk-visually-hidden">Posted by: </span>
<?php
if (function_exists('coauthors_posts_links')) {
coauthors_posts_links(', ');
<span class="govuk-visually-hidden">Posted by: </span><?php
$tmp_author_id = get_post_field( 'post_author', $post->ID );
$tmp_user = get_user_by('id', $author_id );
if (empty($tmp_user->user_login)) {
echo "Deleted user $tmp_author_id";
error_log("{$post->ID} has deleted user $tmp_author_id", 0);
} else {
?> <a href="<?php echo get_author_posts_url(get_the_author_meta('ID')) ?>" rel="author" class="govuk-link"><?php echo get_the_author() ?></a> <?php
if (function_exists('coauthors_posts_links')) {
coauthors_posts_links(', ');
} else {
?> <a href="<?php echo get_author_posts_url(get_the_author_meta('ID')) ?>" rel="author" class="govuk-link"><?php echo get_the_author() ?></a> <?php
}
}
}

0 comments on commit 7c85d9a

Please sign in to comment.