#5096 closed defect (bug) (duplicate)
wp_set_post_categories fails if input array index starts with other than 0
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 2.3 |
| Component: | Taxonomy | Keywords: | has-patch |
| Focuses: | 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'));
Attachments (2)
Change History (13)
#6
@
16 years ago
- Cc wojtek.szkutnik@… added
- Keywords gsoc added
Related?: http://bugs.php.net/bug.php?id=38478 @reset
#9
@
13 years ago
- Keywords gsoc removed
This now works no prob - patch added:
wp_set_post_categories( 1, array( '', 9 ) );
Note: See
TracTickets for help on using
tickets.
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.