Make WordPress Core

Opened 14 years ago

Last modified 6 years ago

#16600 reopened defect (bug)

AdminMenu rendering code chokes on uppercase

Reported by: jltallon's profile jltallon Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.1
Component: Posts, Post Types Keywords: needs-patch needs-codex
Focuses: administration Cc:

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)

cpt_test.php (2.1 KB) - added by jltallon 14 years ago.
Test case for "C-P-T case sensitivity" - 'DomainName' vs 'domainname'
cpt_test.2.php (2.2 KB) - added by greuben 14 years ago.
patch.16600a.diff (3.6 KB) - added by jltallon 14 years ago.
Implement 'sanitize_objectname' and use it for register_post_type and register_taxonomy
16600.diff (472 bytes) - added by greuben 14 years ago.

Download all attachments as: .zip

Change History (21)

@jltallon
14 years ago

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

@greuben
14 years ago

#1 @greuben
14 years ago

  • 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.

#2 @jltallon
14 years ago

  • 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.

#3 @greuben
14 years ago

  • 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

#4 @jltallon
14 years ago

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)

#5 @jltallon
14 years ago

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.

@jltallon
14 years ago

Implement 'sanitize_objectname' and use it for register_post_type and register_taxonomy

@greuben
14 years ago

#6 @greuben
14 years ago

  • Keywords dev-feedback added

Instead of creating a new function we can just array_map to sanitize_key.

#7 @duck_
14 years ago

See #14910 and #15982 as to why we cannot just replace with sanitize_key.

#8 @nacin
14 years ago

  • Keywords needs-codex added; needs-patch dev-feedback removed

Let's start with a note added to the Codex page.

#9 @jltallon
14 years ago

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.

#10 @ocean90
14 years ago

Duplicate: #16649

#11 @mikeschinkel
14 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.

#12 @scribu
14 years ago

+1 on case folding, for both post types and taxonomies.

#13 follow-up: @c3mdigital
11 years ago

  • Keywords close added; needs-codex removed
  • Resolution set to invalid
  • Status changed from reopened to closed

Fixed in #16649

#14 in reply to: ↑ 13 @helen
11 years ago

Replying to c3mdigital:

Fixed in #16649

#16649 was closed as a dupe of this one...

#15 @ocean90
11 years ago

  • Keywords close removed
  • Resolution invalid deleted
  • Status changed from closed to reopened

#16 @chriscct7
9 years ago

  • Keywords needs-patch added

#17 @swissspidy
9 years ago

  • Component changed from Administration to Posts, Post Types
  • Focuses administration added
  • Keywords needs-codex added
Note: See TracTickets for help on using tickets.