Make WordPress Core

Ticket #36227: 36227.diff

File 36227.diff, 1.3 KB (added by boonebgorges, 10 years ago)
  • src/wp-includes/category.php

    diff --git a/src/wp-includes/category.php b/src/wp-includes/category.php
    index cbef474..a89b410 100644
    a b function get_categories( $args = '' ) { 
    5151                $taxonomy = $args['taxonomy'] = 'link_category';
    5252        }
    5353
    54         $categories = (array) get_terms( $taxonomy, $args );
     54        $categories = get_terms( $taxonomy, $args );
    5555
    56         foreach ( array_keys( $categories ) as $k )
    57                 _make_cat_compat( $categories[$k] );
     56        if ( is_wp_error( $categories ) ) {
     57                $categories = array();
     58        } else {
     59                $categories = (array) $categories;
     60                foreach ( array_keys( $categories ) as $k ) {
     61                        _make_cat_compat( $categories[ $k ] );
     62                }
     63        }
    5864
    5965        return $categories;
    6066}
  • new file tests/phpunit/tests/category/getCategories.php

    diff --git a/tests/phpunit/tests/category/getCategories.php b/tests/phpunit/tests/category/getCategories.php
    new file mode 100644
    index 0000000..3f2140d
    - +  
     1<?php
     2
     3/**
     4 * @group taxonomy
     5 * @group category.php
     6 */
     7class Tests_Category_GetCategories extends WP_UnitTestCase {
     8        /**
     9         * @ticket 36227
     10         */
     11        public function test_wp_error_should_return_an_empty_array() {
     12                $found = get_categories( array( 'taxonomy' => 'foo' ) );
     13                $this->assertSame( array(), $found );
     14        }
     15}