WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#21586 closed enhancement (fixed)

Telling register_post_type to not support anything

Reported by: sc0ttkclark Owned by: nacin
Milestone: 3.5 Priority: normal
Severity: minor Version:
Component: Posts, Post Types Keywords: has-patch commit
Focuses: Cc:

Description

As the use of WP becomes more complex, post types are getting used in more interesting ways. This is evident by a use-case for passing an empty array to the 'supports' argument. Essentially, the Post Type becomes an object relatable to taxonomies and custom fields.

If an empty array() is sent (or any empty value), WordPress currently sets the defaults to 'title' and 'editor':

http://core.trac.wordpress.org/browser/tags/3.4.1/wp-includes/post.php#L1020

I believe an alternate value should be able to passed such as false, where no defaults will get set. Currently, my work around is to pass an array, but place a faux value within it like '_placeholder'. This keeps the array from being empty and defaults set.

I'll have the patch ready by morning but feel free to provide any input positive/negative on this.

Attachments (2)

21520.patch (1.3 KB) - added by markoheijnen 3 years ago.
21586.patch (586 bytes) - added by sc0ttkclark 3 years ago.
Patch for the supports argument to be false, so as to not add support for the defaults

Download all attachments as: .zip

Change History (9)

comment:1 @sc0ttkclark3 years ago

  • Cc lol@… added

My patch would basically contain a change to this line:

http://core.trac.wordpress.org/browser/tags/3.4.1/wp-includes/post.php#L1023

} else {

to:

}
elseif ( false !== $args->supports ) {

comment:2 @markoheijnen3 years ago

Had this once and inserted the string 'false' as a value what does work since it isn't existing.

Wouldn't it be better to have array('title', 'editor') in the defaults array. That will remove the if/else check.

@markoheijnen3 years ago

comment:3 @sc0ttkclark3 years ago

  • Keywords has-patch dev-feedback added

+1 on that Marko, I had over assumed based on existing code there was a reason not to accept an empty value. Hopefully there wasn't, your solution would be best IMO.

comment:4 @sc0ttkclark3 years ago

  • Severity changed from normal to minor

Minor patch, changing to minor severity

comment:5 @nacin3 years ago

  • Keywords commit added; dev-feedback removed
  • Milestone changed from Awaiting Review to 3.5

I feel like the original purpose of a default was to use it only if no 'supports' arg was passed in at all. Setting array() should explicitly say "don't support anything."

That might break too much random code — so, false seems good for now.

@sc0ttkclark3 years ago

Patch for the supports argument to be false, so as to not add support for the defaults

comment:7 @nacin3 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [21831]:

Allow supports => false to be passed to register_post_type() to disable the default title and editor.

An empty array may also disable all default features in the future.
Do not rely on this behavior: always specify title and editor if you want them.

props sc0ttkclark.
fixes #21586.

Note: See TracTickets for help on using tickets.