Allowing authors to set co-authors

In the WordPress.org forums, whoaloic asks:

I have a site with multiple authors.
I would like to allow authors who create a post or a page to give rights to other authors.
For now, only administrator and editor can do that.
Is there a solution?

Yep, totally doable. By default, Co-Authors Plus defaults to ‘edit_others_posts’ as the required cap for changing co-authors. With the following code snippet in your theme’s functions.php file, you can make that cap ‘publish_posts’ instead (which authors and above usually have).

/**
 * Filter the Co-Authors Plus current_user_can_set_authors() function
 * so that users with 'publish_posts' can set Co-Authors
 *
 * @author danielbachhuber
 *
 * @see https://github.com/danielbachhuber/Co-Authors-Plus/issues/8
 * @see http://wordpress.org/support/topic/plugin-co-authors-plus-allow-authors-post-to-give-access-to-other-authors
 */
add_filter( 'coauthors_plus_edit_authors', 'db_filter_coauthors_edit_cap' );
function db_filter_coauthors_edit_cap( $cap_result ) {
	global $coauthors_plus;

	$post_type = $coauthors_plus->get_current_post_type();
	if( ! $post_type ) return false;
	
	$post_type_object = get_post_type_object( $post_type );
	return current_user_can( $post_type_object->cap->publish_posts );
}

In preparing this snippet, I also opened a couple of issues in Github:

Show biographies for co-authors at the end of your post

In the WordPress.org forums, doubleedesign says:

I want to add the authors’ biographies to the end of each post.

Awesome… it’s pretty simple to do. Conceptually, what we need to do is load our co-authors, and then loop through printing the relevant information for each one.

You’ll want to put the following code snippet within The Loop in any template you’d like the bios to appear.

/**
 * Show multiple Co-Author biography fields at the bottom of a single post 
 * This snippet should be placed within The Loop
 */
if ( class_exists( 'coauthors_plus' ) ) {
	// Get the Co-Authors for the post
	$co_authors = get_coauthors();
	// For each Co-Author, echo a wrapper div, their name, and their bio if they have one
	foreach ( $co_authors as $key => $co_author ) {
		$co_author_classes = array(
			'co-author-wrap',
			'co-author-number-' . ( $key + 1 ),
		);
		echo '<div class="' . implode( ' ', $co_author_classes ) . '">';
		echo '<h4 class="co-author-display-name">' . $co_author->display_name . '</h4>';
		// Only print the description if the description exists
		if ( $description = get_the_author_meta( 'description', $co_author->ID ) )
			echo '<p class="co-author-bio">' . $description . '</p>';
		echo '</div>';
	}
}

If you’d like other co-author details to appear as well, like their avatar for instance, you can modify the output within the foreach loop.

Today’s two WordPress.com VIP launches: PandoDaily and Grist

Today, MLK day even, two new sites launched on WordPress.com VIP that I’m personally pretty excited about.

PandoDaily

PandoDaily is a brand new tech site started by Sarah Lacy, former senior editor at TechCrunch. From her announcement post:

We have one goal here at PandoDaily: To be the site-of-record for that startup root-system and everything that springs up from it, cycle-after-cycle. That sounds simple but it’ll be incredibly hard to pull off. It’s not something we accomplish on day one or even day 300. It’s something we accomplish by waking up every single day and writing the best stuff we can, and continually adding like-minded staffers who have the passion, drive and talent to do the same.

So… this sounds like a newer, better, and fresher TechCrunch starting from scratch. And she’s recruited Michael ArringtonMG SieglerPaul Carr and Farhad Manjoo as regular contributors. Props to Sara Cannon for pulling off the design.

Grist

Grist, a non-profit environmental news publication, is near and dear to my heart. It’s why I’m on the technology side of publishing instead of photographing in the third world. In summer 2007, I worked an awesome web production internship where, in exchange for a bit of copy and pasting into the CMS, I had the freedom to explore publishing on the web and to start developing my skills. That was back in the days of Bricolage; Grist has since been on ExpressionEngine. Props to Matt Perry and Nathan Letsinger for making the switch happen (and to the Otto and Nacin show for their support).

Want to help publishers kick ass with WordPress? Come join my team — we’re hiring.

Open Web FTW

Quote

I worry about the independent web. I worry about the content creators, and I worry that if 100 percent of the distribution of everything starts to go through just a few websites, that kills the vibrancy.

A few years ago, Google started favoring some of their own websites over others. They left a path of scorched earth through many prominent businesses and publishers. Facebook hasn’t done that, but they could. And I think that would be bad for the web as a whole.

As things like Facebook’s news feed become ever more ingrained in our lives, the knobs they turn are hugely influential. For a year now, I’ve said scripting is the new literacy. That’s something I strongly believe. In Douglas Rushkoff’s latest book, he talks about “program or be programmed.” That is, if you’re not in control of your inputs, you’re not really in control of your outputs either. You’re just a reactionary force.

[...]

The Internet needs a strong, independent platform for those of us who don’t want to be at the mercy of someone else’s domain. I like to think that if we didn’t create WordPress something else that looks a lot like it would exist. I think Open Source is kind of like our Bill of Rights. It’s our Constitution. If we’re not true to that, nothing else matters.

Matt Mullenweg — Open Web FTW

Co-Authors Plus v2.6: Search user’s display names, change byline order and more

Co-Authors Plus makes it easy to add multiple bylines to a given post, and has full support for custom post types. Out this evening, v2.6 has the following improvements:

  • Sortable authors — drag and drop the order of the authors as you’d like them to appear
  • Search for authors by display name so you can easily add bylines by first or last name
  • Option to remove the first author when there are two or more listed
  • More reliably generates the published post count for each user

Thanks to those in the forum who provided feedback and special thanks to Russell Heimlich for his contributions with sortable authors. If you feel like giving back, there are a few tickets open we’d love patches for. In particular, guest bylines would be pretty neat. I have a possible direction you can go if you’re looking for inspiration.

For our WordPress.com VIPs, this release will be available in the shared plugins directory in just a moment.

Show matching terms in your search results

WordPress’ internal search isn’t all that great out of the box, as I’ve discussed before. For instance, tags and categories aren’t included in the search query; as such, if your post is tagged “apple”, but there is no mention of “apple” in the title or post content, the post won’t be included in your search results.

One partial workaround is to search taxonomy terms against your query and include those in your results. I did this previously with the CUNY J-School’s tech website:

You can have something similar with the code snippet below.

<?php
/**
 * Show matching terms for a given search query
 * Best placed under the_search_form() in search.php 
 */
global $wp_query;
// Only show the matching terms on the first page of results
if ( $wp_query->query_vars['paged'] <= 1 ) {
	$args = array(
		'search' => get_search_query(),
		'orderby' => 'none',
	);
	// You can change the first argument to an array of whatever taxonomies you want to search against
	$matching_terms = get_terms( array( 'post_tag', 'category' ), $args );
	if ( count( $matching_terms ) ) {					
		echo '<div class="all-matching-terms">Looking for? ';
		$all_terms = '';
		foreach ( $matching_terms as $matching_term ) {
			$all_terms .= '<a ';
			if ( $matching_term->description )
				$all_terms .= 'title="' . esc_attr( $matching_term->description ) . '" ';
			$all_terms .= 'href="' . esc_url( get_term_link( $matching_term, $matching_term->taxonomy ) ) . '">' . esc_html( $matching_term->name ) . '</a>, ';
		}
		echo rtrim( $all_terms, ', ' );
		echo '</div>';
	}
}