WordPress.org

Make WordPress Core

Opened 2 months ago

Closed 4 weeks ago

Last modified 4 weeks 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
Milestone: 5.5.2 Priority: normal
Severity: normal Version: 5.5.1
Component: Posts, Post Types Keywords: has-patch has-unit-tests commit fixed-major
Focuses: Cc:

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 5 weeks ago.
Refreshed patch

Download all attachments as: .zip

Change History (10)

#1 @SergeyBiryukov
2 months ago

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

Hi there, thanks for the ticket!

Introduced in [48480].

Last edited 2 months ago by SergeyBiryukov (previous) (diff)

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


6 weeks ago

  • 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 weeks ago

#4 @audrasjb
6 weeks ago

  • Keywords needs-testing added

#5 @audrasjb
6 weeks 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
5 weeks ago

Refreshed patch

#6 @SergeyBiryukov
4 weeks ago

  • Resolution set to fixed
  • Status changed from accepted to 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
4 weeks ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for backporting to the 5.5 branch.

#8 @SergeyBiryukov
4 weeks ago

  • Resolution set to fixed
  • Status changed from reopened to 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.

#9 @prbot
4 weeks ago

hellofromtonya commented on PR #596:

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

Note: See TracTickets for help on using tickets.