Make WordPress Core


Ignore:
Timestamp:
08/20/2016 05:34:13 PM (7 years ago)
Author:
boonebgorges
Message:

Allow attachment taxonomies to be fetched as objects.

By adding the $output parameter to get_attachment_taxonomies(), the
function signature matches that of get_object_taxonomies(). The change
also allows for more consistent behavior when passing output=objects
to get_object_taxonomies() for the 'attachment' object type, since
the $output parameter is now passed through the function stack.

Props codemovement.pk.
See #37368.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media/getAttachmentTaxonomies.php

    r38291 r38292  
    8080        $this->assertSame( $expected, $found );
    8181    }
     82
     83    /**
     84     * @ticket 37368
     85     */
     86    public function test_should_respect_output_objects() {
     87        register_taxonomy( 'wptests_tax2', 'attachment:image' );
     88
     89        $a = self::factory()->attachment->create_object( 'image.jpg', 0, array(
     90            'post_mime_type' => 'image/jpeg',
     91            'post_type' => 'attachment'
     92        ) );
     93        $attachment = get_post( $a );
     94
     95        $found = get_attachment_taxonomies( $attachment, 'objects' );
     96
     97        $this->assertSame( array( 'wptests_tax2' ), array_keys( $found ) );
     98        $this->assertInternalType( 'object', $found['wptests_tax2'] );
     99        $this->assertSame( 'wptests_tax2', $found['wptests_tax2']->name );
     100    }
    82101}
Note: See TracChangeset for help on using the changeset viewer.