Pods: Revision history for pod fields

Created on 18 Jun 2016  Â·  21Comments  Â·  Source: pods-framework/pods

Pretty much what these fine folk here are asking:
https://wordpress.org/support/topic/add-revision-history-to-custom-fields?replies=2

But then for the pods plugin and the fields it creates. So if someone edits a custom field on a custom post type it tracks the changes somewhere.

Also be able to clear the history and set the limit of how much is stored ,etc..

It could be packaged as a module you can enable or disable.

Need Dev Feedback Need Votes PR > Pending Code Review Feature

Most helpful comment

A follow-up:

Given the many challenges of saving revisions of custom fields in postmeta, we took another tack, using the Publish Press Revisions Pro plugin (which used to be Revisionary). It stores a revision of the entire page, including all custom fields, and provides a compare feature for the most recent revision.

The developer is working on an enhancement that stores multiple revisions but, for the moment, it works well and avoids the problem in WP core.

Thanks to everyone who has supported the various attempted work-arounds.

All 21 comments

see https://de.wordpress.org/plugins/wp-post-meta-revisions/ maybe that's all you need ;)

Does it support custom post types?

From reading this I'm not sure: https://wordpress.org/support/topic/custom-post-types-235?replies=1

How would I now use it for pods plugin?
Like this?

function add_meta_keys_to_revision( $keys ) {
    $keys[] = 'uname', 'suspision', 'other_name';
    return $keys;
}
add_filter( 'wp_post_revision_meta_keys', 'add_meta_keys_to_revision' );

if anyone is looking for a way to achieve this, I've made a gist that might help someone. Good luck!

Hi @JimSRush and others on this thread.

I added the gist mentioned above to our functions.php and custom field changes are still not triggering revisions (although title, author, and excerpt do).

I have also tried these plugins, no luck:

https://wordpress.org/plugins/wp-revisions-control/

https://wordpress.org/plugins/wp-post-meta-revisions/

@jaycollier I'd suggest you start by looking at what's happening in the $_REQUEST object - can you see your custom fields in there? They're prefixed by pods_meta.., so the gist may be failing at the isset step, where it checks to see if they're set.

Also, another thing you could try is double checking that this function is working properly, since this is the bit where it adds the list of fields to check changes against - if it's not working, it won't trigger a revision.

function my_revision_fields( $fields ) {
    // return the pod story type and extract the fields
    $story = pods('story');
    foreach ($story->fields as $key => $value) {
        $fields[$key] = $value['label'];
    }
    return $fields;
}
add_filter( '_wp_post_revision_fields', 'my_revision_fields' );

In this case, our pod name was 'story' so you'll need to change it to whatever the name of your pod is - apologies I didn't make this clear. I'll update the gist.

@jaycollier I've updated the gist with some more in depth comments - sorry about that - there's a couple of other things that you'll need to update. Please post your code here with your field names etc and I can take a closer look if you'd like?

Thanks, most of that makes sense to me (I missed the post type definition), except for one thing. I actually have over a dozen custom fields in the post type. Is there a method for checking and comparing that alleviates the need to duplicate those lines? (I am decidedly not a coder, just trying to fix this major problem with CPT/custom field revisions.)

@JimSRush thank you for doing this. I didn't expect it would take so long for the team or someone else to take note of this feature request and work something out but I'm very happy someone did that now. Haven't tested your gist yet but hope to do that soon.

I hope it works out for you @jaycollier!

There would definitely be a way, you'd need to loop through the request object and look for object keys that start with pods_meta.. and then use those ones. I'd suggest you start with just getting one to work, then cutting and pasting and getting the rest to work...a little bit of duplication isn't the worst thing in the world and then you can tidy up when you get it working.

The good thing is, you'll see it working after just one so you'll know you're on the right track.

That being said, we have about 8 custom fields, so if I end up refactoring to loop through I'll post the gist here and tag you.

Anyway, here's what it'll look like with multiples:

function my_save_post( $post_id, $post, $update ) {

    $parent_id = wp_is_post_revision( $post_id );

    if ( $parent_id ) {
        $parent  = get_post( $parent_id );
        $body = get_post_meta( $parent->ID, 'body', true );
        $first_meta = get_post_meta( $parent->ID, 'first_meta', true );
        $second_meta = get_post_meta( $parent->ID, 'second_meta', true );
        $third_meta = get_post_meta( $parent->ID, 'third_meta', true );
        $fourth_ meta = get_post_meta( $parent->ID, 'fourth_', true );

        if (isset($_REQUEST['pods_meta_body'])) {
            if ( false !== $body )
                add_metadata( 'post', $post_id, 'body', $_REQUEST['pods_meta_body'] );
        }
        if (isset($_REQUEST['pods_meta_first_meta'])) {
            if ( false !== $first_meta )
                add_metadata( 'post', $post_id, 'first_meta', $_REQUEST['pods_meta_first_meta'] );
        }
        if (isset($_REQUEST['pods_meta_second_meta])) {
            if ( false !== $second_meta )
                add_metadata( 'post', $post_id, 'second_meta', $_REQUEST['pods_meta_second_meta'] );
        }

//etc
    }
}

Thanks @bustapaladin ! Let me know if you hit any issues, and we can work through them and I'll update the gist/instructions if needed.

edit: just to clarify, not a pods team member but part of a team using pods who had this exact need :-)

Hi, JimSRush.

I have to admit, as a non-coder, I've not been able to grok this. I'm still disappointed that, even though Edit Pods > Advanced Options > Supports > Revisions is checked, it still doesn't include revisions of custom fields defined in Pods > Manage Fields.

As I wrote before, we have a half dozen Pods custom post types, each with 5-15 custom fields, and so an ad hoc method isn't sustainable. We're looking for programmatic method, either within the Pods plug-in or an add on.

I've been scouring the web for solutions and have tried each with no luck, perhaps because they were developed with earlier WP or Pods version.

We're so very hopeful that this will be seen as a priority. Our multiple editors need to see what changes their colleagues made to those custom fields in the past. Pods is getting a bad name with them, and I wish it didn't, because I love it!

Thanks to anyone who may have an update.

Hello @jaycollier

This isn't supported because WordPress simply doesn't support this. You'd have to submit a ticket here: https://core.trac.wordpress.org/ but I guess there are already numerous tickets on this topic.

Pods merely lets you enable revisions for post types (which is a WordPress function, not Pods). Taxonomies, Users, etc. all do not support revisions.

Unless @sc0ttkclark thinks differently I'd have to mark this as out of scope. Third party plugins/solutions/integrations like created by @JimSRush are always welcome of course!

UPDATE: I've marked it as "Need Votes" to let the community decide whether we look into this.

Thank you, Jory.

We are planning to try out PublishPress Revisions Pro (it used to be Revisionary). They are already supporting ACF and the developer has support for Pods custom fields in queue.

https://wordpress.org/plugins/revisionary/
https://publishpress.com/revisionary/

-Jay

@jaycollier Sounds good!

Follow up: We've also learned about a MetaBox extension that does pretty much exactly what we're looking for. Not sure if it supports custom fields created by non-MetaBox methods.

https://docs.metabox.io/extensions/mb-revision/

FYI: Sadly, not having revision history for custom fields — which we never expected — is turning into a showstopper for our clients who are pretty frustrated we chose Pods to develop our site.

There are solutions that can do this in a simple way for all custom fields, like this one: https://github.com/vavrecan/custom-fields-revisions

That could help you in the interim since it supports Pods.

FYI: Sadly, not having revision history for custom fields — which we never expected — is turning into a showstopper for our clients who are pretty frustrated we chose Pods to develop our site.

I'm sorry to hear that, but as you can see from all the plugins that are created for this functionality, this isn't something that is provided though WordPress core, Pods or other custom fields plugins unless specifically mentioned in the features list (I don't know of any).
Please check the plugin suggestion from @sc0ttkclark and let us know if that fits your project!

Thank you, @sc0ttkclark.

My lack of experience developing plugins may be the reason that, when I downloaded the master branch zip ("custom-fields-revisions-master.zip") from https://github.com/vavrecan/custom-fields-revisions and uploaded it, I received this error:

Installing Plugin from uploaded file: custom-fields-revisions-master.zip
Unpacking the package…
Installing the plugin…

The package could not be installed. No valid plugins were found.
Plugin installation failed.

Perhaps someone might point out the error of my ways.

You have to re-zip the "custom-fields-revisions" folder from within the master zip you've downloaded or manually upload that folder with FTP.

Thanks so much for the obvious tip. Unfortunately, after installing and making 3 revisions to a Pods CPT, a revision appears, but not the changed custom fields. We'll keep looking.

A follow-up:

Given the many challenges of saving revisions of custom fields in postmeta, we took another tack, using the Publish Press Revisions Pro plugin (which used to be Revisionary). It stores a revision of the entire page, including all custom fields, and provides a compare feature for the most recent revision.

The developer is working on an enhancement that stores multiple revisions but, for the moment, it works well and avoids the problem in WP core.

Thanks to everyone who has supported the various attempted work-arounds.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

HmCody picture HmCody  Â·  6Comments

sc0ttkclark picture sc0ttkclark  Â·  4Comments

wpstudio picture wpstudio  Â·  6Comments

garypaul picture garypaul  Â·  7Comments

jcampbell05 picture jcampbell05  Â·  5Comments