bonny / WordPress-Simple-History

🔍🕵️‍♀️ WordPress audit log that track user changes in WordPress admin using a nice activity feed.
https://simple-history.com
309 stars 69 forks source link

Feature Request: Show Meta Data Diff #192

Open Enchiridion opened 4 years ago

Enchiridion commented 4 years ago

When changes are made to a post, a diff is shown for the standard fields, ie title, content, status, but it'd be great if it could log all meta data changes as well. The custom post types I work with are mostly meta data. Thanks!

claytoncollie commented 3 years ago

I am also interested in this feature and have been working on it for a good part of my day. I can say that showing a diff is easy for WordPress custom fields but I am having trouble with ACF and Metabox custom fields. The old values are being retrieved but the new value are not. I think this is what you are after. I was able to accomplish this by installing the Classic Editor plugin then making two native custom fields.

image

@bonny Anything you can think of that would not allow for ACF or Metabox field values to be queried? I think it might have something to do with timing on this function.

https://github.com/bonny/WordPress-Simple-History/blob/66b8c7f94c8acae7a93d131e223561c29d247a37/loggers/SimplePostLogger.php#L103


Here is my code for displaying custom fields in a diff. Insert this on line 791

https://github.com/bonny/WordPress-Simple-History/blob/66b8c7f94c8acae7a93d131e223561c29d247a37/loggers/SimplePostLogger.php#L791

foreach ($old_meta as $diff_key => $old_diff_values) {
    $context["post_prev_{$diff_key}"] = $old_meta[$diff_key][0];
}

foreach ($new_meta as $new_diff_key => $new_diff_values) {
    $context["post_new_{$new_diff_key}"] = $new_diff_values[0];
}
bonny commented 1 year ago

This is also a requested feature in the support forums, for example: https://wordpress.org/support/topic/support-logging-changes-in-custom-fields/.

rodrigo-arias commented 1 week ago

@bonny This would be great, even if initially limited to text fields to simplify the presentation of before-after diffs.