Make WordPress Core

Ticket #17253: 17253-2.diff

File 17253-2.diff, 3.4 KB (added by knutsp, 11 years ago)

Patch to add capabilities for authors vs. pages, including tests

  • src/wp-admin/includes/schema.php

     
    595595        populate_roles_270();
    596596        populate_roles_280();
    597597        populate_roles_300();
     598        populate_roles_430();
    598599}
    599600
    600601/**
     
    843844}
    844845
    845846/**
     847 * Create and modify WordPress roles for WordPress 4.3.
     848 *
     849 * @since 4.3.0
     850 */
     851function populate_roles_430() {
     852        $role = get_role( 'author' );
     853
     854        if ( !empty( $role ) ) {
     855                $role->add_cap( 'edit_pages' );
     856                $role->add_cap( 'publish_pages' );
     857                $role->add_cap( 'edit_published_pages' );
     858                $role->add_cap( 'delete_pages' );
     859                $role->add_cap( 'delete_published_pages' );
     860        }
     861}
     862
     863/**
    846864 * Install Network.
    847865 *
    848866 * @since 3.0.0
  • tests/phpunit/tests/user/capabilities.php

     
    8989                $this->assertTrue($user->has_cap('upload_files'));
    9090                $this->assertTrue($user->has_cap('level_2'));
    9191
     92                // extra author capabilities added in WordPress 4.3, @ticket 17253
     93                $this->assertTrue( $user->has_cap( 'edit_pages' ) );
     94                $this->assertTrue( $user->has_cap( 'publish_pages' ) );
     95                $this->assertTrue( $user->has_cap( 'edit_published_pages' ) );
     96                $this->assertTrue( $user->has_cap( 'delete_pages' ) );
     97                $this->assertTrue( $user->has_cap( 'delete_published_pages' ) );
     98
    9299                // and a few capabilities this user doesn't have
    93100                $this->assertFalse($user->has_cap('moderate_comments'));
    94101                $this->assertFalse($user->has_cap('manage_categories'));
     
    634641                $editor = new WP_User( $this->factory->user->create( array( 'role' => 'editor' ) ) );
    635642                $contributor = new WP_User( $this->factory->user->create( array( 'role' => 'contributor' ) ) );
    636643
    637                 // administrators, editors and the post owner can edit it
     644                // administrators, editors and the page owner can edit it
    638645                $this->assertTrue($admin->has_cap('edit_page', $page));
    639646                $this->assertTrue($editor->has_cap('edit_page', $page));
     647                $this->assertTrue($author->has_cap('edit_page', $page));
    640648                // other authors and contributors can't
    641                 $this->assertFalse($author->has_cap('edit_page', $page));
    642649                $this->assertFalse($author_2->has_cap('edit_page', $page));
    643650                $this->assertFalse($contributor->has_cap('edit_page', $page));
    644651
    645                 // administrators, editors and the post owner can delete it
     652                // administrators, editors and the page owner can delete it
    646653                $this->assertTrue($admin->has_cap('delete_page', $page));
    647654                $this->assertTrue($editor->has_cap('delete_page', $page));
     655                $this->assertTrue($editor->has_cap('delete_page', $page));
    648656                // other authors and contributors can't
    649657                $this->assertFalse($author->has_cap('delete_page', $page));
    650658                $this->assertFalse($author_2->has_cap('delete_page', $page));
    651659                $this->assertFalse($contributor->has_cap('delete_page', $page));
     660
     661                // administrators, editors, and authors can publish it
     662                $this->assertTrue($admin->has_cap('publish_page', $page));
     663                $this->assertTrue($editor->has_cap('publish_page', $page));
     664                $this->assertTrue($author->has_cap('publish_page', $page));
     665                $this->assertTrue($author_2->has_cap('publish_page', $page));
     666                // contributors can't
     667                $this->assertFalse($contributor->has_cap('publish_page', $page));
    652668        }
    653669
    654670        /**