Changeset 38292
- Timestamp:
- 08/20/2016 05:34:13 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r38086 r38292 2695 2695 * 2696 2696 * @since 2.5.0 2697 * @since 4.7.0 Introduced the `$output` parameter. 2697 2698 * 2698 2699 * @param int|array|object $attachment Attachment ID, data array, or data object. 2700 * @param string $output Output type. 'names' to return an array of taxonomy names, 2701 * or 'objects' to return an array of taxonomy objects. 2702 * Default is 'names'. 2699 2703 * @return array Empty array on failure. List of taxonomies on success. 2700 2704 */ 2701 function get_attachment_taxonomies( $attachment ) {2705 function get_attachment_taxonomies( $attachment, $output = 'names' ) { 2702 2706 if ( is_int( $attachment ) ) { 2703 2707 $attachment = get_post( $attachment ); … … 2724 2728 2725 2729 $taxonomies = array(); 2726 foreach ( $objects as $object ) 2727 if ( $taxes = get_object_taxonomies($object) ) 2728 $taxonomies = array_merge($taxonomies, $taxes); 2730 foreach ( $objects as $object ) { 2731 if ( $taxes = get_object_taxonomies( $object, $output ) ) { 2732 $taxonomies = array_merge( $taxonomies, $taxes ); 2733 } 2734 } 2729 2735 2730 2736 return array_unique($taxonomies); -
trunk/src/wp-includes/taxonomy.php
r38277 r38292 182 182 if ( is_object($object) ) { 183 183 if ( $object->post_type == 'attachment' ) 184 return get_attachment_taxonomies( $object);184 return get_attachment_taxonomies( $object, $output ); 185 185 $object = $object->post_type; 186 186 } -
trunk/tests/phpunit/tests/media/getAttachmentTaxonomies.php
r38291 r38292 80 80 $this->assertSame( $expected, $found ); 81 81 } 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 } 82 101 } -
trunk/tests/phpunit/tests/taxonomy/getObjectTaxonomies.php
r38290 r38292 46 46 $this->assertSame( $expected, $found ); 47 47 } 48 49 /** 50 * @ticket 37368 51 */ 52 public function test_should_return_all_attachment_taxonomies_for_attachment_object_type() { 53 register_taxonomy( 'wptests_tax2', 'attachment:image' ); 54 55 $a = self::factory()->attachment->create_object( 'image.jpg', 0, array( 56 'post_mime_type' => 'image/jpeg', 57 'post_type' => 'attachment' 58 ) ); 59 $attachment = get_post( $a ); 60 61 $found = get_object_taxonomies( $attachment, 'names' ); 62 63 $this->assertSame( array( 'wptests_tax2' ), $found ); 64 } 65 66 /** 67 * @ticket 37368 68 */ 69 public function test_should_respect_output_objects_when_object_is_attachment() { 70 register_taxonomy( 'wptests_tax2', 'attachment:image' ); 71 72 $a = self::factory()->attachment->create_object( 'image.jpg', 0, array( 73 'post_mime_type' => 'image/jpeg', 74 'post_type' => 'attachment' 75 ) ); 76 $attachment = get_post( $a ); 77 78 $found = get_object_taxonomies( $attachment, 'objects' ); 79 80 $this->assertSame( array( 'wptests_tax2' ), array_keys( $found ) ); 81 $this->assertInternalType( 'object', $found['wptests_tax2'] ); 82 $this->assertSame( 'wptests_tax2', $found['wptests_tax2']->name ); 83 } 48 84 }
Note: See TracChangeset
for help on using the changeset viewer.