WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#24162 closed enhancement (invalid)

Add filter hook to get_post_format_meta()

Reported by: stuntbox Owned by: markjaquith
Milestone: Priority: normal
Severity: normal Version: 3.6
Component: Post Formats Keywords: has-patch
Focuses: Cc:

Description

As per a previous request from Alex King, it would be useful if a filter hook could be added to get_post_format_meta(), particularly for plugin and theme builders looking to reformat the output of post formats for uses like HiDPI image plugins, lazy loading techniques, picture element polyfills, etc.

Attachments (4)

24162.diff (372 bytes) - added by wonderboymusic 2 years ago.
post-meta-values-post-id.diff (786 bytes) - added by alexkingorg 2 years ago.
24162.2.diff (802 bytes) - added by SergeyBiryukov 2 years ago.
24162.3.diff (843 bytes) - added by alexkingorg 2 years ago.
always call filters

Download all attachments as: .zip

Change History (15)

comment:2 @SergeyBiryukov2 years ago

  • Component changed from General to Post Formats
  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Awaiting Review to 3.6

@wonderboymusic2 years ago

comment:3 @markjaquith2 years ago

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

In 24080:

Add a post_format_meta filter.

props alexkingorg. fixes #24162.

comment:4 follow-up: @alexkingorg2 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Whoops, I think my patch was incomplete - we should also pass the $post_id to the filter so there is context to work with.

Additionally, the $post_id param to the function is listed as optional, but there is nothing to have it fall back on the global $post, I added this as well. The $post_id is passed to get_post_format() which requires the post id (doesn't fall back on global $post).

Sorry for not catching this sooner. Updated patch attached.

@SergeyBiryukov2 years ago

comment:5 in reply to: ↑ 4 @SergeyBiryukov2 years ago

Replying to alexkingorg:

Additionally, the $post_id param to the function is listed as optional, but there is nothing to have it fall back on the global $post, I added this as well.

We've replaced global $post references with get_post() in [21735]. 24162.2.diff uses get_post() here for consistency.

The $post_id is passed to get_post_format() which requires the post id (doesn't fall back on global $post).

It does fall back to the global, via get_post(). [24057] made that clear in the description. get_post_meta(), however, does not.

comment:6 @alexkingorg2 years ago

Hmm, interesting. I hadn't realized about the standardization on get_post() vs global $post, thanks for the explanation.

This does introduce an additional set of SQL calls for loading up the post if it's not already in object cache. Doesn't seem necessary if the $post_id isn't 0.

Is it the job of this function to check that the post ID is valid? Seems like a lot of responsibility to put on this guy. :)

comment:7 @alexkingorg2 years ago

Here's a slight mod so that the filter always gets called.

@alexkingorg2 years ago

always call filters

comment:8 @DrewAPicture2 years ago

24162.3.diff works as expected for me.

comment:9 @ocean902 years ago

  • Milestone 3.6 deleted
  • Resolution set to invalid
  • Status changed from reopened to closed

comment:10 @alexkingorg2 years ago

We're just throwing away code and ideas relating to post formats now?

comment:11 @SergeyBiryukov2 years ago

All the patches and ideas are still available for future reference.

Note: See TracTickets for help on using tickets.