[wp-trac] [WordPress Trac] #63028: PHP Warning caused by media.php and formatting.php

WordPress Trac noreply at wordpress.org
Thu Feb 27 06:38:38 UTC 2025


#63028: PHP Warning caused by media.php and formatting.php
--------------------------+-----------------------------
 Reporter:  isrgrajan     |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  6.7.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 == PHP Warning in media.php and formatting.php ==

 === Description ===

 A PHP warning occurs due to an "Array to string conversion" error during
 media processing. The error logs report:

 {{{
   #6 {main}
   thrown in /wp-includes/media.php on line 4531
   [25-Feb-2025 17:59:27 UTC] PHP Warning: Array to string conversion in
 /wp-includes/formatting.php on line 1096
 }}}
 === Steps to Reproduce ===
 * Process media uploads where the attachment's post parent is set as an
 array.

 === Proposed Fix ===
 Ensure the post parent is treated as a scalar value. For example, modify
 the code in media.php as follows:
 {{{
 if ( ! empty( $attachment->post_parent ) ) {
     $post_parent_id = is_array( $attachment->post_parent )
         ? reset( $attachment->post_parent )
         : $attachment->post_parent;
     $post_parent = get_post( $post_parent_id );
     if ( $post_parent ) {
         $response['uploadedToTitle'] = $post_parent->post_title ?
 $post_parent->post_title : __( '(no title)' );
         $response['uploadedToLink']  = get_edit_post_link(
 $post_parent_id, 'raw' );
     }
 }
 }}}

 === Impact ===
 This fix will prevent PHP warnings during media processing and ensure
 proper handling of attachment data.

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


More information about the wp-trac mailing list