From 10ca0ea6861456d052e5c707786ff0ef79990b93 Mon Sep 17 00:00:00 2001 From: Lee Maguire Date: Fri, 13 Dec 2024 16:42:14 +0000 Subject: [PATCH] Reset the post_author when user has been deleted Sets the post_author to 2 if the actual post_author is not found --- functions.php | 1 + lib/byline.php | 16 +++++----------- lib/set-archive-author.php | 16 ++++++++++++++++ templates/entry-meta.php | 17 +++++++++++++++-- 4 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 lib/set-archive-author.php diff --git a/functions.php b/functions.php index e76d1f9b..d8a5c81d 100644 --- a/functions.php +++ b/functions.php @@ -41,3 +41,4 @@ require(__DIR__.'/lib/tiny_mce.php'); require(__DIR__.'/lib/image-default-link-type.php'); require(__DIR__.'/lib/feeds.php'); +require(__DIR__.'/lib/set-archive-author.php'); diff --git a/lib/byline.php b/lib/byline.php index 670c486f..4d180621 100644 --- a/lib/byline.php +++ b/lib/byline.php @@ -4,17 +4,11 @@ function gds_byline() { ?> - Posted by: 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); + Posted by: + - , Posted on: +
ID); +if ($tmp_author_id > 2) { + $tmp_user = get_user_by('id', $tmp_author_id); + if (empty($tmp_user->user_login)) { + error_log("post {$post->ID} has deleted user $tmp_author_id", 0); + add_filter('wp_insert_post_data', 'set_archive_owner', '99', 2); + wp_update_post($post); + } +} + +gds_byline(); +?>, Posted on: - Categories: