From 4a409d9c751e42055792d3f6a680bef8a24a645c Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 24 Oct 2025 04:04:26 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@61057 git-svn-id: http://core.svn.wordpress.org/trunk@60393 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/author-template.php | 37 ++++++++++++++++++++------------- wp-includes/version.php | 2 +- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/wp-includes/author-template.php b/wp-includes/author-template.php index a847fdcc16..3de4432b5e 100644 --- a/wp-includes/author-template.php +++ b/wp-includes/author-template.php @@ -86,24 +86,31 @@ function the_author( $deprecated = '', $deprecated_echo = true ) { * Retrieves the author who last edited the current post. * * @since 2.8.0 + * @since 6.9.0 Added the `$post` parameter. Unknown return value is now explicitly null instead of void. * - * @return string|void The author's display name, empty string if unknown. + * @param int|WP_Post|null $post Optional. Post ID or post object. Default is global `$post` object. + * @return string|null The author's display name. Empty string if user is unavailable. Null if there was no last editor or the post is invalid. */ -function get_the_modified_author() { - $last_id = get_post_meta( get_post()->ID, '_edit_last', true ); - - if ( $last_id ) { - $last_user = get_userdata( $last_id ); - - /** - * Filters the display name of the author who last edited the current post. - * - * @since 2.8.0 - * - * @param string $display_name The author's display name, empty string if unknown. - */ - return apply_filters( 'the_modified_author', $last_user ? $last_user->display_name : '' ); +function get_the_modified_author( $post = null ) { + $post = get_post( $post ); + if ( ! $post ) { + return null; } + + $last_id = get_post_meta( $post->ID, '_edit_last', true ); + if ( ! $last_id ) { + return null; + } + $last_user = get_userdata( $last_id ); + + /** + * Filters the display name of the author who last edited the current post. + * + * @since 2.8.0 + * + * @param string $display_name The author's display name, empty string if user is unavailable. + */ + return apply_filters( 'the_modified_author', $last_user ? $last_user->display_name : '' ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 71c9c1388c..888c40d663 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.9-beta1-61056'; +$wp_version = '6.9-beta1-61057'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.