[wp-trac] [WordPress Trac] #9256: clean up the global variables when moving out of the loop

WordPress Trac noreply at wordpress.org
Wed Oct 22 17:44:41 UTC 2014


#9256: clean up the global variables when moving out of the loop
-------------------------+-----------------------
 Reporter:  aldolat      |       Owner:
     Type:  enhancement  |      Status:  reopened
 Priority:  normal       |   Milestone:  4.1
Component:  Query        |     Version:  2.7.1
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:
-------------------------+-----------------------
Changes (by boonebgorges):

 * keywords:  has-patch needs-unit-tests => has-patch
 * milestone:  Future Release => 4.1


Comment:

 This ticket is essentially the same as #20904 and #25349. The root issue
 is that `setup_postdata()` is not always sensitive to its current
 environment (ie, the `WP_Query` class from which it's initiated).
 [attachment:9256.4.patch] addresses this root issue by doing the
 following:

 * Convert `setup_postdata()` to a method of `WP_Query`, and make
 `setup_postdata()` a wrapper for `$wp_query->setup_postdata` for backward
 compatibility. (see #20904)
 * In `WP_Query::setup_postdata()`, get the value of `$page` out of the
 current object, rather than using `get_query_var()`, which references the
 `$wp_query` global. This means that `<!--nextpage-->` is respected in
 secondary loops.
 * In `WP_Query::setup_postdata()`, only force `$more` to 1 when (a) you're
 looking at an RSS feed, or (b) you're looking at the permalink of the
 `$post` passed into the method. This means that `<!--more-->` is respected
 in secondary loops. This change, along with the previous one, mean that
 (a) `get_the_excerpt()` and (b) `wp_link_pages()` work as expected in
 secondary loops.
 * Lots of unit tests, mainly to cover the more mundane parts of
 `setup_postdata()`. The critical ones for this ticket are the ones marked
 with `@ticket` annotations.

 I'm not sure if this counts as the "major cleanup" that nacin discusses
 earlier, but it's a substantial enough improvement that I think we should
 consider it for 4.1. Would like feedback from a lead on this one.

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


More information about the wp-trac mailing list