• Resolved Cornwell

    (@cornwell)


    I am seeing the following warning message in my php error log:
    PHP Warning: Attempt to read property “ID” on null in /home/[userid]/public_html/wp-includes/author-template.php on line 93

    Line 93 is

    $last_id = get_post_meta( get_post()->ID, '_edit_last', true );

    It occurs in this function:

    /**
    * Retrieves the author who last edited the current post.
    *
    * @since 2.8.0
    *
    * @return string|void The author's display name, empty string if unknown.
    */
    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 : '' );
    }
    }

    I think this code relies on line 93 returning a null value if the ID has not been set (as would probably be the case if the function were called outside the loop). However, php at current releases (mine is at 8.3) generates a warning message and this is filling my logs.

    My solution has been to replace line 93 with

    if ( isset(get_post()->ID) ) {
    $last_id = get_post_meta( get_post()->ID, '_edit_last', true );
    } else {
    $last_id = '';
    }

    Since implementing this change no errors have been flagged.

    Is this something I might suggest as a fix?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You may, though the real problem is calling the function outside of the loop. That is unclear to me, it may require a debug backtrace to find out.

    None the less, validating assumed data is never a bad idea. You can create a Trac ticket regarding this so it can be properly tracked. Suggestions here in the forums tend to get lost. Please do a search first to ensure something about this hasn’t already been posted.

    Thread Starter Cornwell

    (@cornwell)

    Thanks. I did search this forum back to 2019 and found nothing. I’ll create a Trac ticket.

    Moderator Support Moderator

    (@moderator)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘author-template.php generates PHP Warning with PHP 8.3’ is closed to new replies.