Opened 2 years ago
Last modified 2 years ago
#16600 reopened defect (bug)
AdminMenu rendering code chokes on uppercase
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Administration | Version: | 3.1 |
| Severity: | minor | Keywords: | needs-codex |
| Cc: | jltallon, mikeschinkel@… |
Description
When registering custom taxonomies for a custom post type, if the post type name contains uppercase letters, the menu items for the custom taxonomies are not shown.
It looks like the post type name is lowercased in some parts of the core code (but no all) and so string comparisons fail.
Just isolated this behaviour, so I'm still not sure how much of the core this affects.
Moreover, when I saved posts with the intended mixed-case name, they have been saved to the DB with lowercased post_type
It it is indeed the intended behaviour, a note should be added to the Codex:
"Custom Post Type names must be lowercase"
The attached sample (real) code reproduces the problem by setting "post_type_tag" to "DomainName" instead of "domain_name". Numbers work properly, however.
Tested with latest SVN (RC4 + r17467)
Attachments (4)
Change History (16)
- Keywords dev-feedback removed
- Resolution set to worksforme
- Status changed from new to closed
You need to register the taxonomies before the custom post type and also you must use 'taxonomies' in register_post_type arguments.
see the attached file.
- Resolution worksforme deleted
- Severity changed from major to minor
- Status changed from closed to reopened
Thanks.
The Codex does not clearly specify that it has to be done in this order, so this would be a documentation bug.
Moreover, the fact that doing it in the order I was doing it works, but only with all-lowercase names is at the very least surprising. WP should be case-preserving and case-respecting or be documented as "case
folding". The problem being with varying behaviour and/or lack of documentation, not with the internals as such.
- Keywords needs-patch added
Okay my bad...the order doesn't matter. The taxonomies arg have done the trick.
This is a valid bug. In register_post_type the $post_type is sanitized but in register_taxonomy we are not sanitizing the $object_type array
wp-includes/post.php, line 822:
$post_type = sanitize_user($post_type, true);
( whereas taxonomy.php, line 313 reads "$args [ ' object_type ' ] = (array) $object_type;" )
The problem being that sanitize_user, in strict mode, changes the intended "custom post type name".
Moreover, it looks like a C-P-T (or taxonomy, for that matter) name shouldn't contain the 'at' sign, right?
Hence, I propose to introduce a new sanitize_object_name function (not filter) for this matter.
(patch follows)
Alternative b) just use "sanitize key" for register_taxonomy (just like it is done in post.php, line 916)
Unless there is a compelling reason to do so, I think WP should be case-preserving and case-sensitive for user-defined Post-Types and Taxonomies.
Implement 'sanitize_objectname' and use it for register_post_type and register_taxonomy
- Keywords dev-feedback added
Instead of creating a new function we can just array_map to sanitize_key.
- Keywords needs-codex added; needs-patch dev-feedback removed
Let's start with a note added to the Codex page.
Yes, the documentation piece is needed anyway.
Noted that sanitize_key is a bit too expensive. My "sanitize_objectname" could be made simpler.
Moreover, I did not use sanitize_key (in fact, I replaced its usage for register_object_type) since it wraps names to lowercase, and I wanted it to be case-preserving.
Call the function whatever you like, but (IMHO) we should allow [A-Za-z0-9_] (i.e. "identifier" as in most programming languages) for custom post types and custom taxonomies.
comment:10
ocean90 — 2 years ago
Duplicate: #16649
comment:11
mikeschinkel — 2 years ago
- Cc mikeschinkel@… added
I'd love to see lowercase as a requirement for taxonomy and post type names. They are, after all, internal names and not named for display to the user. having them be lowercase means it's easier to ensure our code can sanitize them. FWIW.
comment:12
scribu — 2 years ago
+1 on case folding, for both post types and taxonomies.

Test case for "C-P-T case sensitivity" - 'DomainName' vs 'domainname'