[wp-meta] [Making WordPress.org] #8105: author-template.php generates PHP Warning with PHP 8.3

Making WordPress.org noreply at wordpress.org
Wed Oct 15 17:11:20 UTC 2025


#8105: author-template.php generates PHP Warning with PHP 8.3
--------------------------+--------------------
 Reporter:  Cornwell      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:
Component:  General       |   Keywords:
--------------------------+--------------------
 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://meta.trac.wordpress.org/ticket/8105>
Making WordPress.org <https://meta.trac.wordpress.org/>
Making WordPress.org


More information about the wp-meta mailing list