Make WordPress Core

Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#13709 closed defect (bug) (fixed)

Post type name should be limited to 20 chars in register_post_type()

Reported by: phrostypoison's profile phrostypoison Owned by:
Milestone: 3.1 Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:


I was in the process of making a plugin for WordPress 3.0 that utilizes a custom post_type with the name 'designtags_stylesheet', but when I activated the plugin, although the UI would show up properly, the publish button showed 'Submit for Review' instead of the usual 'publish'. Furthermore, if I do click on the button, WordPress spits out an error and does nothing.

The same situation didn't occur with's Podcasts post_type plugin example (see

It turns out the cause of the problem was the length of the post_type name. After looking into the database schema of the wp_posts table, the post_type column has a 20-character limit. 'designtags_stylesheet' is more than 20 chars long, so WordPress refuses to publish.

If the post_type column is to stay as a varchar(20) after custom post_type support, register_post_type() should spit an error if a plugin attempts to register a post_type that has a name over 20 chars long.

Maybe change these lines

	$post_type = sanitize_user($post_type, true);
	$args->name = $post_type;


	$post_type = sanitize_user($post_type, true);
	if ( strlen($post_type) > 20)
		return new WP_Error('invalid_post_type', __('Invalid post type name.'));
	$args->name = $post_type;

Thank you!

Attachments (1)

13709.patch (414 bytes) - added by johnpbloch 14 years ago.

Download all attachments as: .zip

Change History (11)

#1 @nacin
14 years ago

I can't think of an obvious place where we check against the schema, I imagine somewhat rooted in portability. Related is a ticket that probably does deserve a schema sanity check: #11959.

#2 @kovshenin
14 years ago

Offtopic, but it's sir, not .org ;)

#3 @kevinB
14 years ago

  • Cc kevinB added

#4 @nacin
14 years ago

  • Milestone changed from Awaiting Review to 3.1

14 years ago

#5 @johnpbloch
14 years ago

My patch is a pretty quick and simple fix. I don't think it's necessary to send a warning to the user, since we already potentially change the post_type key with sanitize_key(). The problem, as I understand it, is that this bug breaks WordPress without making it clear that the length of the post_type name is the issue (i.e. almost all user-facing uses of the post_type name use the name in its full and invalid length). Trimming the key at registration fixes that problem and would remove the confusion.

#6 @johnpbloch
14 years ago

  • Cc johnpbloch added

#7 @markjaquith
13 years ago

johnpbloch — the problem is that there are many places where you can provide a post type, and your patch would just sanitize one of them. I'd rather let people know what's going on so they can choose a better post type name.

#8 @markjaquith
13 years ago

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

(In [16650]) Throw WP_Error if post_type passed to register_post_type() is longer than schema allows. props phrostypoison. fixes #13709

#9 @markjaquith
13 years ago

(In [16668]) Doh. [16646] and [16650] were made against the wrong branch. Revert. see #13709. see #15621

#10 @automattor
13 years ago

(In [16670]) Throw WP_Error if post_type passed to register_post_type() is longer than schema allows. props phrostypoison. fixes #13709

Note: See TracTickets for help on using tickets.