Ticket #5096 (new defect)

Opened 1 year ago

Last modified 1 year ago

wp_set_post_categories fails if input array index starts with other than 0

Reported by: borgar Assigned to: anonymous
Priority: normal Milestone: 2.9
Component: General Version: 2.3
Severity: normal Keywords:
Cc:

Description

wp_set_post_categories is defected in that if it is passed a an array of categories who's index starts at other than 0, it returns without any action. I noticed this when tracking another issue in Textpattern import.

Example:

$cats = array();
$cats[1] = 10;
wp_set_post_categories($postID, $cats);

This fails because (1==count($cats) && ''==$cats[ 0 ]) == true.

Further, I feel that inconsistent checking behavior needs addressing. Why should this function return true in the single case where it gets an array of values where [0]=='' ?

My suggestion is to use this:

if (!is_array($post_categories) || '' == implode($post_categories))
  $post_categories = array(get_option('default_category'));

Change History

09/28/07 02:23:57 changed by foolswisdom

  • milestone set to 2.4.

09/28/07 17:35:52 changed by ryan

It was probably done to work around some bug in the dark past. We can probably get rid of it, but a more conservative fix would be to add an isset on $post_categories[0] to that else if so that you don't get caught by the early return.