From 788cabdee14c78cb2dc3992648f91a16c68dc1f5 Mon Sep 17 00:00:00 2001 From: Lee Maguire Date: Mon, 16 Dec 2024 12:03:54 +0000 Subject: [PATCH] Use an option "archive_author" to specify the author --- lib/set-archive-author.php | 16 ++++++++++++++-- templates/entry-meta.php | 15 +++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/set-archive-author.php b/lib/set-archive-author.php index 7eb100b..27b3d72 100644 --- a/lib/set-archive-author.php +++ b/lib/set-archive-author.php @@ -1,6 +1,7 @@ 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_author', '99', 2); - wp_update_post($post); +// If the post is owned by a deleted user, patch it to the archive user +$check_author_id = get_post_field('post_author', $post->ID); +if ($check_author_id > 1) { + $check_user = get_user_by('id', $check_author_id); + if (empty($check_user->user_login)) { + error_log("author of post {$post->ID} is deleted user $check_author_id", 0); + add_filter('wp_insert_post_data', 'set_archive_author', 99, 2); } }