[wp-trac] [WordPress Trac] #22448: WP_Post conversion overwrites object changes on the_posts filter

WordPress Trac noreply at wordpress.org
Thu Nov 15 13:08:42 UTC 2012


#22448: WP_Post conversion overwrites object changes on the_posts filter
-------------------------------------------------+-------------------------
 Reporter:  ntm                                  |       Owner:  ryan
     Type:  defect (bug)                         |      Status:  assigned
 Priority:  high                                 |   Milestone:  3.5
Component:  Query                                |     Version:  trunk
 Severity:  normal                               |  Resolution:
 Keywords:  needs-unit-tests has-patch needs-    |
  testing                                        |
-------------------------------------------------+-------------------------
Changes (by kovshenin):

 * cc: kovshenin (added)
 * keywords:  needs-unit-tests => needs-unit-tests has-patch needs-testing


Comment:

 Howdy! I spent some time figuring out how all of this works, doesn't seem
 to be caused by [22011] from what I see. The problem is because of the
 behavior of `get_post`, which is supposed to retrieve a fresh post from
 cache if filter is (but was not) raw.

 The behavior was copied into `WP_Post` but with the current implementation
 of `WP_Query`, the cache exists for all posts, before `get_instance` is
 called, so the `sanitize_post` inside `get_instance` is never called
 (within a `WP_Query` scenario). The 3.4 scenario used to explicitly call
 `sanitize_post`, but 3.5 relies on `get_post` instead. So in 3.4, after a
 successful query, every post in the posts array will have its `filter` set
 to `raw`, whereas 3.5 keeps it blank, causing `WP_Post::filter` to call
 `get_instance` over and over again (because the cached version has no
 filter either).

 I'm not sure this is the only problem, and I'm pretty sure
 [attachment:22448.diff] is not the best solution, but it does make sure
 that when retrieved, a fresh post is always sanitized, meaning
 `WP_Post::filter` can not run the `get_instance` routine unless the filter
 has been explicitly changed to something other than `raw`.
 [attachment:22448.unit-tests.diff] adds some tests, covers adding more
 posts via `the_posts` filter, and adding custom data using `the_posts`
 filter, as initially described in this ticket.

 {{{
 phpunit --group post
 phpunit --group query
 phpunit --group 22448
 }}}

 Hope this helps :)

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22448#comment:10>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list