Automattic / Automattic/co-authors-plus
Deleting main author and assigning post to new author removes co-authors
Nobody has claimed this yet.
- #650 by @Lumrenion — closed without merging
- Dominant language
- PHP
- Stars
- 322
- Forks
- 218
- Avg merge
- 7h 50m
- Merged PRs (30d)
- 65
Description
Hi,
Following usecase:
Post A is assigned to author X (main author) and author Y (co-author).
Deleting author Y, no form for replacing the author in posts is shown, per wordpress default.
Deleting author X, the form is shown and I can select author Z to be set as the new author for post A.
Expected behaviour:
Deleting author X, post A should have author Z as main author and author Y remains as co-author.
Actual behaviour:
Deleting author X, post A has author Z as main author but author Y vanishes from the list of authors.
I dug through the code and found CoAuthors_Plus::add_coauthors(). In line 861, $existing_coauthors holds the user_login, in line 868, another reference to user_login is made.
In line 876, while iterating over the user_login strings, get_coauthor_by('user_nicename', $author_name) searches the user_nicename with having the user_login in $author_name. user_nicename and user_login are different in the above use case and false is returned.
Therefore, in line 881 wp_set_post_terms() removes all authors from the post.
When I change lines 868 and 876 to user_nicename instead of user_login, deleting a main author produces the expected behaviour.
Is this a bug or did I not understand the feature correctly?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect CoAuthors_Plus::add_coauthors(), especially the references on lines 868 and 876, and trace how wp_set_post_terms() is called. Reproduce deleting the main author when the co-author's user_login and user_nicename differ; done means the replacement author becomes primary while the existing co-author remains attached to the post.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- backend, content
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100