[Resolved] Guest author wp_posts ID mistaken for wp_user ID in get_coauthors()
To my knowledge, we have never added Guest Authors, but at some point two were somehow created on my blog with names/slugs/emails identical to existing Users on the blog. Not quite sure how these were generated–at what point are Guest Authors generated?
But the bigger issue is that with these “duplicate” Guest Authors (duplicate in the sense that their post_title is the same as an existing User’s slug), they collide with the actual User within get_coauthors(). Now, when I iterate through the results of get_coauthors(), I get back the ID of the wp_posts Guest Author instead of the ID of the wp_users User. I then go on to display the completely wrong avatar and user information. In our situation, all of a sudden, a random User appears to be the author of the page.
When I go into the Users>Guest Authors and delete these Guest Authors, things return to normal. So I guess this brings up several issues:
- Under what circumstances are guest authors created? I want to better understand how these “dupes” were silently created.
- Can you not create a guest author if a User with this slug already exists? This seems a bad idea regardless of whether you fix collisions downstream.
- When there exists a User and a Guest Author with the same slug/post_title, shouldn’t you defer to the User? I think some changes to the get_coauthors() function are necessary to avoid this collision.
Thanks for the terrific plugin and I hope that this helps you track down the problems I describe.
Under what circumstances are guest authors created? I want to better understand how these “dupes” were silently created.
They weren’t automatically generated — someone must’ve accidentally created them by clicking the “Create Profile” link on the Manage Users Page.
Can you not create a guest author if a User with this slug already exists? This seems a bad idea regardless of whether you fix collisions downstream.
It’s actually intentional. Creating guest authors with the same slug as a user allows you to override user profile details. This is useful on a multisite network where a site admin might not have appropriate permissions to edit a user’s profile, or need to have different bios, etc. on a site by site basis.
You can safely delete the guest authors. One of the options when deleting a guest author will be to leave the posts associated with the mapped user.
Alternatively, guest authors are easily to disable with the following:
add_filter( 'coauthors_guest_authors_enabled', '__return_false' );
I’ll admit that I don’t fully understand the Guest Author content, but I have a few followup points from someone blindsided by this behavior…
I don’t know who clicked “Create Profile,” but perhaps the label for this link could be more descriptive. “Set up as Guest Author”? It’s very enticing to click as is. Had I noticed it, I would have clicked on it to see what that was, just out of curiosity. So, afterwards, it’s not very clear that (by being curious) you have just now created a Guest Author. I clicked it now, and got a cryptic screen asking for “Related Guest-author 1”. When I navigate away, it’s unclear that I’ve done anything permanent to the User. I feel like I should have had to confirm or hit a save button before the plugin inserted the Guest Author into the database.
I am using WP in multisite, so I’m happy that you support multisite. But in the situation that you describe, the User already existed on this blog. In fact, she was an Editor and had lots of content that got mis-assigned to a random incorrect blog user on the frontend.
So, I don’t think it was clear that we were overriding an editor’s profile with a feature called “Guest Authors.” I wish that there were prompts, explanations, or confirmations along the way which allowed us to avoid this mistake. Since there are other that use get_coauthors() or CoAuthorsIterator to find information on their authors, I imagine this issue will continue to pop up. The fact that this sometimes returns a Guest Author’s post, from which we get an incorrect avatar and incorrect permalink, was unexpected. (On that note, perhaps you should have introduced a new function which behaves this way instead of changing the returned values of the existing function.)
Ok just some thoughts. Thanks for considering this issue, and in the meantime I’ll add the filter as you suggest.
I wish that there were prompts, explanations, or confirmations along the way which allowed us to avoid this mistake.
I think a prompt / confirmation is a great idea. I’ve filed an issue.
On that note, perhaps you should have introduced a new function which behaves this way instead of changing the returned values of the existing function.
I tried to model the normal user object as much as possible so you could use guest authors without additional configuration. The ID is the only problematic value, and I don’t have a good solution for it right now.
I had the same problem, the “Create profile” link is misleading terminology since it really means “Create Guest Author profile”.
I’ve applied the filter to disable now as well, especially important on a multisite install. Will note if there is any remaining trouble.
- The topic ‘[Resolved] Guest author wp_posts ID mistaken for wp_user ID in get_coauthors()’ is closed to new replies.