[wp-trac] [WordPress Trac] #64104: author-template.php generates PHP Warning with PHP 8.3

WordPress Trac noreply at wordpress.org
Thu Oct 16 10:07:31 UTC 2025


#64104: author-template.php generates PHP Warning with PHP 8.3
--------------------------+-----------------------------
 Reporter:  Cornwell      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  6.8.3
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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

 This in WordPress release 6.8.3. 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.

 I appreciate the root cause may be that the function is called outside the
 loop, but this function should handle this. My suggested code achieves
 this.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64104>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list