Make WordPress Core


Ignore:
Timestamp:
11/17/2021 03:23:40 AM (3 years ago)
Author:
peterwilsoncc
Message:

Posts, Post Types: Use global post as the default for wp_get_post_parent_id().

Convert the $post parameter of wp_get_post_parent_id() to optional, defaulting to the current global post object when called within the loop.

Props danielpost, davidbaumwald, SergeyBiryukov, birgire, audrasjb, hellofromTonya, TimothyBlynJacobs.
Fixes #48358.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/wpGetPostParentId.php

    r49603 r52194  
    3434    }
    3535
     36    /**
     37     * @ticket 48358
     38     * @covers ::wp_get_post_parent_id
     39     */
     40    public function test_wp_get_post_parent_id_with_no_post_argument_default_to_global_post_id() {
     41        $GLOBALS['post'] = get_post( self::$post_id );
     42        $this->assertSame( self::$parent_post_id, wp_get_post_parent_id() );
     43    }
     44
    3645    public function test_wp_get_post_parent_id_with_non_existing_id_default_to_global_post_id() {
    3746        $GLOBALS['post'] = get_post( self::$post_id );
Note: See TracChangeset for help on using the changeset viewer.