From 344c88d39fc951769c6aea6365bca62987e7558a Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sat, 20 Aug 2016 17:35:31 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@38292 git-svn-id: http://core.svn.wordpress.org/trunk@38233 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 14 ++++++++++---- wp-includes/taxonomy.php | 2 +- wp-includes/version.php | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index bc7a90ced8..4eb2886205 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -2694,11 +2694,15 @@ function adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) * Retrieves taxonomies attached to given the attachment. * * @since 2.5.0 + * @since 4.7.0 Introduced the `$output` parameter. * * @param int|array|object $attachment Attachment ID, data array, or data object. + * @param string $output Output type. 'names' to return an array of taxonomy names, + * or 'objects' to return an array of taxonomy objects. + * Default is 'names'. * @return array Empty array on failure. List of taxonomies on success. */ -function get_attachment_taxonomies( $attachment ) { +function get_attachment_taxonomies( $attachment, $output = 'names' ) { if ( is_int( $attachment ) ) { $attachment = get_post( $attachment ); } elseif ( is_array( $attachment ) ) { @@ -2723,9 +2727,11 @@ function get_attachment_taxonomies( $attachment ) { } $taxonomies = array(); - foreach ( $objects as $object ) - if ( $taxes = get_object_taxonomies($object) ) - $taxonomies = array_merge($taxonomies, $taxes); + foreach ( $objects as $object ) { + if ( $taxes = get_object_taxonomies( $object, $output ) ) { + $taxonomies = array_merge( $taxonomies, $taxes ); + } + } return array_unique($taxonomies); } diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 70af35a326..20ae20f611 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -181,7 +181,7 @@ function get_object_taxonomies( $object, $output = 'names' ) { if ( is_object($object) ) { if ( $object->post_type == 'attachment' ) - return get_attachment_taxonomies($object); + return get_attachment_taxonomies( $object, $output ); $object = $object->post_type; } diff --git a/wp-includes/version.php b/wp-includes/version.php index d18a4a6e0c..2bc559d81c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-alpha-38291'; +$wp_version = '4.7-alpha-38292'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.