WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 months ago

#13771 closed enhancement (fixed)

get_the_date() to accept optional $post argument

Reported by: bigdawggi Owned by: nacin
Milestone: 3.9 Priority: normal
Severity: normal Version: 3.0
Component: Date/Time Keywords: has-patch dev-feedback commit
Focuses: Cc:

Description

Currently the get_the_date() function only utilizes the global $post. Allowing this function to accept an optional $post object as an argument would be beneficial for getting the formatted date of any post.

Attachments (7)

get_the_date.diff (526 bytes) - added by bigdawggi 4 years ago.
Patch for get_the_date() to accept optional $post arg.
13771.diff (993 bytes) - added by solarissmoke 3 years ago.
13771_2.diff (986 bytes) - added by tanner m 4 months ago.
New patch.
13771_3.diff (983 bytes) - added by tanner m 4 months ago.
Fix doc block grammar and use more conventional $post = 0.
13771.2.diff (1.1 KB) - added by adamsilverstein 4 months ago.
Slight doc block cleanup, add 'Optional' to description of $post variable
13771.2.2.diff (1.9 KB) - added by adamsilverstein 4 months ago.
add a unit test
13771.3.diff (2.3 KB) - added by adamsilverstein 4 months ago.

Download all attachments as: .zip

Change History (24)

bigdawggi4 years ago

Patch for get_the_date() to accept optional $post arg.

comment:1 ryan4 years ago

  • Milestone changed from 3.0 to 3.1

We typically call get_post() and let it figure out whether to use the global.

No more enhancements for 3.0. Moving to 3.1.

comment:2 bigdawggi4 years ago

  • Cc matt@… added

Thanks Ryan. I agree, I was just trying to trim the extra function calls; but after review it may not be worth the investment in time to set a precedent of allowing an optional $post arg in template tags, though I'll let you guys decide ;)

comment:3 nacin4 years ago

  • Keywords needs-patch added; date removed
  • Milestone changed from Awaiting Triage to Future Release

solarissmoke3 years ago

comment:4 solarissmoke3 years ago

  • Keywords has-patch added; needs-patch removed

Also cleaned up the code/docs a bit.

comment:5 devinreams3 years ago

  • Cc devin@… added

comment:6 barrykooij21 months ago

  • Cc b.kooij@… added

(When) Will this be added to core?

Last edited 21 months ago by barrykooij (previous) (diff)

comment:7 jeremyfelt6 months ago

  • Component changed from General to Date/Time

tanner m4 months ago

New patch.

comment:8 follow-up: tanner m4 months ago

Hey guys! Just added a new patch here. Let me know if there is anything else you need.

tanner m4 months ago

Fix doc block grammar and use more conventional $post = 0.

adamsilverstein4 months ago

Slight doc block cleanup, add 'Optional' to description of $post variable

comment:9 in reply to: ↑ 8 adamsilverstein4 months ago

  • Keywords dev-feedback added

Replying to tanner m:

Hey guys! Just added a new patch here. Let me know if there is anything else you need.

Hey Tanner - this looks good, I added the word 'Optional' to the doc block description of the new $post variable, and also cleaned up the alignment a bit.

Thanks for contributing! A unit test would be nice here...

adamsilverstein4 months ago

add a unit test

comment:10 adamsilverstein4 months ago

13771.2.2.diff Adds a unit test verifying that get_the_date() returns the expected date when passed a post id (apologies for the funky filename).

comment:11 tanner m4 months ago

Great, thanks Adam!

comment:12 follow-up: nacin4 months ago

Nice work, tanner and adam. It looks like $post should also be passed to the get_the_date filter.

adamsilverstein4 months ago

comment:13 in reply to: ↑ 12 adamsilverstein4 months ago

Replying to nacin:

Nice work, tanner and adam. It looks like $post should also be passed to the get_the_date filter.

Thanks & good point! Added $post to the filter in 13771.3.diff and added a doc block above the filter since I was touching it anyway.

comment:14 ircbot4 months ago

This ticket was mentioned in IRC in #wordpress-dev by tannermoushey. View the logs.

comment:15 follow-up: DrewAPicture4 months ago

  • Keywords commit added
  • Milestone changed from Future Release to 3.9

13771.3.diff seems to be in order. @adamsilverstein: nice work on the hook docs!

comment:16 in reply to: ↑ 15 adamsilverstein4 months ago

Replying to DrewAPicture:

13771.3.diff seems to be in order. @adamsilverstein: nice work on the hook docs!

Yea! that is the first time i've written a hook doc you didn’t have to fix!

comment:17 nacin4 months ago

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

In 27380:

Let get_the_date() accept a post object.

props tanner-m, adamsilverstein, bigdawggi.
fixes #13771.

Note: See TracTickets for help on using tickets.