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

fix: query for CAP terms #1535

Merged
merged 1 commit into from
Sep 28, 2023
Merged

fix: query for CAP terms #1535

merged 1 commit into from
Sep 28, 2023

Conversation

dkoo
Copy link
Contributor

@dkoo dkoo commented Sep 20, 2023

All Submissions:

Changes proposed in this Pull Request:

Co-Authors Plus author terms for WP users match the WP user's user_login at the time of the WP user's creation. The user_login can't be updated in WP once the user is created, so it assumes that these values will always match. But in production environments, we've seen cases where this is not the case: specifically, the user_login and user_email differ, but the CAP term name matches the user_email instead of the `user_login. This seems to be possible only through direct DB manipulation, so I suspect this is happening from data migration. I haven't been able to recreate this scenario in a test site using WP admin, so the risk of it happening seems low for sites that haven't run into it, but it can be a serious issue with no workaround for sites that are affected.

How to test the changes in this Pull Request:

  1. On release, using a test site with Co-Authors Plus active, create a new WP "author" user. Make sure the user_login is something different from the user_email.
  2. Assign the user to one or more posts. This will also assign an author taxonomy term to the posts, as is standard CAP behavior. By default, the CAP term name will match the WP user's user_login, which you can verify by running wp term get author <user_login> and verifying that term exists. You can also run wp post term list author <post_id> on any of the posts assigned to the user to verify that this term is assigned to those posts.
  3. Using WP CLI, change the name of the author term to the user_email: wp term update author <term_id> --name=<user_email>
  4. In a page or post, add a new Homepage Posts block and set the Authors field to the WP user. Observe that the block finds 0 posts because it assumes the term's name will match the user's user_login.
  5. Check out this branch and refresh. Confirm that the block now shows the posts assigned to the user in step 2, in the editor and the front-end.
  6. Create another a new WP user and assign to different posts, but this time don't change anything about the term. Confirm that the user's posts still get fetched properly in the Homepage Posts block when setting the Author to this user.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@dkoo dkoo requested a review from a team as a code owner September 20, 2023 00:06
@dkoo dkoo changed the base branch from master to release September 20, 2023 00:06
@dkoo dkoo self-assigned this Sep 20, 2023
@dkoo dkoo marked this pull request as draft September 20, 2023 15:25
@dkoo dkoo marked this pull request as ready for review September 20, 2023 18:33
Copy link
Contributor

@laurelfulford laurelfulford 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 as described -- thanks @dkoo! 🚢

@dkoo
Copy link
Contributor Author

dkoo commented Sep 20, 2023

Update: this has been confirmed to be caused by a data migration, so the better approach would be to fix the migrated data.

@dkoo dkoo closed this Sep 20, 2023
@dkoo dkoo deleted the hotfix/cap-term-names branch September 20, 2023 20:53
@dkoo dkoo restored the hotfix/cap-term-names branch September 28, 2023 18:17
@dkoo
Copy link
Contributor Author

dkoo commented Sep 28, 2023

Reopening because we need more time to clean the data on the affected sites, and this solves the reader-facing issue in the meantime. We can potentially revert the change once the data is cleaned.

@dkoo dkoo reopened this Sep 28, 2023
@dkoo
Copy link
Contributor Author

dkoo commented Sep 28, 2023

Merging because it was already tested and approved!

@dkoo dkoo merged commit 49406b9 into release Sep 28, 2023
9 checks passed
@dkoo dkoo deleted the hotfix/cap-term-names branch September 28, 2023 18:19
matticbot pushed a commit that referenced this pull request Sep 28, 2023
## [1.75.1](v1.75.0...v1.75.1) (2023-09-28)

### Bug Fixes

* **checkout-button:** handle 10+ product variations ([#1536](#1536)) ([5df5065](5df5065))
* query for CAP terms ([#1535](#1535)) ([49406b9](49406b9))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.75.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants