Changeset 34089
- Timestamp:
- 09/12/2015 08:57:06 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/query.php
r34073 r34089 4617 4617 * 4618 4618 * @since 4.1.0 4619 * @since 4.4.0 Added the ability to pass a post ID to `$post`. 4619 4620 * 4620 4621 * @global int $id … … 4628 4629 * @global int $numpages 4629 4630 * 4630 * @param WP_Post $post Post data.4631 * @param WP_Post|object|int $post WP_Post instance or Post ID/object. 4631 4632 * @return true True when finished. 4632 4633 */ 4633 4634 public function setup_postdata( $post ) { 4634 4635 global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages; 4636 4637 if ( ! ( $post instanceof WP_Post ) ) { 4638 $post = get_post( $post ); 4639 } 4640 4641 if ( ! $post ) { 4642 return; 4643 } 4635 4644 4636 4645 $id = (int) $post->ID; … … 4702 4711 if ( ! empty( $this->post ) ) { 4703 4712 $GLOBALS['post'] = $this->post; 4704 setup_postdata( $this->post );4713 $this->setup_postdata( $this->post ); 4705 4714 } 4706 4715 } … … 4770 4779 * 4771 4780 * @since 1.5.0 4781 * @since 4.4.0 Added the ability to pass a post ID to `$post`. 4772 4782 * 4773 4783 * @global WP_Query $wp_query 4774 4784 * 4775 * @param object $post Post data.4785 * @param WP_Post|object|int $post WP_Post instance or Post ID/object. 4776 4786 * @return bool True when finished. 4777 4787 */ -
trunk/tests/phpunit/tests/query/setupPostdata.php
r30976 r34089 45 45 $this->assertNotEmpty( $p->ID ); 46 46 $this->assertSame( $p->ID, $GLOBALS['id'] ); 47 } 48 49 /** 50 * @ticket 30970 51 */ 52 public function test_setup_by_id() { 53 $p = $this->factory->post->create_and_get(); 54 setup_postdata( $p->ID ); 55 56 $this->assertSame( $p->ID, $GLOBALS['id'] ); 57 } 58 59 /** 60 * @ticket 30970 61 */ 62 public function test_setup_by_fake_post() { 63 $fake = new stdClass; 64 $fake->ID = 98765; 65 setup_postdata( $fake->ID ); 66 67 // Fails because there's no post with this ID. 68 $this->assertNotSame( $fake->ID, $GLOBALS['id'] ); 69 } 70 71 /** 72 * @ticket 30970 73 */ 74 public function test_setup_by_postish_object() { 75 $p = $this->factory->post->create(); 76 77 $post = new stdClass(); 78 $post->ID = $p; 79 setup_postdata( $p ); 80 81 $this->assertSame( $p, $GLOBALS['id'] ); 47 82 } 48 83
Note: See TracChangeset
for help on using the changeset viewer.