[wp-trac] [WordPress Trac] #12955: Add get_post filter

WordPress Trac noreply at wordpress.org
Sat Feb 13 02:14:28 UTC 2016

#12955: Add get_post filter
 Reporter:  JohnLamansky            |       Owner:
     Type:  feature request         |      Status:  new
 Priority:  normal                  |   Milestone:  Future Release
Component:  Posts, Post Types       |     Version:
 Severity:  normal                  |  Resolution:
 Keywords:  has-patch dev-feedback  |     Focuses:

Comment (by MikeSchinkel):

 Replying to [comment:31 chriscct7]:
 > Feedback on the current patch ''(from
 > The current patch proposes deprecating the ability to call new `WP_Post`
 in favor of calling `WP_Post::make_instance()`. I think a better path
 forward would be to have the `__construct()` call `make_instance()`, as
 there are so many plugins (and parts of core using new `WP_Post`) then
 this is going to cause so many issues (it will be like deprecating
 `WP_Widget::WP_Widget` but way worse).
 > The patch also needs unit tests.
 > Basically by using `make_instance()` the goal is to be able to filter
 the returned object in `get_post()`

 Completely agreed that it would be ideal to have the `__construct()` call
 call `make_instance()`, but unfortunately PHP does not allow changing the
 class of an object inside a constructor.  A major goal here was to stop
 `get_post()` from changing the object such that the following is always

 $_post = get_post( $post );
 echo $_post === $post  // Can currently echo `false`

 Yes it is an issue that plugins use `new WP_Post()` but that's the lesser
 concern.  That they do so does not cause the problem above.

 To address your concern we could have a ''"soft deprecation"'' where no
 warning or error is thrown for numerous releases, as long as `get_post()`
 can be made to not change the object that it is being effectively used to
 "cast" to `WP_Post`.

Ticket URL: <https://core.trac.wordpress.org/ticket/12955#comment:32>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list