[wp-trac] [WordPress Trac] #47114: global $pages not available on the_post

WordPress Trac noreply at wordpress.org
Fri May 3 18:07:13 UTC 2019


#47114: global $pages not available on the_post
-------------------------------+-----------------------------
 Reporter:  david.binda        |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:
 Severity:  normal             |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 After r44941 the `$pages` (and other global variables) are no longer
 available in `the_post` action.

 As the `the_post` action is now being triggered from a new
 `WP_Query::generate_postdata` method, which is called from original
 `WP_Query::setup_postdata` before any of the `global $id, $authordata,
 $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages;`
 is populated, previously available global variables are no longer
 populated at the time `the_post` action is triggered.

 I've whipped-up a quick unit tests to test this behaviour. The test passes
 prior r44941, but fails afterwards:

 {{{#!php
 <?php
     function test_the_post_action() {
         $post = self::factory()->post->create_and_get();
         add_action( 'the_post', function() {
             $this->pages = $GLOBALS['pages'];
         } );
         setup_postdata( $post );
         $this->assertEquals( $GLOBALS['pages'], $this->pages );
     }
 }}}

 (In my tests, I added the test to
 https://core.trac.wordpress.org/browser/trunk/tests/phpunit/tests/query/setupPostdata.php
 )

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


More information about the wp-trac mailing list