P2 Resolved Posts: Only mark a specific category as unresolved

In the WordPress.org forums, ameeromar asks:

Hey would it be possible to limit the automatically marking as unresolved to one category? This would be particularly useful for my category ‘tasks’ which need to be marked as unresolved when published (and then marked as resolved when completed).

It’s totally possible using a combination of a couple filters. Here’s what the annotated code snippet looks like:

[code lang=”php”]
/**
* P2 Resolved Posts: Only mark ‘task’ posts as unresolved
*
* @see http://danielbachhuber.com/2013/04/18/p2-resolved-posts-only-mark-a-specific-category-as-unresolved/
*/
// Marks all new posts as unresolved
add_filter( ‘p2_resolved_posts_mark_new_as_unresolved’, ‘__return_true’ );
// Let us apply conditional logic to when posts are marked unresolved
add_filter( ‘p2_resolved_posts_maybe_mark_new_as_unresolved’, ‘p2rpx_only_mark_tasks’, 10, 2 );
function p2rpx_only_mark_tasks( $ret, $post ) {

// Get all of the categories assigned to the post
$cats = get_the_terms( $post->ID, ‘category’ );
// Make sure this didn’t return false or a WP_Error object
if ( is_array( $cats ) ) {

// Use wp_filter_object_list() to see if there are any ‘task’ terms
$task = wp_filter_object_list( $cats, array( ‘slug’ => ‘task’ ) );
// If there is a task term, we want to mark unresolved. Otherwise, no.
if ( ! empty( $task ) )
$ret = true;
else
$ret = false;
}

return $ret;
}
[/code]

However, in a stock P2 install, there isn’t a frontend interface for setting the category. The category is determined by the post format you use. Other users might be better off searching for tags by switching the term lookup to: get_the_terms( $post->ID, 'post_tag' );

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).

[sourcecode language=”php”]
/**
* 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 );
}
[/sourcecode]

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.

[sourcecode language=”php”]
/**
* 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>’;
}
}
[/sourcecode]

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.

Co-authors in your RSS feeds

In the WordPress.org forums, razorfrog asks:

Short of editing core WordPress code, is it possible to display the multiple authors in the site’s RSS feed?

Of course there is! From the source code, we know the RSS feed template uses the_author() to display the post’s byline information. Furthermore, the_author() echoes get_the_author() which is a filterable function. Filters allow us to programmatically change values used in a function. What we need to do is write a short snippet to produce the co-authors byline when an RSS feed is requested and Co-Authors Plus is activated.

The snippet is as follows, and can be placed in your theme’s functions.php file or a standalone MU plugin.

[sourcecode lang=”php”]/**
* Co-authors in RSS and other feeds
* /wp-includes/feed-rss2.php uses the_author(), so we selectively filter the_author value
*/
function db_coauthors_in_rss( $the_author ) {

if ( !is_feed() || !function_exists( ‘coauthors’ ) )
return $the_author;

return coauthors( null, null, null, null, false );
}
add_filter( ‘the_author’, ‘db_coauthors_in_rss’ );[/sourcecode]