[wp-trac] [WordPress Trac] #40789: pre_get_lastpostdate filter

WordPress Trac noreply at wordpress.org
Wed May 17 15:03:27 UTC 2017


#40789: pre_get_lastpostdate filter
-------------------------+-----------------------------
 Reporter:  toddlevy     |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:  4.7.5
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 This is line 5530 of
 https://github.com/WordPress/WordPress/blob/4.7.5/wp-includes/post.php


 Currently, there is no way to filter `get_lastpostdate` in advance of it
 calling `_get_last_post_time`.

 This creates situations where it's impossible to filter/modify the default
 post type because...

 a) `get_lastpostdate` is called without the `$post_type` argument (e.g. as
 happens in `get_lastpostmodified` and sometimes in 3rd party plugins), and

 b) The `_get_last_post_time` function that gets called doesn't allow
 `$post_type` to be filtered as best I can tell

 If you take a look at `get_lastpostmodified` you can see the
 `pre_get_lastpostmodified` filter, which is great and would solve this
 problem.

 Suggested enhancement is to add a similar `pre_get_lastpostdate` filter
 for `get_lastpostdate` with the same naming convention and functionality.

 Something like this...


 {{{#!php
 <?php
 function get_lastpostdate( $timezone = 'server', $post_type = 'article' )
 {

   $lastpostdate = apply_filters( 'pre_get_lastpostdate', false, $timezone,
 $post_type );
   if ( false !== $lastpostdate ) {
      return $lastpostdate;
   }

   $lastpostdate  = _get_last_post_time( $timezone, 'date', $post_type );

   return apply_filters( 'get_lastpostdate', $lastpostdate, $timezone );

 }
 }}}

 Thank you for your consideration of this idea.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40789>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list