Make WordPress Core

Ticket #48358: 48358.3.diff

File 48358.3.diff, 1.7 KB (added by peterwilsoncc, 3 years ago)
  • src/wp-includes/post.php

    diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
    index 286ad8ccf61..5a0671ac463 100644
    a b function _publish_post_hook( $post_id ) { 
    76427642 * Returns the ID of the post's parent.
    76437643 *
    76447644 * @since 3.1.0
     7645 * @since 5.9.0 The `$post` parameter was made optional.
    76457646 *
    7646  * @param int|WP_Post $post Post ID or post object.
     7647 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
    76477648 * @return int|false Post parent ID (which can be 0 if there is no parent),
    76487649 *                   or false if the post does not exist.
    76497650 */
    7650 function wp_get_post_parent_id( $post ) {
     7651function wp_get_post_parent_id( $post = null ) {
    76517652        $post = get_post( $post );
    76527653        if ( ! $post || is_wp_error( $post ) ) {
    76537654                return false;
  • tests/phpunit/tests/post/wpGetPostParentId.php

    diff --git a/tests/phpunit/tests/post/wpGetPostParentId.php b/tests/phpunit/tests/post/wpGetPostParentId.php
    index bd25232830b..b2a054239d2 100644
    a b public function test_wp_get_post_parent_id_with_post_id() { 
    3333                $this->assertSame( self::$parent_post_id, wp_get_post_parent_id( self::$post_id ) );
    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 );
    3847                $this->assertSame( self::$parent_post_id, wp_get_post_parent_id( 0 ) );