WordPress Trac: Ticket #9670: wp_category_checklist may output incorrect resultshttps://core.trac.wordpress.org/ticket/9670
<p>
wp_category_checklist has a loop through $categories, it assumes the index begins with 0, and auto-increments. Most $categories will be that case. However, this is a shaky assumption. PHP doesn't guarantee that. I've seem its index begin with 2, for example. and it may not be consecutive.
</p>
<p>
This will cause the function to output wrong data set sometimes.
The idea is similar to <a class="closed ticket" href="https://core.trac.wordpress.org/ticket/9661" title="defect (bug): cat_row doesn't not list all categories (closed: fixed)">#9661</a>
</p>
<p>
The fix is to get array_keys first, then loop through the keys. I've verified that the following patch works correctly.
</p>
en-usWordPress Trachttps://core.trac.wordpress.org/chrome/site/your_project_logo.pnghttps://core.trac.wordpress.org/ticket/9670
Trac 1.0.1hailinTue, 28 Apr 2009 18:48:45 GMTattachment sethttps://core.trac.wordpress.org/ticket/9670
https://core.trac.wordpress.org/ticket/9670
<ul>
<li><strong>attachment</strong>
set to <em>9670_checklist.diff</em>
</li>
</ul>
<p>
patch
</p>
TickethailinTue, 28 Apr 2009 18:51:09 GMThttps://core.trac.wordpress.org/ticket/9670#comment:1
https://core.trac.wordpress.org/ticket/9670#comment:1
<p>
This is a safe fix too, as the logic is obvious.
However when the problem occurs, it could be very difficult to track it down.
</p>
TickethailinTue, 28 Apr 2009 18:56:01 GMThttps://core.trac.wordpress.org/ticket/9670#comment:2
https://core.trac.wordpress.org/ticket/9670#comment:2
<p>
the patch is taken against today's WP trunk.
</p>
TicketryanWed, 29 Apr 2009 21:01:53 GMTstatus changed; resolution sethttps://core.trac.wordpress.org/ticket/9670#comment:3
https://core.trac.wordpress.org/ticket/9670#comment:3
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
</ul>
<p>
(In <a class="changeset" href="https://core.trac.wordpress.org/changeset/11130" title="Allow for non-contiguous array indices. Props hailin. fixes #9670">[11130]</a>) Allow for non-contiguous array indices. Props hailin. fixes <a class="closed ticket" href="https://core.trac.wordpress.org/ticket/9670" title="defect (bug): wp_category_checklist may output incorrect results (closed: fixed)">#9670</a>
</p>
TicketDenis-de-BernardyWed, 29 Apr 2009 21:44:28 GMThttps://core.trac.wordpress.org/ticket/9670#comment:4
https://core.trac.wordpress.org/ticket/9670#comment:4
<p>
Ack. I had written a patch in that very same area that fixes a bug in another ticket, related to category selector weirdness.
</p>
<p>
@ryan: If you find it before I do, please bump it with a "patch is stale" or something, so I get an email.
</p>
TicketDenis-de-BernardyThu, 30 Apr 2009 10:51:39 GMTmilestone changedhttps://core.trac.wordpress.org/ticket/9670#comment:5
https://core.trac.wordpress.org/ticket/9670#comment:5
<ul>
<li><strong>milestone</strong>
changed from <em>Unassigned</em> to <em>2.8</em>
</li>
</ul>
Ticket