WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 16 months ago

#13246 closed defect (bug) (fixed)

wp_set_post_categories assumes $post_categories has a value in [0], but wp_insert_post doesn't assign the default category there

Reported by: jorbin Owned by: jorbin
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: Taxonomy Keywords: has-patch needs-testing
Focuses: Cc:

Description

right now wp_insert post assigns the default category to a post just as an array item which should be in the 0 ofset. However this isn't guaranteed. If we cast it as the 0 offset in wp_insert_post, this solves the problem

To reproduce:

on a vanilla install with wp_debug enabled, add a post modifying the categories. This causes the following error: Notice: Undefined offset: 0 in /opt/lampp/htdocs/amun/wp/trunk/wp-includes/post.php on line 2561

Attachments (3)

14431.diff (539 bytes) - added by jorbin 4 years ago.
14433.diff (479 bytes) - added by jorbin 4 years ago.
14438.diff (1.3 KB) - added by scribu 4 years ago.

Download all attachments as: .zip

Change History (10)

jorbin4 years ago

jorbin4 years ago

comment:1 jorbin4 years ago

My first patch didn't solve it. For the second I added a check to make sure we have a category assigned in [0] if there is only one category.

comment:2 filosofo4 years ago

  • Owner changed from filosofo to jorbin
  • Status changed from new to assigned

scribu4 years ago

comment:3 follow-up: scribu4 years ago

  • Keywords needs-testing added

I wasn't able to reproduce the notice. Could you provide more detailed steps to reproduce?

Anyway, 14438.diff:

  • removes duplicated validation code from wp_insert_post()
  • uses reset($post_category) instead of $post_category[0]

comment:4 in reply to: ↑ 3 duck_4 years ago

Replying to scribu:

I wasn't able to reproduce the notice. Could you provide more detailed steps to reproduce?

I get the error when only one category is checked before clicking Update

Undefined offset: 0 in \wp-dev\wp-includes\post.php on line 2574

comment:5 wpmuguru4 years ago

(In [14447]) use reset vs offset 0, props scribu, see #13246

comment:6 jorbin4 years ago

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

Fixed. Thanks scribu and wpmuguru

comment:7 SergeyBiryukov16 months ago

#5096 was marked as a duplicate.

Note: See TracTickets for help on using tickets.