Make WordPress Core

Changeset 38437


Ignore:
Timestamp:
08/30/2016 03:06:06 AM (8 years ago)
Author:
boonebgorges
Message:

Remove unnecessary uniqueness check in get_attachment_taxonomies().

Running the taxonomy array through array_unique() is unnecessary
when the function returns objects, because the associative keys already
ensure uniqueness.

This also fixes a bug when running get_attachment_taxonomies() in
HHVM, which doesn't like casting objects to strings for the purposes
of array_unique().

Props swissspidy.
See #37368.

Location:
trunk
Files:
2 edited

Legend:

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

    r38411 r38437  
    27502750    }
    27512751
    2752     return array_unique($taxonomies);
     2752    if ( 'names' === $output ) {
     2753        $taxonomies = array_unique( $taxonomies );
     2754    }
     2755
     2756    return $taxonomies;
    27532757}
    27542758
  • trunk/tests/phpunit/tests/media/getAttachmentTaxonomies.php

    r38292 r38437  
    9999        $this->assertSame( 'wptests_tax2', $found['wptests_tax2']->name );
    100100    }
     101
     102
     103    /**
     104     * @ticket 37368
     105     */
     106    public function test_should_return_unique_taxonomies_for_output_objects() {
     107        register_taxonomy( 'wptests_tax2', array( 'attachment:image', 'attachment:image/jpeg' ) );
     108
     109        $a = self::factory()->attachment->create_object( 'image.jpg', 0, array(
     110            'post_mime_type' => 'image/jpeg',
     111            'post_type' => 'attachment'
     112        ) );
     113        $attachment = get_post( $a );
     114
     115        $found = get_attachment_taxonomies( $attachment, 'objects' );
     116
     117        $this->assertSame( array( 'wptests_tax2' ), array_keys( $found ) );
     118        $this->assertInternalType( 'object', $found['wptests_tax2'] );
     119        $this->assertSame( 'wptests_tax2', $found['wptests_tax2']->name );
     120    }
    101121}
Note: See TracChangeset for help on using the changeset viewer.