Make WordPress Core

Ticket #28145: 28145.diff

File 28145.diff, 1.6 KB (added by MikeHansenMe, 11 years ago)

patch based on suggestion, includes unit test

  • tests/phpunit/tests/admin/includesTemplate.php

     
    4545                $this->assertEquals('', selected(0,false,false));
    4646                $this->assertEquals('', checked(0,false,false));
    4747        }
     48
     49        function test_wp_terms_checklist_decendants_and_self() {
     50                ob_start();
     51                wp_terms_checklist( 0, array( 'decendants_and_self' => 1 ) );
     52                $actual = ob_get_clean();
     53                $expected = "\n<li id='category-1'><label class=\"selectit\"><input value=\"1\" type=\"checkbox\" name=\"post_category[]\" id=\"in-category-1\" disabled='disabled' /> Uncategorized</label></li>\n";
     54                $this->assertSame( $actual, $expected );
     55        }
    4856}
  • src/wp-admin/includes/template.php

     
    202202                ) );
    203203        }
    204204        if ( $descendants_and_self ) {
    205                 $categories = (array) get_terms( $taxonomy, array(
    206                         'child_of' => $descendants_and_self,
    207                         'hierarchical' => 0,
    208                         'hide_empty' => 0
    209                 ) );
     205               
     206                if( is_taxonomy_hierarchical( $taxonomy ) ) {
     207                        $categories = (array) get_terms( $taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) );
     208                } else {
     209                        $categories = array();
     210                }
     211               
    210212                $self = get_term( $descendants_and_self, $taxonomy );
    211213                array_unshift( $categories, $self );
    212214        } else {