Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#31500 closed defect (bug) (duplicate)

New post type undefined delete post value

Reported by: ozzwanted's profile ozzWANTED Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.1
Component: Posts, Post Types Keywords:
Focuses: ui, administration Cc:

Description

I have WP_DEBUG = TRUE on my localhost.

I registered new post type for my plugin. And then went to WP ADMIN -> MENU -> CARS. And in the list of 'cars' (no items added) I see this warning:
Notice: Undefined property: stdClass::$delete_posts in C:\Program Files (x86)\Zend\Apache2\htdocs\GitHub\*WEBSITE-NAME*\wp-admin\includes\class-wp-posts-list-table.php on line 209

Change History (13)

#1 follow-up: @DrewAPicture
10 years ago

  • Keywords reporter-feedback added

Hi ozzWANTED,

Can you provide your post type registration code so we can attempt to reproduce your issue?

#2 @SergeyBiryukov
10 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 4.2

I can reproduce with 'map_meta_cap' => false. Introduced in [29757].

The Codex page says: "There are also seven other primitive capabilities which are not referenced directly in core, except in map_meta_cap()..."

That is no longer true since [29757].

#3 in reply to: ↑ 1 @ozzWANTED
10 years ago

Replying to DrewAPicture:

Hi ozzWANTED,

Can you provide your post type registration code so we can attempt to reproduce your issue?

Here you go my friend:

function crs_custom_post_type_init()
{
	$menu_position1 = 95;
	$icon_url = plugins_url().'/car-rental-system/images/plugin.ico';

	// Set UI labels for Custom Post Type
	$labels = array(
		'name'                => _x( 'Car Descriptions', 'Post Type General Name', 'car-rental-system' ),
		'singular_name'       => _x( 'Car Description', 'Post Type Singular Name', 'car-rental-system' ),
		'menu_name'           => __( 'Car Descriptions', 'car-rental-system' ),
		'parent_item_colon'   => __( 'Parent Car', 'car-rental-system' ),
		'all_items'           => __( 'All Car Descriptions', 'car-rental-system' ),
		'view_item'           => __( 'View Car Description', 'car-rental-system' ),
		'add_new_item'        => __( 'Add New Car Description', 'car-rental-system' ),
		'add_new'             => __( 'Add New Description', 'car-rental-system' ),
		'edit_item'           => __( 'Edit Car Description', 'car-rental-system' ),
		'update_item'         => __( 'Update Car Description', 'car-rental-system' ),
		'search_items'        => __( 'Search Car Description', 'car-rental-system' ),
		'not_found'           => __( 'Not Found', 'car-rental-system' ),
		'not_found_in_trash'  => __( 'Not found in Trash', 'car-rental-system' ),
	);

	// Set other options for Custom Post Type
	$args = array(
		'label'               => __( 'cars', 'car-rental-system' ),
		'description'         => __( 'List of cars descriptions', 'car-rental-system' ),
		'labels'              => $labels,
		// Features this CPT supports in Post Editor
		'supports'            => array( 'title', 'editor', 'author', 'thumbnail', ),
		/* A hierarchical CPT is like Pages and can have
		* Parent and child items. A non-hierarchical CPT
		* is like Posts.
		*/
		'hierarchical'        => false,
		'public'              => true,
		'show_ui'             => true,
		'show_in_menu'        => true,
		'show_in_nav_menus'   => true,
		'show_in_admin_bar'   => true,
		'menu_position'       => $menu_position1,
		'menu_icon'			  => $icon_url,
		'can_export'          => true,
		'has_archive'         => false,
		'rewrite'			  => array(
			// TRANSLATION IS A MUST
			'slug' => 'automobiliai',
			'with_front' => false,
			'pages' => false,
		),
		'exclude_from_search' => false,
		'publicly_queryable'  => true,
		/* To manage specific rights to edit only cars*/
		'capability_type'     => 'car',
	);

	// Registering your Custom Post Type
	register_post_type( 'cars', $args );
}

#4 follow-up: @valendesigns
10 years ago

@ozzWANTED Have you setup the delete_posts and other custom capabilities for car somewhere else in your code, since you have 'capability_type' => 'car' in your arguments array?

#5 in reply to: ↑ 4 @ozzWANTED
10 years ago

Replying to valendesigns:

@ozzWANTED Have you setup the delete_posts and other custom capabilities for car somewhere else in your code, since you have 'capability_type' => 'car' in your arguments array?

Probably I don't setup that anywhere else. Should I? Can you give of example code so that I could do 'search' in my PhpStorm project. But my first guess that there is no other definition for it. I thought it was the place to define it.

#6 @valendesigns
10 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

This is a question for the forums and is beyond the scope of Trac. Short answer, set it to post until you find the answer you're looking for on adding custom capabilities. I'm closing this as worksforme, because everything works when you have capability_type set to post. Cheers!

#7 @ozzWANTED
10 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

Well, it still doesn't work if I do set map_meta_cap to false, trying to hide add/edit buttons

'capability_type'     => 'post',
'map_meta_cap'        => false, // Set to false, if users are not allowed to edit/delete existing posts

Erorr:

Notice: Undefined property: stdClass::$delete_posts in C:\Program Files (x86)\Zend\Apache2
\htdocs\GitHub\**WEB***\wp-admin\includes\class-wp-posts-list-table.php on line 209
Last edited 10 years ago by ozzWANTED (previous) (diff)

#8 follow-up: @valendesigns
10 years ago

  • Resolution set to worksforme
  • Status changed from reopened to closed

@ozzWANTED This is still working correctly in Core, what is not working correctly is your combination of arguments. Unless you are planning on creating your own custom meta capabilities setting map_meta_cap to false is essentially removing all the post capabilities. Therefore, you either need to set map_meta_cap to true or roll out your own capabilities.

#9 in reply to: ↑ 8 @ozzWANTED
10 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

Replying to valendesigns:

@ozzWANTED This is still working correctly in Core, what is not working correctly is your combination of arguments. Unless you are planning on creating your own custom meta capabilities setting map_meta_cap to false is essentially removing all the post capabilities. Therefore, you either need to set map_meta_cap to true or roll out your own capabilities.

Well, it doesn't work even then. If I map these capiblities, still gives me the same error.

This code gives an error:

		'capability_type'     => 'car',
		'map_meta_cap'        => false, // Set to false, if users are not allowed to edit/delete existing posts
		'capabilities' => array(
			'read'
		),

This code also gives an error:

		'capability_type'     => 'post',
		'map_meta_cap'        => false, // Set to false, if users are not allowed to edit/delete existing posts
		'capabilities' => array(
			'read'
		),
Last edited 10 years ago by ozzWANTED (previous) (diff)

#10 follow-up: @SergeyBiryukov
10 years ago

  • Keywords reporter-feedback removed

This was a regression introduced in [29757], see comment:2.

We need to decide what the correct fix is, please don't close as worksforme.

#11 in reply to: ↑ 10 @valendesigns
10 years ago

Replying to SergeyBiryukov:

This was a regression introduced in [29757], see comment:2.

We need to decide what the correct fix is, please don't close as worksforme.

Sorry about that. The code above looked like it was the cause of the issue for this particular situation and could be solved by changing it accordingly. Apologies for the confusion.

It seems like we should be fixing the regression in the original ticket that introduced it or is that not the process?

#12 @valendesigns
10 years ago

  • Resolution set to duplicate
  • Status changed from reopened to closed

Duplicate of #30991.

There's already a ticket and patch for this issue.

#13 @DrewAPicture
10 years ago

  • Keywords needs-patch removed
  • Milestone 4.2 deleted
Note: See TracTickets for help on using tickets.