WordPress.org

Make WordPress Core

Opened 4 weeks ago

Last modified 4 weeks ago

#48358 reviewing defect (bug)

wp_get_post_parent_id() does not default to global $post

Reported by: danielpost Owned by: SergeyBiryukov
Milestone: 5.4 Priority: normal
Severity: normal Version: 3.1
Component: Posts, Post Types Keywords: has-patch has-unit-tests needs-dev-note
Focuses: Cc:
PR Number:

Description

https://core.trac.wordpress.org/browser/tags/5.2.4/src/wp-includes/post.php#L6595

Because wp_get_post_parent_id() does not declare a default value for the $post parameter, calling it without explicitly passing the $post parameter results in an error. This means that it will never default to the global $post. I believe the fix here is to declare $post = null in the function declaration and specify in the PHPDoc that this parameter is optional, similar to how other functions handle this.

Attachments (2)

48358.diff (728 bytes) - added by danielpost 4 weeks ago.
48358.1.diff (1.6 KB) - added by danielpost 4 weeks ago.
Adds test

Download all attachments as: .zip

Change History (9)

@danielpost
4 weeks ago

#1 @danielpost
4 weeks ago

  • Version changed from 5.2.3 to 3.1

#2 @davidbaumwald
4 weeks ago

  • Keywords has-patch needs-unit-tests added

#3 @SergeyBiryukov
4 weeks ago

  • Milestone changed from Awaiting Review to 5.4
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

@danielpost
4 weeks ago

Adds test

#4 @danielpost
4 weeks ago

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

#5 @davidbaumwald
4 weeks ago

  • Keywords needs-dev-note added

This doesn't need a full dev-note, but it should get a small call-out in the miscellaneous changes note in 5.4.

#6 @birgire
4 weeks ago

The test in 48358.1.diff might need the annotation @ticket 48358. I also wonder if the function's doc would need the @since annotation after the signature change.

#7 @danielpost
4 weeks ago

I'm happy to make those changes if the consensus is that they're necessary—I don't have enough experience with core contributing to make that call myself.

Note: See TracTickets for help on using tickets.