WordPress.org

Make WordPress Core

Changeset 47357


Ignore:
Timestamp:
02/25/2020 12:48:11 PM (5 months ago)
Author:
SergeyBiryukov
Message:

Posts, Post Types: Ensure delete_posts is included in default post type capabilities regardless of map_meta_cap value.

This resolves PHP notices in a few places in core where this capability is checked.

Props Mte90, johnbillion, dipesh.kakadiya, jipmoors, bamadesigner, dd32, johnjamesjacoby, xedin.unknown, flixos90, SergeyBiryukov.
Fixes #30991.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r47317 r47357  
    15101510 * registration, capability_type will always be a string of the singular value.
    15111511 *
    1512  * By default, seven keys are accepted as part of the capabilities array:
     1512 * By default, eight keys are accepted as part of the capabilities array:
    15131513 *
    15141514 * - edit_post, read_post, and delete_post are meta capabilities, which are then
     
    15221522 *   can be edited. If the post type does not support an author, then this will
    15231523 *   behave like edit_posts.
     1524 * - delete_posts - Controls whether objects of this post type can be deleted.
    15241525 * - publish_posts - Controls publishing objects of this post type.
    15251526 * - read_private_posts - Controls whether private objects can be read.
    15261527 *
    1527  * These four primitive capabilities are checked in core in various locations.
    1528  * There are also seven other primitive capabilities which are not referenced
     1528 * These five primitive capabilities are checked in core in various locations.
     1529 * There are also six other primitive capabilities which are not referenced
    15291530 * directly in core, except in map_meta_cap(), which takes the three aforementioned
    15301531 * meta capabilities and translates them into one or more primitive capabilities
     
    15321533 *
    15331534 * - read - Controls whether objects of this post type can be read.
    1534  * - delete_posts - Controls whether objects of this post type can be deleted.
    15351535 * - delete_private_posts - Controls whether private objects can be deleted.
    15361536 * - delete_published_posts - Controls whether published objects can be deleted.
     
    15691569        'edit_posts'         => 'edit_' . $plural_base,
    15701570        'edit_others_posts'  => 'edit_others_' . $plural_base,
     1571        'delete_posts'       => 'delete_' . $plural_base,
    15711572        'publish_posts'      => 'publish_' . $plural_base,
    15721573        'read_private_posts' => 'read_private_' . $plural_base,
     
    15771578        $default_capabilities_for_mapping = array(
    15781579            'read'                   => 'read',
    1579             'delete_posts'           => 'delete_' . $plural_base,
    15801580            'delete_private_posts'   => 'delete_private_' . $plural_base,
    15811581            'delete_published_posts' => 'delete_published_' . $plural_base,
  • trunk/tests/phpunit/tests/user/mapMetaCap.php

    r46586 r47357  
    305305    }
    306306
     307    /**
     308     * @ticket 30991
     309     */
     310    function test_delete_posts_cap_without_map_meta_cap() {
     311        register_post_type(
     312            self::$post_type,
     313            array(
     314                'capability_type' => 'post',
     315                'map_meta_cap'    => false,
     316            )
     317        );
     318
     319        $post_type_object = get_post_type_object( self::$post_type );
     320
     321        $this->assertFalse( $post_type_object->map_meta_cap );
     322        $this->assertEquals( 'delete_posts', $post_type_object->cap->delete_posts );
     323    }
     324
    307325    function test_unfiltered_html_cap() {
    308326        if ( defined( 'DISALLOW_UNFILTERED_HTML' ) ) {
Note: See TracChangeset for help on using the changeset viewer.