Make WordPress Core

Opened 6 weeks ago

Closed 5 weeks ago

#63920 closed defect (bug) (fixed)

get_adjacent_post() has a misplaced check for WP_Error

Reported by: kitchin's profile kitchin Owned by: westonruter's profile westonruter
Milestone: 6.9 Priority: normal
Severity: normal Version: 4.0
Component: Posts, Post Types Keywords: has-patch has-unit-tests commit
Focuses: Cc:

Description

The function calls is_wp_error( $term_array ) after $term_array = array_map( 'intval', $term_array ).

Attachments (1)

63920.patch (851 bytes) - added by kitchin 6 weeks ago.

Download all attachments as: .zip

Change History (13)

@kitchin
6 weeks ago

#1 follow-up: @westonruter
6 weeks ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 6.9

@kitchin thanks for the report and the patch. It looks good to me. Would you like to add a test case for the scenario that causes a failure without the fix?

Also, it would be good to open a pull request with your patch so we can see the existing automated tests run.

#2 in reply to: ↑ 1 @SirLouen
6 weeks ago

  • Keywords needs-testing needs-unit-tests added
  • Version changed from trunk to 3.7

This was introduced in one of those megalodon commits #26937/[27836], so not rare to see this. I wonder if PHPStan would have spotted it.

Replying to westonruter:

Also, it would be good to open a pull request with your patch so we can see the existing automated tests run.

Tests are passing, but just because there are no unit tests covering this. It would be great to add them.

Moreover, this can be a great opportunity to reunify all the hanging get_adjacent_post tests in other files that don't belong.

Let me add the needs-unit-tests tag and if I find some time I will work on this @kitchin if you want to do it, send a PR as @westonruter commented.

#3 follow-up: @SergeyBiryukov
5 weeks ago

  • Version changed from 3.7 to 4.0

Introduced in [29248] / #22112.

#4 in reply to: ↑ 3 @SirLouen
5 weeks ago

Replying to SergeyBiryukov:

Introduced in [29248] / #22112.

True, in origin wp_get_object_terms could return WP_Error it was in [29248] with array_map in between when it broke this conditional.

#5 @pmbaldha
5 weeks ago

@kitchin Thanks for reporting the issue and creating the patch for it. Can you please give us a test case so we can test it? You can refer to https://make.wordpress.org/test/2025/05/15/building-the-testing-use-case/.

This ticket was mentioned in PR #9861 on WordPress/wordpress-develop by @ishikaatxecurify.


5 weeks ago
#6

Added the is_wp_error check before calling other array functions so that no warning is thrown.

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

This ticket was mentioned in PR #9863 on WordPress/wordpress-develop by @mindctrl.


5 weeks ago
#7

  • Keywords has-unit-tests added; needs-unit-tests removed

Improves error handling in get_adjacent_post to avoid PHP errors when passing non-array values to array functions. Adds phpunit tests to confirm behavior.

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

#8 @mindctrl
5 weeks ago

Hi all, I've added a PR that matches the original patch, but with some suggested phpunit test cases.

@westonruter commented on PR #9861:


5 weeks ago
#9

Hello! I'm curious about your PR here, and if you factored in the existing patch from @kitchin as proposed on the ticket?

That patch has been iterated on by @mindctrl with added unit tests in https://github.com/WordPress/wordpress-develop/pull/9863 so it's likely to be what gets committed.

@mindctrl commented on PR #9863:


5 weeks ago
#10

@westonruter thank you for the review. I've applied your suggestions.

#11 @westonruter
5 weeks ago

  • Keywords commit added; needs-testing removed
  • Owner set to westonruter
  • Status changed from new to accepted

#12 @westonruter
5 weeks ago

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

In 60733:

Posts, Post Types: Fix placement of WP_Error check in get_adjacent_post().

Props kitchin, mindctrl, westonruter, SirLouen, SergeyBiryukov, pmbaldha.
Fixes #63920.

Note: See TracTickets for help on using tickets.