Coder Social home page Coder Social logo

automattic / co-authors-plus Goto Github PK

View Code? Open in Web Editor NEW
288.0 132.0 204.0 4.25 MB

Multiple bylines and Guest Authors for WordPress

Home Page: https://wordpress.org/plugins/co-authors-plus/

License: GNU General Public License v2.0

Shell 1.26% CSS 0.93% PHP 82.90% JavaScript 14.25% Makefile 0.04% Gherkin 0.61%
wordpress wordpress-plugin wpvip-plugin

co-authors-plus's Introduction

Co-Authors Plus

Stable tag: 3.6.1
Requires at least: 4.1
Tested up to: 6.5
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: authors, users, multiple authors, co-authors, multi-author, publishing
Contributors: batmoo, danielbachhuber, automattic, GaryJ

Assign multiple bylines to posts, pages, and custom post types with a search-as-you-type input box.

Description

Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box. Co-authored posts appear on a co-author's archive page and in their feed. 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 core behavior).

Add writers as bylines without creating WordPress user accounts. Simply create a guest author profile for the writer and assign the byline as you normally would.

On the frontend, use the Co-Authors Plus template tags to list co-authors anywhere you'd normally list the author.

This plugin is an almost complete rewrite of the Co-Authors plugin originally developed by Weston Ruter (2007). The original plugin was inspired by the 'Multiple Authors' plugin by Mark Jaquith (2005).

Refer to our wiki for detailed documentation.

Installation

  1. IMPORTANT: If you are using the original Co-Authors plugin, disable it before installing Co-Authors Plus.
  2. Extract the coauthors-plus.zip file and upload its contents to the /wp-content/plugins/ directory. Alternately, you can install directly from the Plugin directory within your WordPress Install.
  3. Activate the plugin through the "Plugins" menu in WordPress.
  4. Place co-authors template tags in your template.
  5. Add co-authors to your posts and pages.

Screenshots

  1. Multiple authors can be added to a Post, Page, or Custom Post Type using an auto-complete interface.
  2. Guest authors allow you to assign bylines without creating WordPress user accounts. You can also override existing WordPress account meta by mapping a guest author to a WordPress user.

Frequently Asked Questions

How do I add Co-Authors Plus support to my theme?

If you've just installed Co-Authors Plus, you might notice that the bylines are being added in the backend but aren't appearing on the front end. You'll need to add the template tags to your theme before the bylines will appear.

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

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

Can I use Co-Authors Plus with WordPress multisite?

Yes! Co-Authors Plus can be activated on a site-by-site basis or network-activated. If you create guest authors, however, those guest authors will exist on a site-by-site basis.

Who needs permission to do what?

A WordPress user will need the edit_others_posts capability to assign co-authors to posts. This is typically granted to the Editor role but can be altered with the coauthors_plus_edit_authors filter.

A WordPress user will need the list_users capability to create new guest author profiles. This is typically granted to the Administrator role but can be altered with the coauthors_guest_author_manage_cap filter.

Can I easily create a list of all co-authors?

Yes! A template tag called coauthors_wp_list_authors() accepts many of the same arguments as wp_list_authors(). Look in template-tags.php for more details.

Can I disable Guest Authors?

Yes! Guest authors can be disabled entirely through a filter. Having the following line load on init will do the trick: add_filter( 'coauthors_guest_authors_enabled', '__return_false' )

Change Log

View the change log.

Blocks

Co-Authors

Use this block to create a repeating template that displays the co-authors of a post. By default it contains the Co-Author Name block, but you can add any other block you want to the template. If you choose another Co-Author block like avatar, biography or image it will automatically be supplied the author context that it needs. This works similarly to creating a Post Template in a Query Loop block.

The Co-Authors Block supports two layouts:

Inline Layout

Use the inline layout to display co-authors in a list on a single wrapping line.

You can control the characters displayed before, between and after co-authors in the list using the block settings, or change the defaults using the following server-side filters:

coauthors_default_before
coauthors_default_between
coauthors_default_between_last
coauthors_default_after

Block Layout

Use the block layout to display co-authors in a vertical stack. While using the block layout you can use block spacing settings to control the vertical space between co-authors.

Then you can create your own layout using blocks like group, row or stack and it will be applied to each co-author, similar to applying a layout to each post in a query loop.

Co-Author Name

This block displays a co-author's Display Name and optionally turns it into a link to their author archive.

Using the block's advanced settings you can select which HTML element is used to output the name. This is useful in contexts such as an author archive where you might want their name to be a heading.

Co-Author Avatar

Like the post author avatar, or comment author avatar, this block displays a small scale square image of a co-author and utilizes the Gravatar default avatars as configured in your site's discussion options.

To customize the available sizes, use the rest_avatar_sizes filter.

Co-Author Biography

This block outputs the biographical information for a co-author based on either their user or guest author data.

The content is wrapped in paragraph elements using wpautop and is escaped using wp_kses_post.

Co-Author Featured Image

This block requires the use of Guest Authors. Because guest author avatars are uploaded to the WordPress media library, there are more options for displaying these images.

This block utilizes the image sizes configured in your theme and your site's media settings to present a guest author's avatar at a larger scale or higher resolution. It does not support Gravatars.

Block Context

Post, Page, Query Loop

By default, all blocks receive the post context. The job of the Co-Authors Block is to use this context to find the relevant authors and provide context to its inner blocks.

Author Archive

If you want to display data about the author on their own archive, use the individual co-author blocks directly without wrapping them in the Co-Authors Block. During requests for an author archive the correct context is derived from the author_name query variable and provided to all blocks that declare their use of the context co-authors-plus/author.

Extending

If you make a custom block and want to use the author context, add co-authors-plus/author to the usesContext property in your block.json file.

Example:

{
	"usesContext": ["co-authors-plus/author"]
}

Block Example Data

When working with Full Site Editing, or in the post editor before the authors are loaded, example data is used. The example data provided with the co-author blocks resembles a response to the /coauthors/v1/coauthors/:user-nicename REST API endpoint.

Extending

If you have written a plugin that modifies the REST API response, you can similarly modify the example data either on the server-side using the filter coauthors_blocks_store_data or the client-side using the filter co-authors-plus.author-placeholder.

Block Non-support

To declare a lack of support for Co-Author Plus blocks on your site, use the filter coauthors_plus_support_blocks to return false.

co-authors-plus's People

Contributors

alecgeatches avatar bcampeau avatar blunce24 avatar danielbachhuber avatar dependabot[bot] avatar douglas-johnson avatar ethitter avatar garyjones avatar hibernation avatar joshbetz avatar laras126 avatar leogermani avatar lschuyler avatar mattoperry avatar mjangda avatar mpatek avatar natebot avatar netaustin avatar nickdaugherty avatar nielslange avatar nmeh20 avatar paulschreiber avatar philipjohn avatar rebeccahum avatar sanketio avatar sboisvert avatar shantanu2704 avatar simonwheatley avatar thecrowned avatar trepmal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

co-authors-plus's Issues

Incorrect post_author value being set

Sometimes, an editor will save or publish a post under different bylines and their user ID will be stored in the post_author field. This means that others' articles show up in their author listing page. Not exactly sure at this point where the code is breaking.

WP coding standards

We need to make sure we're up to snuff with all of the coding standards, that our comments actually make sense, etc.

Co-Authors breaks when user logins have a space

WordPress allows spaces in user logins. Don't ask me why, but it does. Since WP doesn't allow users to change their logins after the fact, this puts us in a precarious situation using this plugin as-is.

Looking through the code, there are a few places this might be remedied, but I'm not as closely familiar with the code.

  • First: the sanitize_title functions are probably not necessary for user logins since WordPress doesn't use this function for this purpose, and it adds a dash to the login name and causes get_user_by('login') functions to fail.
  • In line 21 of template-tags.php, I had to change the following line:
$post_author =  $coauthors_plus->get_coauthor_by( 'user_login', $coauthor->slug );

to:

$post_author =  $coauthors_plus->get_coauthor_by( 'user_login', $coauthor->name );

This uses the name property, which isn't sanitized, and more accurately reflects the proper username. This fixed authors with spaces in login names from appearing on posts. I'm still unable to search for additional authors however. I'm not sure the long-term implications of this change.

Glossing over everything, it doesn't seem like this would be enormously difficult to fix.

Thanks for the great plugin!

Update authors' post counts when quick editing or bulk editing

In #1433, we worked on making sure each author has an accurate published post count. It fires when the post is published or updated from the Edit Post view, but doesn't fire when posts are Quick Edit'd or Bulk Edit'd.

We should update the post counts for these actions too, and make sure we do it in a performant matter by only firing the update action when we're switching to or from a published state.

Ability to delete a guest author

Admins should be able to permanently delete a guest author. In doing so, we should prompt them to do one of three things:

  • If the guest author is associated with a WordPress user, allow them to leave the posts associated with the user. This results in the guest author post being deleted but the 'author' taxonomy term being left as it is.
  • Similarly, if the guest author doesn't have an associated WordPress user, the guest author post object is deleted and the corresponding 'author' taxonomy term is left associated with their bylined posts. This allows the admin to create the guest author again at a later date.
  • Allow the admin to reassign the guest author's posts to another guest author or WordPress user. This results in the guest author post object being deleted and all posts associated with the 'author' taxonomy term being reassigned to the new author.
  • Allow the admin to delete all posts associated with the guest author, in addition to their guest author post object.

Advanced functionality for guest authors search page

None of this should be too difficult, and it's on my near-term task list, just reflecting it here so my intentions are public:

  • Sortable columns.
  • Hover action and bulk action for deleting authors—maybe also a hover action to jump to associated user account?
  • Filters for guest authors that do and do not have WP users attached.

Media upload impossible when you are co-author

When you are a co-author (not the 'first' author) and you are not able to edit posts of other people, it's impossible to do a media-upload (Cheatin' Uh?). When you are 'first' author, the problem doesn't exist. Is there an easy fix for this problem? Thanks :-)

Update the readme

A fair amount of the content, and the screenshots, are out of date.

Slug management for guest authors

The 'slug' is how the relationship between the guest author and the 'author' taxonomy term is maintained. The 'author' taxonomy term is what's saved in relationship to the post. Thus, changing these together allows us to associate a post with a guest author.

For instance, I may have a post saved with 'daniel' as one of my 'author' taxonomy term values, or co-authors. When I use get_coauthor_by(), the code looks for a guest author with 'daniel' as the slug (actually stored in the post_name) and returns that data instead.

As of Friday the 4th of May at 5 pm, the slug is established from the user_login value when the guest author is created from an existing user, and from the 'Display Name' field the first time a new guest author is saved. We need a way of editing the slug for any guest author, but this will be more complex to do because we have to accommodate these use cases:

  • Create a Guest Author, use it as-is
  • Create a Guest Author, associate with user down the road
  • Create a Guest Author, decide to change the slug later
  • Existing user, create a guest author because user is leaving but still want post association
  • Existing user, create a guest author from it because want to modify user info (WP.com or multisite only)

Slug management will have at least these requirements:

  • Check to ensure a new slug doesn't conflict with other slugs
  • Rename the slug and transfer ownership of the posts
  • Rename the slug and leave the ownership of the posts with the old slug

Problem with url like upload.php?author=1

Hello.

I'm trying to filter media files under Media by user. Normally I can just use url like upload.php?author=1 and I can filter only media files from author 1. When Co Authors Plus is activated that doesn't work. I get "No media attachments found." or in some cases one media file.

The reason I'm asking this is that I have magazine with lots of students (authors) and they upload a lot of (unnecessary) images. It would help if they could filter they own images or admin could do it. I'm trying to make a plugin which make author name clickable instead of just plain text and adds that url upload.php?author=1.

Any idea how to fix this?

Don't query post_author when only guest authors are assigned to a post

Related to #32, here's a bigger, uglier part that manifests itself like this:

https://img.skitch.com/20120509-gfji1uryh7anhmtun74cd3css7.jpg

Basically, what's happening is that with the force_guest_author flag set to false, we query where the post_author is set to this particular author (which is the case with the two other guest-authored posts he's published).

We might be able to get around this by setting post_author to '0' when guest authors are assigned, but this might cause other bad things to happen when the plugin is deactivated.

Add rel=author to coauthor links

I had a case where we want to add rel="author" to coauthor links. Also it will be better to have it configurable, so we can change the rel="author" to some other value (may be rel="nofollow"). I have a patch commited to our branch of Co-Authors-Plus.

Amit Sannad

Avatars for guest authors

We should let admins upload images as avatars for guest authors, and then override the default value of get_avatar()

Fix ajax user search with large number of users

In #5, we switched to using get_users() and doing our search with PHP. Based on a forum report, it sounds like this breaks when you have a large number of users. Performance be damned... we should probably just switch back to a MySQL LIKE query when you have greater than N users (maybe the "large network" limit in core)

Form validation for creating or editing a guest author

When creating or editing a guest author, we should validate the form submitted by the user. In particular, we need to look for things like:

  • Required fields are filled out. Which fields are required to come.
  • No duplicate email addresses

Deleting a user can mistakenly assign new bylines

To reproduce:

  • User A creates a new post but publishes it under Guest Author A byline
  • Admin deletes User A and assigns all of their posts to User B
  • Post with Guest Author A byline will now get User B added to the byline too.

The culprit is:

$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $delete_id ) );

This gets post IDs where the user doesn't necessarily have the byline.

Create a guest author from an existing WordPress user

In the Users WP List Table, we should offer an action link to create a guest author from an existing WordPress user. If the user already has a guest author profile, then we should indicate as such and allow them to directly edit that profile.

Incorrect caps check for allowing editing

From Doug in the forums:

Ok. It took me a long time, but I figured out what the problem is. Line 833 of co-authors-plus.php checks for the publish_posts
capability for already existing posts. The correct capability it ought to be checking is edit_published_posts. Therefore, change 
the two occurrences of publish_posts to edit_published_posts and it seems to work properly. The modified line will then look 
like: if ( 'publish' == $post->post_status && ( ! isset( $allcaps[$post_type_object->cap->edit_published_posts] ) || ! 
$allcaps[$post_type_object->cap->edit_published_posts] ) )

Manage guest authors view

At "Users" -> "Guest Authors", we'll have a view for managing all of your guest authors. It would be nice if it comprised the following:

  • Paginated, searchable WP List Table of all of the guest authors in the system
  • See how many published posts each author has written
  • Links to edit an existing author or create a new one
  • Table fields:
    -- Name (w/ image)
    -- Email address
    -- See how many posts they've written
  • Bulk actions to delete

Integration with Edit Flow

Edit Flow, another plugin I work on, presents the post author in multiple contexts. When Co-Authors Plus is enabled too, it would be great if we made sure to update the values appropriately.

Co-Authors Plus breaks Quick Edit when WP_DEBUG is enabled

Co-Authors Plus breaks Quick Edit when WP_DEBUG is enabled and a post doesn’t have any co-authors assigned:

Notice: Trying to get property of non-object in C:\wamp\www\vip-sim\wp-content\themes\vip\plugins\co-authors-plus\template-tags.php on line 25
Notice: Undefined offset: 0 in C:\wamp\www\vip-sim\wp-content\themes\vip\plugins\co-authors-plus\co-authors-plus.php on line 470
Notice: Trying to get property of non-object in C:\wamp\www\vip-sim\wp-content\themes\vip\plugins\co-authors-plus\co-authors-plus.php on line 470

Reported by Jake Goldman (via Mo)

Prevent Infinite Loops

The following results in an infinite loop because coauthors_posts_links relies on get_the_author to output the user's name. We should prevent this from happening.

function my_guest_author($author){ if ( function_exists( 'coauthors_posts_links' ) ) $author = coauthors_posts_links(); return $author; } add_filter('the_author', 'my_guest_author');

Resolve notices on author.php views

Some notices that occur:

Notice: Trying to get property of non-object in /Users/danielbachhuber/edit-flow-demo/wp-includes/template.php on line 85
Notice: Trying to get property of non-object in /Users/danielbachhuber/edit-flow-demo/wp-includes/template.php on line 86
Notice: Trying to get property of non-object in /Users/danielbachhuber/edit-flow-demo/wp-includes/post-template.php on line 456

Improve caps filters

Our check function for filtering the cap required to set co-authors is pretty ugly. We should make it much better.

Presentation constants are defined too early

To allow the changing of how the co-authors are listed, we have the following at the top of the plugin:

if( ! defined( 'COAUTHORS_DEFAULT_BEFORE' ) )
    define( 'COAUTHORS_DEFAULT_BEFORE', '' );

if( ! defined( 'COAUTHORS_DEFAULT_BETWEEN' ) )
    define( 'COAUTHORS_DEFAULT_BETWEEN', ', ' );

if( ! defined( 'COAUTHORS_DEFAULT_BETWEEN_LAST' ) )
    define( 'COAUTHORS_DEFAULT_BETWEEN_LAST', __( ' and ', 'co-authors-plus' ) );

if( ! defined( 'COAUTHORS_DEFAULT_AFTER' ) )
    define( 'COAUTHORS_DEFAULT_AFTER', '' );

This means the user has to define these constants in an mu-plugin because their theme is loaded too late. We should just make these values filterable, and use the constants if they exist for backwards compat.

Improve performance of auto-suggest user search

Currently, we use and filter get_users() to handle the auto-suggest search. This works fine, but it would be better to improve its performance. We're doing queries every time the AJAX is fired.

One way we might do this is to load all of the users into cache on load and then search through that cached value with PHP instead. This way, we only need to to query once (on the first ajax search) and all other results are returned from the cached values.

Guest authors: main ticket

It would be great to be able to assign guest authors to a post without creating user accounts for them.

Slugs break with non-Latin character sets

If you use something like 'سمیر کھوسہ' in the display name field for a guest author, the plugin attempts to create a slug based on that display name. Unfortunately, we get a slug full of garbly-gook and bylines aren't properly associated with posts.

Don't allow any current authors to be added again

Currently, you can search for an author that's already been added to the post and add them again. It's not a huge problem because we dedupe when we save. It would be nice to not allow these users to be added again anyway.

Ability to exclude users form list of authors

Falls under "feature request". We have a lot of people with admin access (developers/project managers/ad ops/etc) who will never write a post, so we started work on a feature that would allow you to exclude users from the search. Basically adding a "exclude from co-authors" checkbox to the user page, and removing checked users from the list.

I have about half of the code on this ready to go, but it would take some work to finish it and make it compliant with WordPress coding standards.

Support "Mine" filter used in core

Core has a nice mine filter that appears when you're managing any post type. Because of how we change the filter query arg to author_name, the link is no longer added. We should fix that properly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.