#13709 closed defect (bug) (fixed)
Post type name should be limited to 20 chars in register_post_type()
Reported by: | phrostypoison | Owned by: | |
---|---|---|---|
Milestone: | 3.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | |
Focuses: | Cc: |
Description
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 kovshenin.org's Podcasts post_type plugin example (see http://kovshenin.com/archives/extending-custom-post-types-in-wordpress-3-0/).
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;
into
$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)
Change History (11)
#5
@
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.
#7
@
14 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.
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.