Co-Authors Plus
add_coauthors() method: user_login vs user_nicename (2 posts)

  1. Alexandre Simard
    Posted 1 year ago #

    Hey there,

    Thanks for the excellent plugin. I just have a small problem with it. In the add_coauthors() method in the main plugin file, you "pluck" existing coauthors' user_login on line 769:

    $existing_coauthors = wp_list_pluck( get_coauthors( $post_id ), 'user_login' );
    and add the current user's user_login on line 776:

    $coauthors = array( $current_user->user_login );

    , but when comes time to build the coauthors User objects, on line 784, you use 'user_nicename':

    $author = $this->get_coauthor_by( 'user_nicename', $author_name );

    In almost all WordPress installs, user_nicename and user_login are identical. It just so happens that they're not in mine. Therefore coauthors are not added. Is there a particular reason why 'user_login' isn't used everywhere?

    Thanks in advance!


  2. Alexandre Simard
    Posted 1 year ago #

    OK I've had the time to delve a bit more into the code and it seems that user_login and user_nicename are used as if they were interchangeable. That is _not_ the case. They're not filtered the same way on user creation. For example, spaces and the @ character are OK in user_login and not OK in user_nicename, which is meant to be used as a URL slug.

    Anybody else ever run into this issue?

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Co-Authors Plus
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.