Include fields in revisions

Viewing 2 posts - 1 through 2 (of 2 total)



I’m working on a website that uses Download Manager Pro and revisions are enabled for Download Manager post type.
The fields __wpdm_files, __wpdm_version and __wpdm_fileinfo are included to be saved in revisions.

When I publish or update a Download Manager post type, for example, there is a warning in PHP 7.4 :
Warning: trim() expects parameter 1 to be string, array given in [sitePath]/wp-includes/formatting.php on line 5365

It’s because the normalize_whitespace function expecting a string.

When I use PHP 8.1, it has become a fatal error :
Fatal error: Uncaught TypeError: trim(): Argument #1 ($string) must be of type string, array given in [sitePath]/wp-includes/formatting.php:5365 Stack trace: #0 [sitePath]/wp-includes/formatting.php(5365): trim(Array) #1 [sitePath]/wp-includes/revision.php(163): normalize_whitespace(Array)

How can I include this fields with PHP 8.1 without to patch the normalize_whitespace function ?

Thank you for your help.




Hello David,

Thanks for contacting us.

To include the fields “__wpdm_files”, “__wpdm_version”, and “__wpdm_fileinfo” in revisions without patching the normalize_whitespace function, you can utilize the WordPress filter hooks available for modifying the behavior of saving revisions.

You can use the “wp_save_post_revision_check_for_changes” filter hook to add your custom fields to the list of fields that are checked for changes when saving a revision.

By adding these fields to the $fields_to_check array, you’re telling WordPress to consider them when determining if a revision needs to be created.

This approach allows you to include your custom fields in revisions without modifying the core WordPress files or patching the normalize_whitespace function.


Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Include fields in revisions’ is closed to new replies.