Plugin Directory

Co-Authors

Author: Weston Ruter

Allows multiple authors to be associated with a post. Co-authored posts appear on a co-author's posts page and feed. Additionally, co-authors may edit the posts they are associated with, and co-authors who are contributors may only edit posts if they have not been published (as is usual). Editors may easily add co-authors via the 'Post Author(s)' or 'Page Author(s)' boxes on the post/page writing page (see screenshots). 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 as follows:

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-graned 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();
}

When a user is deleted from WordPress, they will be removed from all of posts for which they are co-authors, and if a replacement user is provided, their co-authored posts will instead be co-attributed to another user.

Inspired by 'Multiple Authors' plugin by Mark Jaquith (2005).

If you value this plugin, please donate to ensure that it may continue to be maintained and improved.

Changelog

2008-06-16: 1.0 (beta 2)

  • Removed requirement to deactivate/activate newest version.

2008-06-16: 1.0 (beta)

  • Finally, anyone who is associated as a co-author may edit a post.
  • Changed postmeta key from "coauthor" to "_coauthor".

2008-06-15: 0.8.3

  • Added support for WordPress 2.5.1

2008-01-06: 0.8.2

  • Added support for localization. Localization files should be placed in the "localization" subdirectory under the plugin directory.

2008-01-06: 0.8.1

  • When working with a page, the author box now says "Page Author(s)" instead of "Post Author(s)".
  • Fixed trivial JavaScript error raised when working with a post or page that doesn't have any post meta.

2007-12-30: 0.8

  • Initial release.
Tags: ,