[wp-trac] [WordPress Trac] #35995: Registering taxonomies for attachment mime types

WordPress Trac noreply at wordpress.org
Mon Feb 29 05:13:32 UTC 2016


#35995: Registering taxonomies for attachment mime types
--------------------------+-----------------------------
 Reporter:  mboynes       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Taxonomy      |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 I stumbled across
 [https://core.trac.wordpress.org/browser/trunk/tests/phpunit/tests/query/taxQuery.php#L1008
 an interesting unit test] in core that led me down a bit of a rabbit hole.

 The test `test_tax_query_taxonomy_with_attachments()` in
 `phpunit/tests/query/taxQuery.php` calls:

 {{{#!php
 register_taxonomy_for_object_type( 'post_tag', 'attachment:image' );
 }}}

 I never knew that you could register a taxonomy to a mime type, so I
 looked into it, but from what I've found the support seems spotty.

 First off, calling `register_taxonomy_for_object_type( 'post_tag',
 'attachment:image' );` fails and returns `false`. As best I can tell, this
 is because `get_post_type_object( 'attachment:image' )` fails, since
 `$wp_post_types['attachment:image']` is not set. For the purposes of
 testing the query support, I added a taxonomy to an attachment mime type
 "the hard way" using the following:

 {{{#!php
 $GLOBALS['wp_taxonomies']['post_tag']->object_type[] = 'attachment:image';
 }}}

 On the querying side of the equation, support seems much better. The only
 area that's iffy is if you register a taxonomy to the `'attachment'` post
 type, but pass the mime type (e.g. `'attachment:image'`) to
 `get_object_taxonomies()`, you won't get the registered taxonomy. Since
 `attachment:image` is a subset of attachment, I would expect to get all
 the "attachment" taxonomies as well.

 Breaking this all down, the main bug here is that '''it doesn't seem to be
 possible to register a taxonomy to an attachment mime type, despite there
 being support for this feature otherwise.'''

 Side note, since the unit test
 `test_tax_query_taxonomy_with_attachments()` fails in registering a
 taxonomy to an attachment mime type, the rest of this unit test probably
 should have failed (for a couple of reasons).

--
Ticket URL: <https://core.trac.wordpress.org/ticket/35995>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list