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

WordPress Trac noreply at wordpress.org
Fri Nov 18 22:48:03 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 danieliser):

 TBH This filter needs 2 things considered in my oppionon.

 1. The WP_Post class needs to have Final removed so it can be extended
 properly.
 2. The filter discussed in depth here really just needs to be something
 along the lines of

 {{{#!php
 <?php
 $_object = apply_filters( 'get_post_object_type', 'WP_Post', $args );
 if ( ! class_exists( $_object ) ) {
   $_object = 'WP_Post';
 }

 $object = new $_object( $args );
 }}}

 Where that filter belongs is up for debate, as I belive it should actually
 be in the returns for WP_Query.

 @MikeSchinkel - As for your examples above and their inherent issues, here
 is a full example based on the extendable Post class I linked above and
 how we are using it in a themeable plugin.

 Classes used:

 - Query Factory - https://github.com/danieliser/wp-oop-dev-
 modules/blob/master/Abstracts/Factory/Query.php
 - Model - https://github.com/danieliser/wp-oop-dev-
 modules/blob/master/Model/Post.php
 - Loop example - https://github.com/danieliser/wp-oop-dev-
 modules/blob/master/loop.php

 With a little more work the_post could be overwritten to pass the custom
 object into the global $post as well which is the only caveat to our
 methods currently.

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


More information about the wp-trac mailing list