Make WordPress Core


Ignore:
Timestamp:
10/24/2025 04:02:03 AM (7 weeks ago)
Author:
westonruter
Message:

Posts, Post Types: Update get_the_modified_author() to handle missing global $post and add (missing) $post arg.

The addition of the $post argument (which defaults to the global post) brings get_the_modified_author() in line with other similar functions, including get_the_modified_date() and get_the_modified_time().

Props Cornwell, jdahir0789, dhruvang21, Presskopp, mindctrl, samirmalpande, audrasjb, johnbillion, SergeyBiryukov, desrosj, costdev, mukesh27, westonruter.
Fixes #64104, #55978.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/getTheModifiedAuthor.php

    r55755 r61057  
    3838        parent::set_up();
    3939
    40         $GLOBALS['post'] = self::$post_id;
     40        $GLOBALS['post'] = get_post( self::$post_id );
    4141    }
    4242
     
    5757        $this->assertSame( '', get_the_modified_author() );
    5858    }
     59
     60    /**
     61     * @ticket 64104
     62     */
     63    public function test_get_the_modified_author_when_post_global_does_not_exist() {
     64        $GLOBALS['post'] = null;
     65        $this->assertNull( get_the_modified_author() );
     66    }
     67
     68    /**
     69     * @ticket 64104
     70     */
     71    public function test_get_the_modified_author_when_invalid_post() {
     72        $this->assertNull( get_the_modified_author( -1 ) );
     73    }
     74
     75    /**
     76     * @ticket 64104
     77     */
     78    public function test_get_the_modified_author_for_another_post() {
     79        $expected_display_name = 'Test Editor';
     80
     81        $editor_id = self::factory()->user->create(
     82            array(
     83                'role'         => 'editor',
     84                'user_login'   => 'test_editor',
     85                'display_name' => $expected_display_name,
     86                'description'  => 'test_editor',
     87            )
     88        );
     89
     90        $another_post_id = self::factory()->post->create();
     91
     92        $this->assertNull( get_the_modified_author( $another_post_id ) );
     93        $this->assertNull( get_the_modified_author( get_post( $another_post_id ) ) );
     94
     95        add_post_meta( $another_post_id, '_edit_last', $editor_id );
     96        $this->assertSame( $expected_display_name, get_the_modified_author( $another_post_id ) );
     97        $this->assertSame( $expected_display_name, get_the_modified_author( get_post( $another_post_id ) ) );
     98    }
    5999}
Note: See TracChangeset for help on using the changeset viewer.