Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the post_author is a deleted user, change it to a specified user #270

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
16 changes: 16 additions & 0 deletions lib/set-archive-author.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

// Set the post_author to be "2"

function set_archive_author($data, $postarr)
{
$fix_types = ["page", "post", "attachment"];

if (!in_array($data['post_type'], $fix_types)) {
return $data;
}

$data['post_author'] = 2;
leedxw marked this conversation as resolved.
Show resolved Hide resolved

return $data;
}
17 changes: 15 additions & 2 deletions templates/entry-meta.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<div class="govuk-body-s">
<?php gds_byline(); ?>, <span class="govuk-visually-hidden">Posted on: </span><time class="updated" datetime="<?php echo get_the_time('c') ?>"><?php echo get_the_date('j F Y') ?></time>
<div class="govuk-body-s"><?php

// If the post is owned by a deleted user, set it to the archive user
$tmp_author_id = get_post_field('post_author', $post->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);
leedxw marked this conversation as resolved.
Show resolved Hide resolved
}
}

gds_byline();
?>, <span class="govuk-visually-hidden">Posted on: </span><time class="updated" datetime="<?php echo get_the_time('c') ?>"><?php echo get_the_date('j F Y') ?></time>
-
<span class="govuk-visually-hidden">Categories: </span>
<?php echo get_the_category_list(', ') ?>
Expand Down
Loading