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

add_coauthors() deleting old users if user_login is email address #427

Open yomisimie opened 7 years ago

yomisimie commented 7 years ago

I noticed this issue if the user_login is different from user_nicename. This occurs in the main file co-authors-plus.php on line 815:

if ( $append ) { $existing_coauthors = wp_list_pluck( get_coauthors( $post_id ), 'user_login' ); } else { $existing_coauthors = array(); } The problem is that my user_login is the same as user_email and user_nicename removes the @ and . from the email address making it very different from the user_login. Also, if anywhere in the plugin it checks for user_nicename shouldn't this check for it too?

rebeccahum commented 7 years ago

Hi @yomisimie!

Thank you for reporting this issue. Would you be able to provide me steps to re-create the issue?

yomisimie commented 7 years ago

@rebeccahum sorry, been away for a while. The process is: I insert my users manually in PHP and i have to set a user_login so I am using email_post-id format. The user_login is not sanitized like the user_nicename so it still has special characters (the wp function wp_insert_user doesn't remove special characters: @,.) so when your plugin checks for existing users it checks for user_login and compares it to user_nicename, the last one being sanitized it doesn't match up. My script:

 $username = $_POST['user_email']."_".$id;
    $random_password = wp_generate_password( 12, false );
    $userdata = array(
      'user_login'  =>  $username,
      'user_email'  =>  $_POST['user_email'],
      'user_pass'   =>  $random_password,
      'first_name'  =>  $_POST['first_name'],
      'last_name'   =>  $_POST['last_name'],
    );
    $user = wp_insert_user($userdata);

The error comes from here

yomisimie commented 7 years ago

@rebeccahum any updates on this issue?

philipjohn commented 7 years ago

We should do some testing but this does sound like a bug we need to fix.

rebeccahum commented 7 years ago

Hi @yomisimie, sorry for the delay! I'm just looking into things right now and trying to re-create your issue. With your script, how is that done? Via a custom registration form? And are you able to elaborate a little more on the deleting part of the old users?

TheCrowned commented 6 years ago

Hi @yomisimie, I have tried recreating the issue with the latest commit of the master branch of this repository, but I haven't managed to. What I have done is:

  1. Create a new user having as username an email address (pluto@example.it)
  2. Go to an already existent post, with 2 coauthors
  3. Add the new user as coauthor and save
  4. Add yet another new user as coauthor and save

screenshot from 2018-06-18 12-28-05

No issues arose from these steps. Does the issue still exists for you? Can you point out whether I did something wrong?

GaryJones commented 1 year ago

Maybe fixed by #369.