WordPress.org

Make WordPress Core

Ticket #30991: 30991.5.diff

File 30991.5.diff, 3.6 KB (added by Mte90, 2 years ago)

final patch with tests

  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index 491fc666a4..bd5768bedb 100644
    function unregister_post_type( $post_type ) { 
    14851485 * Otherwise, an 's' will be added to the value for the plural form. After
    14861486 * registration, capability_type will always be a string of the singular value.
    14871487 *
    1488  * By default, seven keys are accepted as part of the capabilities array:
     1488 * By default, eight keys are accepted as part of the capabilities array:
    14891489 *
    14901490 * - edit_post, read_post, and delete_post are meta capabilities, which are then
    14911491 *   generally mapped to corresponding primitive capabilities depending on the
    function unregister_post_type( $post_type ) { 
    14971497 * - edit_others_posts - Controls whether objects of this type owned by other users
    14981498 *   can be edited. If the post type does not support an author, then this will
    14991499 *   behave like edit_posts.
     1500 * - delete_posts - Controls whether objects of this post type can be deleted.
    15001501 * - publish_posts - Controls publishing objects of this post type.
    15011502 * - read_private_posts - Controls whether private objects can be read.
    15021503 *
    15031504 * These four primitive capabilities are checked in core in various locations.
    1504  * There are also seven other primitive capabilities which are not referenced
     1505 * There are also six other primitive capabilities which are not referenced
    15051506 * directly in core, except in map_meta_cap(), which takes the three aforementioned
    15061507 * meta capabilities and translates them into one or more primitive capabilities
    15071508 * that must then be checked against the user or role, depending on the context.
    15081509 *
    15091510 * - read - Controls whether objects of this post type can be read.
    1510  * - delete_posts - Controls whether objects of this post type can be deleted.
    15111511 * - delete_private_posts - Controls whether private objects can be deleted.
    15121512 * - delete_published_posts - Controls whether published objects can be deleted.
    15131513 * - delete_others_posts - Controls whether objects owned by other users can be
    function get_post_type_capabilities( $args ) { 
    15411541                'edit_post'          => 'edit_' . $singular_base,
    15421542                'read_post'          => 'read_' . $singular_base,
    15431543                'delete_post'        => 'delete_' . $singular_base,
     1544                'delete_posts'       => 'delete_' . $plural_base,
    15441545                // Primitive capabilities used outside of map_meta_cap():
    15451546                'edit_posts'         => 'edit_' . $plural_base,
    15461547                'edit_others_posts'  => 'edit_others_' . $plural_base,
    function get_post_type_capabilities( $args ) { 
    15521553        if ( $args->map_meta_cap ) {
    15531554                $default_capabilities_for_mapping = array(
    15541555                        'read'                   => 'read',
    1555                         'delete_posts'           => 'delete_' . $plural_base,
    15561556                        'delete_private_posts'   => 'delete_private_' . $plural_base,
    15571557                        'delete_published_posts' => 'delete_published_' . $plural_base,
    15581558                        'delete_others_posts'    => 'delete_others_' . $plural_base,
  • tests/phpunit/tests/user/mapMetaCap.php

    diff --git tests/phpunit/tests/user/mapMetaCap.php tests/phpunit/tests/user/mapMetaCap.php
    index dc67dfeef9..5ce1a19a1a 100644
    class Tests_User_MapMetaCap extends WP_UnitTestCase { 
    8282                        array( 'delete_others_posts', 'delete_private_posts' ),
    8383                        map_meta_cap( 'delete_post', self::$user_id, self::$post_id )
    8484                );
     85                $this->assertEquals(
     86                        array( 'delete_posts' ),
     87                        map_meta_cap( $post_type_object->cap->delete_posts, self::$user_id, self::$post_id )
     88                );
    8589                $this->assertEquals(
    8690                        array( 'delete_others_posts', 'delete_private_posts' ),
    8791                        map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id )