Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#36879 closed enhancement (duplicate)

Allow post data to be filtered if is_customize_preview()

Reported by: westonruter's profile westonruter Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Customize Keywords:
Focuses: Cc:


This was originally reported as an an issue in the Customize Posts feature plugin for #34923. The plugin currently previews post data via the the_posts filter. This is problematic, however, because this filter is not called in queries with suppress_filters on or in calls to get_post():

When querying posts via get_posts() or when using new WP_Query( array( 'suppress_filters' => true ) ), the the_posts filters which apply the previewed changes to the posts is not run. This is a problem with Core in that there are not always filters applied to post data. This necessitates, for example, for there to be a comments_open filter in addition to a the_posts filter, since get_post() will return a pristine copy of the post without any hooks for Customize Posts to apply the previewed changes. In reality, get_post() should be returning the dirty post as opposed to the pristine post, and so an additional comments_open filter wouldn't be needed.

So, what is needed is a new filter to run whenever getting a post via get_post() to allow the array or object to be mutated. This filter can only be applied if is_customize_preview() since applying such a filter generally could be too far reaching.

Attachments (1)

36879.0.diff (1.4 KB) - added by westonruter 8 years ago.

Download all attachments as: .zip

Change History (6)

8 years ago

#1 @westonruter
8 years ago

  • Keywords has-patch needs-unit-tests added

This ticket was mentioned in Slack in #core by westonruter. View the logs.

8 years ago

#4 @ocean90
8 years ago

I don't think that this filter belongs directly into WP_Post. At least not with an is_customize_preview() conditional. Should this be a more general filter which makes it a duplicate of #30292?

#5 @westonruter
8 years ago

  • Keywords has-patch needs-unit-tests removed
  • Milestone 4.6 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Indeed. I wasn't familiar with #30292.

Note: See TracTickets for help on using tickets.