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

Retain co-author data when setting archive author #279

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

RobjS
Copy link
Contributor

@RobjS RobjS commented Feb 5, 2025

Before: when we were setting the post author of a post who's post author ID (according to the author value in the wp_posts table) no longer existed, we also removed any co-authors attributed to that post

Now: we set the author ID in the wp_posts table to the archive author ID, but the co-author attribution is retained. This ensures that e.g. attribution for posts where the original user's WordPress user record has been removed, but they still have a co-author profile, is maintained

How to test

  1. Spin up GDS Blogs, and checkout this branch of the theme
  2. Ensure you have the Co-Authors Plus plugin active
  3. Ensure you don't have an archive_author option set in your wp_sitemeta table:wp network meta get 1 archive_author in WP CLI. If you do, delete it: wp network meta delete 1 archive_author
  4. Log into WordPress as admin
  5. Create a new WordPress user with at least author privileges. Note the ID of this user
  6. Create a new Guest Author record
  7. Publish a post and attribute it to the new guest author. Note the ID of the post you've just published
  8. Update the record for the post you've just published in the wp_posts table so that its post_author points to a non-existent user ID, e.g. UPDATE wp_posts SET post_author=999 WHERE ID=[the ID of the post you just published]. You may need to change the table name depending on whether you published the post on a subsite
  9. View the post in the frontend. It should still be attributed to the coauthor. Check the author_id in the database: SELECT post_author FROM wp_posts WHERE ID=[the ID of the post]. It should still be the non-existent author ID you changed it to
  10. Set the archive_author option to the ID of the user you created in step 5: wp network meta add 1 archive_author [the ID]
  11. Refresh the post in the frontend. It should still be attributed to the coauthor. However, if you check the author_id in the database, it should now point to the archive_author value you set

Before: when we were setting the post author of a post who's post author
ID (according to the `author` value in the `wp_posts` table) no longer
existed, we also removed any co-authors attributed to that post

Now: we set the author ID in the `wp_posts` table to the archive author
ID, but the co-author attribution is retained. This ensures that e.g.
attribution for posts where the original user's WordPress user record
has been removed, but they still have a co-author profile, is maintained
Copy link
Contributor

@snim2 snim2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me in a local env, and it doesn't work on the current main 👍🏻

@RobjS RobjS merged commit 349188b into master Feb 6, 2025
3 checks passed
@RobjS RobjS deleted the fix/do-not-remove-coauthors-on-absent-author-fix branch February 6, 2025 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants