diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php
index 4b423b4606..f201b36c25 100644
--- a/src/wp-includes/taxonomy.php
+++ b/src/wp-includes/taxonomy.php
@@ -3712,39 +3712,43 @@ function the_taxonomies($args = array()) {
* @param array $args Override the defaults.
* @return array
*/
-function get_the_taxonomies($post = 0, $args = array() ) {
+function get_the_taxonomies( $post = 0, $args = array() ) {
$post = get_post( $post );
$args = wp_parse_args( $args, array(
'template' => '%s: %l.',
) );
- extract( $args, EXTR_SKIP );
$taxonomies = array();
- if ( !$post )
+ if ( ! $post ) {
return $taxonomies;
+ }
- foreach ( get_object_taxonomies($post) as $taxonomy ) {
- $t = (array) get_taxonomy($taxonomy);
- if ( empty($t['label']) )
+ foreach ( get_object_taxonomies( $post ) as $taxonomy ) {
+ $t = (array) get_taxonomy( $taxonomy );
+ if ( empty( $t['label'] ) ) {
$t['label'] = $taxonomy;
- if ( empty($t['args']) )
+ }
+ if ( empty( $t['args'] ) ) {
$t['args'] = array();
- if ( empty($t['template']) )
- $t['template'] = $template;
-
- $terms = get_object_term_cache($post->ID, $taxonomy);
- if ( false === $terms )
- $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
+ }
+ if ( empty( $t['template'] ) ) {
+ $t['template'] = $args['template'];
+ }
+ $terms = get_object_term_cache( $post->ID, $taxonomy );
+ if ( false === $terms ) {
+ $terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] );
+ }
$links = array();
- foreach ( $terms as $term )
- $links[] = "$term->name";
-
- if ( $links )
- $taxonomies[$taxonomy] = wp_sprintf($t['template'], $t['label'], $links, $terms);
+ foreach ( $terms as $term ) {
+ $links[] = "$term->name";
+ }
+ if ( $links ) {
+ $taxonomies[$taxonomy] = wp_sprintf( $t['template'], $t['label'], $links, $terms );
+ }
}
return $taxonomies;
}
diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php
index 7e4986b62f..fbab63f2a4 100644
--- a/tests/phpunit/tests/taxonomy.php
+++ b/tests/phpunit/tests/taxonomy.php
@@ -33,6 +33,22 @@ class Tests_Taxonomy extends WP_UnitTestCase {
}
}
+ function test_get_the_taxonomies() {
+ $post_id = $this->factory->post->create();
+
+ $taxes = get_the_taxonomies( $post_id );
+ $this->assertNotEmpty( $taxes );
+ $this->assertEquals( array( 'category' ), array_keys( $taxes ) );
+
+ $id = $this->factory->tag->create();
+ wp_set_post_tags( $post_id, array( $id ) );
+
+ $taxes = get_the_taxonomies( $post_id );
+ $this->assertNotEmpty( $taxes );
+ $this->assertCount( 2, $taxes );
+ $this->assertEquals( array( 'category', 'post_tag' ), array_keys( $taxes ) );
+ }
+
function test_get_link_taxonomy() {
foreach ( get_object_taxonomies('link') as $taxonomy ) {
$tax = get_taxonomy($taxonomy);