Role/Capability: When checking capabilities before setting a post slug, ensure the correct post type capabilities are used.

Previously, only the `publish_posts` capability was checked. Now, the correct meta or primitive capability for the post type is used where appropriate.

Props peterwilsoncc

Fixes #42464


git-svn-id: https://develop.svn.wordpress.org/trunk@42380 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2017-12-09 22:50:13 +00:00
parent 3a7ff0e2e6
commit 61350144fb
2 changed files with 184 additions and 2 deletions

View File

@@ -3304,8 +3304,16 @@ function wp_insert_post( $postarr, $wp_error = false ) {
}
}
// Don't allow contributors to set the post slug for pending review posts.
if ( 'pending' == $post_status && ! current_user_can( 'publish_posts' ) ) {
/*
* Don't allow contributors to set the post slug for pending review posts.
*
* For new posts check the primitive capability, for updates check the meta capability.
*/
$post_type_object = get_post_type_object( $post_type );
if ( ! $update && 'pending' === $post_status && ! current_user_can( $post_type_object->cap->publish_posts ) ) {
$post_name = '';
} elseif ( $update && 'pending' === $post_status && ! current_user_can( 'publish_post', $post_ID ) ) {
$post_name = '';
}