Skip to content

Creating and editing guest authors

Yoli Hodde edited this page Jan 18, 2023 · 7 revisions

Guest authors can be created and managed under “Users” -> “Guest Authors”. Guest author data is created and stored as a guest_author custom post type.

Guest authors can be aded as bylines without creating WordPress user accounts for them. Each guest author can have many of same fields a normal WordPress user would typically have, including display name, email address, and website. You can assign a featured image in order to override the avatar typically associated with the email address.

Once you’ve created your guest author, their byline can be assigned to a post using the normal Co-Authors Plus interface.

Permissions

To create new guest author profiles, a WordPress user must have the list_users capability. This is typically granted to the Administrator role, but can be altered with the coauthors_guest_author_manage_cap filter.

To assign co-authors to posts, a WordPress user must have the edit_others_posts capability. This is typically granted to the Editor role, but can be altered with the coauthors_plus_edit_authors filter.

What happens to posts and pages when I delete a user assigned to a post or page as a coauthor?

When a user is deleted from WordPress, they will be removed from all posts for which they are co-authors. If you chose to reassign their posts to another user, that user will be set as the coauthor instead.

Incorporating new profile fields

The default set of profile fields can easily be manipulated using accessible filters. To place your field in one of the existing post meta boxes, use something similar to this example:

<php
/**
 * Add a "Google Plus" field to Co-Authors Plus Guest Author
 */
add_filter( 'coauthors_guest_author_fields', 'capx_filter_guest_author_fields', 10, 2 );
function capx_filter_guest_author_fields( $fields_to_return, $groups ) {
	if ( in_array( 'all', $groups ) || in_array( 'contact-info', $groups ) ) {
		$fields_to_return[] = array(
					'key'      => 'google_plus',
					'label'    => 'Google Plus',
					'group'    => 'contact-info',
				);
	}
	return $fields_to_return;
}

Then, for use on the frontend, the new field is automatically loaded onto the $coauthor object.

Migrating users to guest authors with wp-cli

If you’re performing a migration of users to co-author guest authors, there are a couple of helpful wp-cli commands packaged with the plugin:

  • wp co-authors-plus create-guest-authors will create guest authors for all of your existing users
  • wp co-authors-plus assign-user-to-coauthor will then assign all of the posts associated with old user to your new guest author

Steps to migrate all users/authors to a site:

  1. Install the Co-Authors Plus plugin on a staging site.
  2. Run the create-guest-authors CLI command to create the Guest Authors automatically.
  3. Export Guest Authors from the "Tools"-->"Export" screen of your staging site. Save the resulting WXR file. The WP-CLI guest authors will be included in this export.
  4. Create a mapping CSV file for editorial users who require real logins from their login on the staging site to their login on the production site (these may or may not be be the same). The CSV file format should be:
johnsmith, johnsmithwp
janesmith, janesmith
johndoe, johndoe123
  1. Import both the WXR and CSV with the WP-CLI command wp import. The WordPress Import tool cannot be used for importing these files.