WordPress.org

Make WordPress Core

Opened 14 months ago

Closed 14 months ago

Last modified 14 months ago

#46181 closed defect (bug) (duplicate)

Meta capabilities are not mapped completely when registering custom post type

Reported by: dingo_d Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Role/Capability Keywords:
Focuses: Cc:

Description

When you register a custom post type (CPT), and set a capability to some string, you won't have delete_posts and delete_others_posts meta capabilities present, which will cause a PHP notice:

PHP Notice: Undefined property: stdClass::$delete_posts in /public_html/wp-admin/includes/class-wp-posts-list-table.php on line 400

I registered a documentation CPT and set

<?php
add_action(
  'init',
  function() {
    register_post_type(
      'documentation',
      [
        ...,
        'capability_type' => 'documentation',
        'map_meta_cap' => false,
      ]
    );
  }
);

Instead, I need to define custom capabilities array to avoid this error (and add the two).

Shouldn't this be done automatically?

Change History (2)

#1 @swissspidy
14 months ago

  • Keywords dev-feedback 2nd-opinion removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #30991.

#2 @dingo_d
14 months ago

Flew under my radar, sorry for the duplicate :)

Note: See TracTickets for help on using tickets.