Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #64314, comment 5


Ignore:
Timestamp:
12/12/2025 01:47:42 AM (5 months ago)
Author:
westonruter
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #64314, comment 5

    initial v1  
    77When saving a post that contains array/object postmeta, the editor displays “Updating failed.” and the REST API request returns an HTTP 500 error. The PHP error log shows the following fatal error:
    88
     9{{{
    910[29-Nov-2025 14:44:42 UTC] PHP Fatal error:  Uncaught TypeError: trim(): Argument #1 ($string) must be of type string, array given in /var/www/html/wordpress-test/wp-includes/formatting.php:5499
    1011Stack trace:
     
    3132#20 {main}
    3233  thrown in /var/www/html/wordpress-test/wp-includes/formatting.php on line 5499
     34}}}
    3335
    3436This confirms the issue described in this ticket: normalize_whitespace() calls trim(), which only accepts strings, but receives an array from $post->$field in wp_save_post_revision().
     
    3638After applying the proposed fix from PR 10560 and updating the comparison to serialize the values:
    3739
     40{{{#!php
     41<?php
    3842foreach ( array_keys( _wp_post_revision_fields( $post ) ) as $field ) {
    3943    if ( normalize_whitespace( serialize( $post->$field ) ) !== normalize_whitespace( serialize( $latest_revision->$field ) ) ) {
     
    4246    }
    4347}
     48
     49}}}
     50
    4451
    4552the fatal error no longer occurs.