Make WordPress Core

Opened 18 years ago

Closed 18 years ago

#5462 closed enhancement (fixed)

invalid nested category HTML list in admin

Reported by: 082net's profile 082net Owned by:
Milestone: 2.5 Priority: normal
Severity: normal Version: 2.3.1
Component: General Keywords: has-patch
Focuses: Cc:

Description

'dropdown_categories' function in wp-admin/includes/template.php returns invalid html list

<ul>
 <li>a</li>
 <li>b</li>
 <ul>
  <li>b-1</li>
  <li>b-2</li>
 </ul>
<li>c</li>
</ul>

It should be

<ul>
 <li>a</li>
 <li>b
 <ul>
  <li>b-1</li>
  <li>b-2</li>
 </ul>
 </li>
<li>c</li>
</ul>

We just need to print '</li>' after child list if a category has children.

function write_nested_categories( $categories ) {
	foreach ( $categories as $category ) {
		echo '<li id="category-', $category['cat_ID'], '"><label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : "" ), '/> ', wp_specialchars( apply_filters('the_category', $category['cat_name'] )), "</label>";

		if ( $category['children'] ) {
			echo "<ul>\n";
			write_nested_categories( $category['children'] );
			echo "</ul>\n";
		}
		echo "</li>";
	}
}

It displayed well on blog, but while I was trying to make 'AJAX category adder for specific parent category', it matters.

Attachments (1)

invalid_nested_category_HTML_llist_in_admin.patch (1.2 KB) - added by 082net 18 years ago.

Download all attachments as: .zip

Change History (3)

#1 @JeremyVisser
18 years ago

  • Milestone changed from 2.3.2 to 2.4

Thanks for your contributions to WordPress.

First, we will apply the patch to 2.4 (trunk), then backport it to 2.3 if we deem it to be important enough.

#2 @matt
18 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [6392]) Invalid HTML in nested category checkbox list. Also cleans up source formatting a bit. Fixes #5462. Hat tip: 082net.

Note: See TracTickets for help on using tickets.