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

feat: handle user nicename change #3725

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open

Conversation

leogermani
Copy link
Contributor

@leogermani leogermani commented Feb 4, 2025

All Submissions:

Changes proposed in this Pull Request:

This PR adds some special handling to allow for a safe change of a user's nicename.

User nicename is used to build the user author archive URL, and it's also what CoAuthors Plus use to create the taxonomy that handles posts authorship.

With this PR, when a user_nicename changes:

  • It stores the old nicename as user meta
  • It changes the taxonomy term used by CAP (author)
  • It redirects visits to the old user archive page to the new one

How to test the changes in this Pull Request:

  1. Activate CoAuthors Plus
  2. Set up a user with a few posts (both as the only author and as a secondary author)
  3. Visit the author archive page
  4. Change the user nicename to something else: wp newspack nicename-change <user_id> <new_nicename>
  5. Refresh the page and confirm you get redirected to the new URL, with the new nicename, and the same authors show up

Test check nicename

  1. Run wp newspack nicename-check <nicename> with a username you know is in use and confirm you see the appropriate output
  2. with CAP active, run the same command using a term slug that exists, with and without the cap prefix. For example, if you know cap-joe exists, run wp newspack nicename-check joe and wp newspack nicename-check cap-joe.

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?

@leogermani leogermani requested a review from a team as a code owner February 4, 2025 21:27
@leogermani leogermani self-assigned this Feb 4, 2025
@leogermani leogermani added [Status] Needs Review The issue or pull request needs to be reviewed and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Feb 4, 2025
@leogermani
Copy link
Contributor Author

Just found an edge case.

If the term slug we want to rename the term to already exists, the script will fail to change the term slug and the posts will no longer be assigned to the user.

This will only happen in a broken database... but that's the kind of database where we want to use this tool

@dkoo dkoo added the [Status] Needs Review The issue or pull request needs to be reviewed label Feb 6, 2025
@leogermani leogermani removed the [Status] Needs Review The issue or pull request needs to be reviewed label Feb 6, 2025
Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

Works as described!

@github-actions github-actions bot added the [Status] Approved The pull request has been reviewed and is ready to merge label Feb 6, 2025
@leogermani
Copy link
Contributor Author

Sorry @dkoo . I removed the Needs review label because I wanted to make some adjustments... I added it back again now.

The CLI will now check the availability of the nicename, including looking for CAP terms, before doing anything.

WP will already do it for the nicename itself, and add a suffix to avoid conflict, but it ignores the CAP terms... so I added this check

Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

Re-tested and it still works! Good call on adding the checks for preexisting nicenames.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] Approved The pull request has been reviewed and is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants