-
Notifications
You must be signed in to change notification settings - Fork 8
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
Fix/handle non existent author #275
Conversation
Before: if a user had authored a post, but then the user had subsequently been deleted without their posts being re-assigned, this resulted in a blank author being displayed in the front-end, and the "Author" spinner in the block editor never resolving. Now: we can set an "archive_author" option in `wp_options`. This should be set to the ID of the author we want to default to in cases where the original author has been removed without re-assignment. When that option is set, the next time the post is viewed in the front-end, the author will be re-written to be the archive author.
Before: when we re-allocated the post author if the existing post author no longer existed, we just changed the author id attached to the post. This fixed the author display in the front-end, but did not resolve the ever-spinning circle in the back-end, as if co-authors is active, co-author relationships (defined by taxonomy term relationships) was still in place. Now: if we have amended the post author ID, we also remove any co-author term relationships with the post in question. This means the newly allocated post author now displays in both the front and back-ends.
|
||
public function setArchiveAuthor($postData) | ||
{ | ||
$fix_types = ["page", "post", "attachment"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we care about revisions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to worry about revisions, they're not currently causing any issues. This code only kicks in if the post is viewed in the front-end, which won't happen with revisions unless they're restored, at which point this would then fix the issue anyway.
app/Theme/FixNonExistentAuthors.php
Outdated
return $postData; | ||
} | ||
|
||
$archive_user_option = get_option('archive_author'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: do we intend to set a default value for this? If not are we intending to go through the sites automatically or manually to set this value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'd been thinking that the wp_options
table applies across the entire network, but of course it doesn't, it's per site. I'll modify this so it takes this value from a network option instead, so we'll have to manually set it, but just the once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, yes, that was Lee's assumption too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine but there are a couple of questions here
Therefore, it only needs to be set once for all sites, rather than once per subsite. It is stored in the `wp_sitemeta` table.
I've pushed a change so the |
This PR re-allocated authorship of a post if the original author ID corresponds to a user who no longer exists (e.g. if that user has been deleted without their posts being re-assigned).
The authorship of the post is re-assigned to the user whose ID matched the
archive_author
option, if that option exists. If that option doesn't exist (or is of a non-numeric value), nothing happens.If the authorship is re-assigned, we also remove any of the co-author data associated with the post, as this can result in the post author still not being correctly displayed in the back-end.
How to test
vendor/bin/php-cs-fixer fix --dry-run && vendor/bin/kahlan spec
to run the automated testsDELETE FROM wp_users WHERE ID=[your-new-user]
archive_author
option to that user's ID (e.g.wp db option set archive_author [the-ID]
)