Description
Right now, CAP updates the WP_Post->post_author field only if one of the added users is only a WP user. Consider the following scenario:
- Create two guest authors, link them to two real WP users other than
admin
. Let these be A and B - Create another guest author, let's call it C, and don't link him to any WP user.
- Logged in as
admin
, create a new post and publish it - Add the three guest authors above as guest authors and remove yourself
- Move C at the top of the list
- Save post
At this point, the post post_author
would still hold admin
as value, even though the post could have been assigned to any other of the two new authors (to be precise, to their linked accounts). This can create issues with counting posts because we'd count this post both as authored from admin
and from the to guest authors, although admin
is not there anymore at all.
There is already a piece of code in add_coauthors()
that reassigns the post if the original author is not among the current co-authors anymore, but it only accepts wpuser
s and doesn't check for linked accounts:
foreach ( $coauthor_objects as $coauthor_object ) {
if ( 'wpuser' == $coauthor_object->type ) {
$new_author = $coauthor_object;
break;
}
}
The fix should act in this portion of the code, looking at whether $coauthor_object->linked_account !== ''
and, in case, retrieving the corresponding WP_User->ID
and assigning it to $new_author
.