Make WordPress Core


Ignore:
Timestamp:
10/24/2025 04:02:03 AM (6 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/src/wp-includes/author-template.php

    r60644 r61057  
    8787 *
    8888 * @since 2.8.0
    89  *
    90  * @return string|void The author's display name, empty string if unknown.
    91  */
    92 function get_the_modified_author() {
    93     $last_id = get_post_meta( get_post()->ID, '_edit_last', true );
    94 
    95     if ( $last_id ) {
    96         $last_user = get_userdata( $last_id );
    97 
    98         /**
    99          * Filters the display name of the author who last edited the current post.
    100          *
    101          * @since 2.8.0
    102          *
    103          * @param string $display_name The author's display name, empty string if unknown.
    104          */
    105         return apply_filters( 'the_modified_author', $last_user ? $last_user->display_name : '' );
    106     }
     89 * @since 6.9.0 Added the `$post` parameter. Unknown return value is now explicitly null instead of void.
     90 *
     91 * @param int|WP_Post|null $post Optional. Post ID or post object. Default is global `$post` object.
     92 * @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.
     93 */
     94function get_the_modified_author( $post = null ) {
     95    $post = get_post( $post );
     96    if ( ! $post ) {
     97        return null;
     98    }
     99
     100    $last_id = get_post_meta( $post->ID, '_edit_last', true );
     101    if ( ! $last_id ) {
     102        return null;
     103    }
     104    $last_user = get_userdata( $last_id );
     105
     106    /**
     107     * Filters the display name of the author who last edited the current post.
     108     *
     109     * @since 2.8.0
     110     *
     111     * @param string $display_name The author's display name, empty string if user is unavailable.
     112     */
     113    return apply_filters( 'the_modified_author', $last_user ? $last_user->display_name : '' );
    107114}
    108115
Note: See TracChangeset for help on using the changeset viewer.