[wp-trac] [WordPress Trac] #30292: Stop get_post() overwriting non-WP_Post objects passed as first parameter

WordPress Trac noreply at wordpress.org
Wed Oct 14 06:57:40 UTC 2015


#30292: Stop get_post() overwriting non-WP_Post objects passed as first parameter
------------------------------------------------+--------------------------
 Reporter:  MikeSchinkel                        |       Owner:
     Type:  enhancement                         |      Status:  new
 Priority:  normal                              |   Milestone:  Awaiting
Component:  Posts, Post Types                   |  Review
 Severity:  normal                              |     Version:  3.5
 Keywords:  has-patch dev-feedback 2nd-opinion  |  Resolution:
                                                |     Focuses:
------------------------------------------------+--------------------------
Changes (by MikeSchinkel):

 * keywords:  has-patch dev-feedback needs-refresh => has-patch dev-feedback
     2nd-opinion


Comment:

 Replying to [comment:6 sc0ttkclark]:
 > the apply filters needs to be on it's own line outside of the if() logic
 and using null instead of false.  Then you'll want to explicitly check if
 null !== ...

 Done.

 > and possibly override the variable here from `$_post` to be `$override`
 or similar.

 Don't follow.  Please elaborate.

 > I could also be mistaken but I think hook docs for filters need a
 `@return` too, but maybe not.

 I checked about five (5) cases where `apply_filters()` was documented in
 core and none of them have an `@return`. Since the first `@param`
 implicitly documents the `@return` so including the latter would be
 redundant and thus come easily become inconsistent.

 I refreshed the patch and also changed the logic to also run `->filter()`
 and optionally to run `->to_array()` when the return value of the filter
 is not `null`.  This way the developer of the hook need not worry about
 filtering or converting to array, but the developer of the class of the
 returned object would obviously need to be concerned ''(if other than
 `WP_Post`)''.

 I can refresh the patch again once I understand your point about
 `$override`.

 > I'm +1 on this patch once those things are done because of what it can
 provide for people.

 :-)

 Getting this in 4.4 would IMO be a huge boon to what could be made
 possible in WP.

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


More information about the wp-trac mailing list