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

WordPress Trac noreply at wordpress.org
Fri Nov 18 11:19:53 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 flixos90):

 Replying to [comment:50 MikeSchinkel]:
 > {{{#!php
 > <?php
 > global $post;
 > $post = new Custom_Wrapper( $post );
 > the_post();
 > echo $post->custom_value();
 > }}}
 >
 > See the above example as to why your statement ignores the most common
 use-case for `$post`; in a theme that uses template tags where the
 template tags call `get_post()` to ''sanitize'' the global `$post`
 variable and cause the wrapped class instance to be thrown away.

 That's what I meant with it should only happen in a custom setup where you
 have full control over the theme. To be clear, I agree with what you're
 saying, but I wanted to highlight that only custom projects where you have
 full control would benefit from this. In my case I do not override the
 global at all, I have my own container class for the wrappers so that
 there are no conflicts with the `$post` global, and that is the workaround
 I was referring to. This is also the only way the code can remain proof of
 conflicts with other plugins. When you put a wrapper class like the
 example you posted in the `$post` global, for example something like
 `get_object_vars( $post )` would fail as magic properties are used.

 In short, I still think this filter is worth exploring, but we should be
 careful on how to approach this in terms of compatibility issues, and I'm
 sure that is the reason it has not happened yet.

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


More information about the wp-trac mailing list