Automattic / Co-Authors-Plus

Multiple bylines and Guest Authors for WordPress
https://wordpress.org/plugins/co-authors-plus/
GNU General Public License v2.0
291 stars 204 forks source link

Deleting main author and assigning post to new author removes co-authors #649

Open Lumrenion opened 5 years ago

Lumrenion commented 5 years ago

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?

rebeccahum commented 5 years ago

@Lumrenion This sounds like a bug to me, feel free to create a PR for this. Thank you for reporting!