[wp-trac] [WordPress Trac] #64314: Fatal error when enabling revisions for post meta of type array/object
WordPress Trac
noreply at wordpress.org
Fri Dec 12 01:48:49 UTC 2025
#64314: Fatal error when enabling revisions for post meta of type array/object
--------------------------+--------------------------
Reporter: LAPSrj | Owner: westonruter
Type: defect (bug) | Status: reviewing
Priority: normal | Milestone: 7.0
Component: Revisions | Version: 6.4
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
--------------------------+--------------------------
Description changed by westonruter:
Old description:
> Since WordPress 6.4 it is now possible to enable revisions for post meta.
> However when verifying if there are changes in the meta fields the
> function expects only strings, breaking if the meta format is array or
> object.
>
> How to reproduce the bug:
> - Register a post meta of type array/object
> - Set a value for it in a post
> - Try to save the post
>
> The API request to save the post will fail, returning a 500 error. The
> PHP log will list say:
>
> PHP Fatal error: Uncaught TypeError: trim(): Argument #1 ($string)
> must be of type string, array given
>
> The cause of the error is the function `wp_save_post_revision`, at `wp-
> includes/revision.php`. At line 190 it uses `normalize_whitespace(
> $post->field )`, which only works with strings, however `$post->field`
> will be an array if the meta is an array and that will cause the fatal
> error.
>
> Since this is a supported feature since WordPress 6.4 and is causing
> fatal errors, I'm setting the severity to critical. Even though the issue
> is with meta fields, I'm setting the component as "Posts, Post Types"
> because the issue is at the part that handles saving the revisions and
> the same code is used both to fetch post attributes and post meta.
New description:
Since WordPress 6.4 it is now possible to enable revisions for post meta.
However when verifying if there are changes in the meta fields the
function expects only strings, breaking if the meta format is array or
object.
How to reproduce the bug:
- Register a post meta of type array/object
- Set a value for it in a post
- Try to save the post
The API request to save the post will fail, returning a 500 error. The PHP
log will list say:
`PHP Fatal error: Uncaught TypeError: trim(): Argument #1 ($string)
must be of type string, array given`
The cause of the error is the function `wp_save_post_revision`, at `wp-
includes/revision.php`. At line 190 it uses `normalize_whitespace(
$post->field )`, which only works with strings, however `$post->field`
will be an array if the meta is an array and that will cause the fatal
error.
Since this is a supported feature since WordPress 6.4 and is causing fatal
errors, I'm setting the severity to critical. Even though the issue is
with meta fields, I'm setting the component as "Posts, Post Types" because
the issue is at the part that handles saving the revisions and the same
code is used both to fetch post attributes and post meta.
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64314#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list