Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#51320 closed defect (bug) (fixed)

PHP Notice while moving post to trash (post_type has 2 registered taxonomies both with default_term set)

Reported by: szaqal21 Owned by: SergeyBiryukov
Priority: normal Milestone: 5.5.2
Component: Posts, Post Types Version: 5.5.1
Severity: normal Keywords: has-patch has-unit-tests commit fixed-major
Cc: Focuses:

Description

While moving post to trash a PHP Notice is thrown:

PHP Notice:  Undefined index: logaction in /var/www/html/czt.dev.puw.rz/wp-includes/post.php on line 4053

post_type has 2 registered taxonomies both with default_term set.

Taxonomy "logaction" is registered as second, first is "logontype" and for this taxonomy no notice is thrown.

I think that this condition:

<?php
if ( isset( $postarr['tax_input'] ) && is_array( $postarr['tax_input'][ $taxonomy ] ) ) {
        $postarr['tax_input'][ $taxonomy ] = array_filter( $postarr['tax_input'][ $taxonomy ] );
}

should be changed to:

<?php
if ( isset( $postarr['tax_input'][ $taxonomy ] ) && is_array( $postarr['tax_input'][ $taxonomy ] ) ) {
        $postarr['tax_input'][ $taxonomy ] = array_filter( $postarr['tax_input'][ $taxonomy ] );
}

This notice wasn't thrown when I had only 1 taxonomy registered, it showed after registering second taxonomy.

On first loop iteration

<?php
isset( $postarr['tax_input'] )

is FLASE, but for second iteration it is TRUE that's why

<?php
is_array( $postarr['tax_input'][ $taxonomy ] )

is throwing a notice because $taxonomy key isn't set in $postarr array.

Attachments (1)

51320.diff​ (1.5 KB ) - added by Hareesh Pillai 6 years ago.
Refreshed patch

Download all attachments as: .zip

Change History (10)

#1 @SergeyBiryukov
6 years ago

  • Milestone Awaiting Review → 5.5.2
  • Owner set to SergeyBiryukov
  • Status new → accepted

Hi there, thanks for the ticket!

Introduced in [48480].

Last edited 6 years ago by SergeyBiryukov (previous) (diff)

This ticket was mentioned in ​PR #596 on ​WordPress/wordpress-develop by ​yakimun.


6 years ago
#2

  • Keywords has-patch has-unit-tests added

Corrected the check of the existence of an array key.

Trac ticket: https://core.trac.wordpress.org/ticket/51320

This ticket was mentioned in ​Slack in #core by audrasjb. ​View the logs.


6 years ago

#4 @audrasjb
6 years ago

  • Keywords needs-testing added

#5 @audrasjb
6 years ago

  • Keywords commit added; needs-testing removed

Hi,
Tested on my side: adding an isset check to test the sub-array fixes the issue. It looks good to go.
Marking this for commit and removing the related keyword.

@Hareesh Pillai
6 years ago

Refreshed patch

#6 @SergeyBiryukov
6 years ago

  • Resolution → fixed
  • Status accepted → closed

In 49328:

Posts, Post Types: Check if taxonomy is set for the tax_input parameter of wp_insert_post().

This avoids a PHP notice when creating a post with multiple taxonomies both having a default term.

Props yakimun, szaqal21, hareesh-pillai, audrasjb.
Fixes #51320.

#7 @SergeyBiryukov
6 years ago

  • Keywords fixed-major added
  • Resolution fixed
  • Status closed → reopened

Reopening for backporting to the 5.5 branch.

#8 @SergeyBiryukov
6 years ago

  • Resolution → fixed
  • Status reopened → closed

In 49332:

Posts, Post Types: Check if taxonomy is set for the tax_input parameter of wp_insert_post().

This avoids a PHP notice when creating a post with multiple taxonomies both having a default term.

Props yakimun, szaqal21, hareesh-pillai, audrasjb.
Merges [49328] to the 5.5 branch.
Fixes #51320.

​hellofromtonya commented on ​PR #596:


6 years ago
#9

Trac ticket was closed with changeset https://core.trac.wordpress.org/changeset/49332.

Note: See TracTickets for help on using tickets.