Skip to content

Change post_author to Guest Author linked account, if any #582

Open
@TheCrowned

Description

@TheCrowned

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:

  1. Create two guest authors, link them to two real WP users other than admin. Let these be A and B
  2. Create another guest author, let's call it C, and don't link him to any WP user.
  3. Logged in as admin, create a new post and publish it
  4. Add the three guest authors above as guest authors and remove yourself
  5. Move C at the top of the list
  6. 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 wpusers 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions