Make WordPress Core


Ignore:
Timestamp:
03/26/2008 06:37:19 AM (18 years ago)
Author:
ryan
Message:

Taxonomy links and template tags from andy. see #6357

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/media.php

    r7516 r7520  
    439439}
    440440
     441function get_attachment_taxonomies($attachment) {
     442        if ( is_int( $attachment ) )
     443                $attachment = get_post($attachment);
     444        else if ( is_array($attachment) )
     445                $attachment = (object) $attachment;
     446
     447        if ( ! is_object($attachment) )
     448                return array();
     449
     450        $filename = basename($attachment->guid);
     451
     452        $objects = array('attachment');
     453
     454        if ( false !== strpos($filename, '.') )
     455                $objects[] = 'attachment:' . substr($filename, strrpos($filename, '.') + 1);
     456        if ( !empty($attachment->post_mime_type) ) {
     457                $objects[] = 'attachment:' . $attachment->post_mime_type;
     458                if ( false !== strpos($attachment->post_mime_type, '/') )
     459                        foreach ( explode('/', $attachment->post_mime_type) as $token )
     460                                if ( !empty($token) )
     461                                        $objects[] = "attachment:$token";
     462        }
     463
     464        $taxonomies = array();
     465        foreach ( $objects as $object )
     466                if ( $taxes = get_object_taxonomies($object) )
     467                        $taxonomies = array_merge($taxonomies, $taxes);
     468
     469        return array_unique($taxonomies);
     470}
     471
    441472?>
Note: See TracChangeset for help on using the changeset viewer.