Plugin Directory

Co-Authors Plus

Basic Usage and Other Notes

  • Contributor-level and above can be added as co-authors. An option added as of 2.0 allows subscribers to be added as coauthors as well.
  • As per WordPress design, only Editor-level and above users can change Post Authors. Authors cannot change authors or add co-authors (yet).
  • As per WordPress design, when an editor creates a new Post or Page, they are by default added as an author. However, they can be replaced by clicking on their name and typing in the name of the new author.
  • The search-as-you-type box starts searching once two letters have been added, and executes a new search with every subsequent letter.
  • The search-as-you-type box searches through the following user fields: a) user login; b) user nicename; c) display name; d) user email; e) first name; f) last name; and g) nickname.

Template Tags

New template tags enable listing of co-authors:

  • coauthors()
  • coauthors_posts_links()
  • coauthors_firstnames()
  • coauthors_lastnames()
  • coauthors_nicknames()
  • coauthors_links()
  • coauthors_IDs()

These template tags correspond to their "the_author*" equivalents; take special note of the pluralization. Each of these template tags accept four optional arguments:

  1. between: default ", "
  2. betweenLast: default " and "
  3. before: default ""
  4. after: default ""

To use them, simply modify the code surrounding all instances of the_author*() to something like the following example:

if(function_exists('coauthors_posts_links'))
    coauthors_posts_links();
else
    the_author_posts_link();

The result of this would be formatted like "John Smith, Jane Doe and Joe Public".

Note that as of this writing, WordPress does provide a means of extending wp_list_authors(), so included in this plugin is the function coauthors_wp_list_authors() modified to take into account co-authored posts; the same arguments are accepted.

Sometimes you may need fine-grained control over the display of a posts's authors, and in this case you may use the CoAuthorsIterator class. This class may be instantiated anywhere you may place the_author() or everywhere if the post ID is provided to the constructor. The instantiated class has the following methods:

  1. iterate(): advances $authordata to the next co-author; returns false and restores the original $authordata if there are no more authors to iterate.
  2. get_position(): returns the zero-based index of the current author; returns -1 if the iterator is invalid.
  3. is_last(): returns true if the current author is the last.
  4. is_first(): returns true if the current author is the first.
  5. count(): returns the total number of authors.
  6. get_all(): returns an array of all of the authors' user data.

For example:

$i = new CoAuthorsIterator();
print $i->count() == 1 ? 'Author: ' : 'Authors: ';
$i->iterate();
the_author();
while($i->iterate()){
    print $i->is_last() ? ' and ' : ', ';
    the_author();
}

the coauthor meta

  • get_the_coauthor_meta( $field ) (2.8 only)
  • the_coauthor_meta( $field ) (2.8 only)

Note: The $field variable corresponds with the same values accepted by the the author meta function.

get coauthors

  • get_coauthors( [$post_id], [$args] )

This function returns an array of coauthors for the specified post, or if used inside the Loop, the current post active in the Loop. the $args paramater is an array that allows you to specify the order in which the authors should be returned.

is coauthor for post

  • is_coauthor_for_post( $user, $post_id )

This function allows you to check whether the specified user is coauthor for a post. The $user attribute can be the user ID or username.

Download

FYI

Compatibility beta

Your Setup

Log in to vote.

The Consensus

No data
50,2,1

Average Rating

5 stars
4 stars
3 stars
2 stars
1 star
(6 ratings)