Skip Navigation

The “Edit Any” and “Edit Own” permissions in Toolset Access do not apply to Published posts

Won't fix

Topic Tags: Access plugin

Symptoms

When managing a post type with Access, the options include permissions to Edit Any and Edit Own.

Based on the underlying WordPress capabilities, this does not grant users permission to edit published posts unless they explicitly have permission to publish posts.

Imagine a user with a low role that is not trusted to publish content to a live site. They are not trusted to edit live content, either.

To be able to edit publish posts, such users must also be given Publish rights.

See below for a workaround if you want users to be edit posts—including published posts—without granting publish rights.

Workaround

You can use the user_has_cap WordPress filter to automatically add the relevant edit_published_posts capability if it is missing.

Here is a fairly crude example, which you can modify to suit your needs:

/**
 * Add filter to force rights to edit published CPT posts
 * e.g. for CPT Things grant `edit_published_things`
 */
add_filter( 'user_has_cap', 'ts_filter_user_has_cap', 11, 3 );
function ts_filter_user_has_cap( $allcaps, $caps, $args ){

	if ( $args[0] === 'edit_post' && isset( $args[2] ) ) {

		// Automatically determine current post type
		// Alternatively, rewrite this to include specific post types
		$post = get_post( $args[2] );
		$post_type = get_post_type_object( $post->post_type );
		$post_type_plural_slug = sanitize_title( $post_type->label );

		$allcaps['edit_published_'.$post_type_plural_slug] = 1;
	}

	return $allcaps;
}

Leave
a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>