How to allow WordPress contributors to view draft posts: Simple Code Solution

Managing user permissions in WordPress is crucial for ensuring efficient workflows, especially when dealing with contributors.

By default, contributors cannot view draft posts authored by others, which might limit their ability to collaborate effectively.

In this article, we’ll provide a simple PHP snippet you can add to a custom mu-plugin or your theme’s functions.php file. This will allow logged-in contributors to see all draft posts, improving teamwork and content review processes.

<?php
/*
*	Allow contributors to see drafts
*
*/
add_filter( 'posts_results', 'wpster_preview_access', 10, 2 );
function wpster_preview_access( $posts ) {
	if (
		is_preview()
		&& ! empty( $posts )
		&& in_array( 'subscriber', wp_get_current_user()->roles, true )
	) {
		$posts[0]->post_status = 'publish';
	}
	return $posts;
}
?>

Submit a Comment

Your email address will not be published. Required fields are marked *