Role/Capability: Only users who can manage options should be able to trash/delete the page for posts or the front page, as they are the only users who can restore it or subsequently alter the "Front page displays" setting.
Fixes #37580 Props JakePT git-svn-id: https://develop.svn.wordpress.org/trunk@38378 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f21f8c1076
commit
5e71c349af
@ -67,6 +67,11 @@ function map_meta_cap( $cap, $user_id ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( ( get_option( 'page_for_posts' ) == $post->ID ) || ( get_option( 'page_on_front' ) == $post->ID ) ) {
|
||||
$caps[] = 'manage_options';
|
||||
break;
|
||||
}
|
||||
|
||||
$post_type = get_post_type_object( $post->post_type );
|
||||
if ( ! $post_type ) {
|
||||
/* translators: 1: post type, 2: capability name */
|
||||
|
@ -255,4 +255,40 @@ class Tests_User_MapMetaCap extends WP_UnitTestCase {
|
||||
$this->assertEquals( array( 'delete_others_posts', 'delete_published_posts' ), map_meta_cap( 'delete_post', $editor, $post_id ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test deleting front page.
|
||||
*
|
||||
* @ticket 37580
|
||||
*/
|
||||
function test_only_users_who_can_manage_options_can_delete_page_on_front() {
|
||||
$post_id = self::factory()->post->create( array(
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
) );
|
||||
|
||||
update_option( 'page_on_front', $post_id );
|
||||
$caps = map_meta_cap( 'delete_page', $this->user_id, $post_id );
|
||||
delete_option( 'page_on_front' );
|
||||
|
||||
$this->assertEquals( array( 'manage_options' ), $caps );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test deleting posts page.
|
||||
*
|
||||
* @ticket 37580
|
||||
*/
|
||||
function test_only_users_who_can_manage_options_can_delete_page_for_posts() {
|
||||
$post_id = self::factory()->post->create( array(
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
) );
|
||||
|
||||
update_option( 'page_for_posts', $post_id );
|
||||
$caps = map_meta_cap( 'delete_page', $this->user_id, $post_id );
|
||||
delete_option( 'page_for_posts' );
|
||||
|
||||
$this->assertEquals( array( 'manage_options' ), $caps );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user