Make WordPress Core


Ignore:
Timestamp:
05/04/2019 09:06:14 PM (7 years ago)
Author:
azaozz
Message:

Fix setup_postdata() to set the (inside the loop) globals before the_post action is fired. Follow-up from #42814 and [44941].

Props david.binda, spacedmonkey, boonebgorges, birgire, jorbin, azaozz.
Merges [45285] from trunk.
Fixes #47114 for 5.2.

Location:
branches/5.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.2

    • Property svn:mergeinfo changed
      /trunk (added)merged: 45285
  • branches/5.2/tests/phpunit/tests/query/setupPostdata.php

    r42343 r45286  
    99
    1010    protected $global_data = array();
     11
     12    protected $pages_global;
    1113
    1214    public function setUp() {
     
    417419    }
    418420
     421    /**
     422     * @ticket 47114
     423     *
     424     * setup_postdata() should set the globals before `the_post` action is fired.
     425     */
     426    public function test_the_post_action() {
     427        $post = self::factory()->post->create_and_get();
     428        add_action( 'the_post', array( $this, 'the_post_action_callback' ) );
     429
     430        setup_postdata( $post );
     431
     432        $this->assertEquals( $GLOBALS['pages'], $this->pages_global );
     433    }
     434
     435    /**
     436     * Helpers
     437     */
     438    public function the_post_action_callback() {
     439        $this->pages_global = $GLOBALS['pages'];
     440    }
    419441}
Note: See TracChangeset for help on using the changeset viewer.