Make WordPress Core

Opened 4 years ago

Closed 3 years ago

Last modified 3 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's profile szaqal21 Owned by: sergeybiryukov's profile 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 3 years ago.
Refreshed patch

Download all attachments as: .zip

Change History (10)

#1 @SergeyBiryukov
4 years ago

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

Thanks for the ticket!

Introduced in [48480].

Version 0, edited 4 years ago by SergeyBiryukov (next)

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


3 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.


3 years ago

#4 @audrasjb
3 years ago

  • Keywords needs-testing added

#5 @audrasjb
3 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
3 years ago

Refreshed patch

#6 @SergeyBiryukov
3 years 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
3 years ago

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

Reopening for backporting to the 5.5 branch.

#8 @SergeyBiryukov
3 years 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.

hellofromtonya commented on PR #596:


3 years ago
#9

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

Note: See TracTickets for help on using tickets.