WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#40780 closed enhancement (fixed)

Update docblocks & parameters in wp-includes/link-template.php for post-related functions

Reported by: GunGeekATX Owned by: DrewAPicture
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.8
Component: Posts, Post Types Keywords: has-patch
Focuses: docs Cc:

Description

The following functions have docblocks and parameters that appear to only accept the post ID, but the underlying code calls get_post() so either post ID or a post object can be accepted.

  • get_post_permalink()
  • get_edit_post_link()
  • edit_post_link()
  • get_delete_post_link()

Attachments (2)

40780.patch (4.8 KB) - added by GunGeekATX 4 years ago.
40780.diff (3.7 KB) - added by DrewAPicture 4 years ago.

Download all attachments as: .zip

Change History (8)

@GunGeekATX
4 years ago

#1 @adamsilverstein
4 years ago

  • Component changed from General to Posts, Post Types
  • Focuses docs added

#2 follow-up: @adamsilverstein
4 years ago

  • Keywords needs-refresh added

Overall this makes sense, however, I don't think get_post_permalink actually accepts a post object currently.

In your change at line 267, you call get_post_status with a WP_Post object, but that function takes a post ID - maybe change to $post->ID? Also I want to make sure the $id isn't used elsewhere.

#3 in reply to: ↑ 2 @adamsilverstein
4 years ago

In your change at line 267, you call get_post_status with a WP_Post object, but that function takes a post ID - maybe change to $post->ID? Also I want to make sure the $id isn't used elsewhere.

Actually thats wrong :) I was looking at outdated docs! It should work as is.

#4 @adamsilverstein
4 years ago

Maybe the changes should just be for the documentation and don't change the variable names?

@DrewAPicture
4 years ago

#5 @DrewAPicture
4 years ago

  • Keywords has-patch added; needs-refresh removed
  • Milestone changed from Awaiting Review to 4.9

I've iterated the patch with 40780.diff in what I think is a fair compromise.

I think we're fine keeping the $id parameter since it's so consistent between the functions already, but there's definitely value in better documenting the types accepted.

Also, I've gone ahead and kept the suggested use of $post for checking the post status in get_post_permalink() as referencing back to the original $id parameter several lines after retrieving the full object seemed weird. get_post_status() can accept an ID or WP_Post object too, so that's fine.

Maybe at some later point we should go through and rename all of these variables at once, but for the purposes of this ticket, let's keep it simple :-)

#6 @DrewAPicture
4 years ago

  • Owner set to DrewAPicture
  • Resolution set to fixed
  • Status changed from new to closed

In 40975:

Link Template: Clarify documentation for the $id parameter in get_post_permalink(), get_edit_post_link(), edit_post_link(), and get_delete_post_link(), to reflect that either a post ID or WP_Post object is accepted.

Separately, use $post for checking the post status and retrieving the page_uri in get_post_permalink() instead of referencing back to the original $id parameter.

Props GunGeekATX for the initial patch.
Fixes #40780.

Note: See TracTickets for help on using tickets.