htmlburger / carbon-fields

WordPress Custom Fields Library ✨
https://carbonfields.net/
Other
1.34k stars 241 forks source link

Post Revisions Support #118

Closed kshaner closed 5 years ago

kshaner commented 7 years ago

Is storing revisions of postmeta of carbon fields radar or is the intention to rely on a separate plugin? This becomes important when laying our your content within carbon fields instead of the post_content field.

I can look into creating a pull request but wanted to make sure it wasn't being actively worked on.

m1r0 commented 7 years ago

Interesting idea @kshaner, right now this is not on the features list, but I think it can be really valuable for some people. A pull request will be highly appreciated!

Santana1053 commented 7 years ago

Because carbon fields use post metadata, different revisions should be updated through the wordpress revision history. The only problem is, wordpress only tracks revisions by what was changed inside of the content editor. If you don't even use the content editor on a page then there just isn't any revision history at all.

timiwahalahti commented 6 years ago

I'm working to make post revisions support (and in the same time preview support, because basically those are revisions...) and basically the functionality for basic fields is there. Fields saved in one meta row works nicely, but complex and other fields saved in multiple rows is causing some headache...

houstona commented 6 years ago

This is something we are looking to have as well.

timiwahalahti commented 6 years ago

Because CF uses it's own methods to get metadata (direct database queries :o) I couldn't implement this as a part of CF core yet. It would have been just too much work at the moment for this quite urgent demand.

Instead I added the support via our own plugin, air helper. It needs some manual settings and it expects that get_post_meta is used instead of CF's own functions, for complex fields there is own function called dude_get_post_meta.

And the manual part is telling which fields should support preview

function ghcf118_revision_keys( $keys ) {
    $keys['_hero_title'] = true;
    $keys['_hero_subtitle'] = true;
    $keys['_upsell_boxes'] = 'complex';
    return $keys;
}
add_filter( 'wp_post_revision_meta_keys', 'ghcf118_revision_keys' );

Not ideal solution, but works...

houstona commented 6 years ago

Is this in the works to get added as a feature?

houstona commented 6 years ago

Has there been any work done to add this? @m1r0

martinhahn commented 6 years ago

We are wondering whether the post revision support would also solve the problem of the not working preview mode. Any experiences so far, @timiwahalahti ?

timiwahalahti commented 6 years ago

@martinhahn Not as straight as you might think, but it is doable with this plugin https://github.com/adamsilverstein/wp-post-meta-revisions and some custom functions I wrote quickly https://github.com/digitoimistodude/air-helper/blob/master/inc/carbonfields.php#L37

Best option would definitely be adding revsion and preview support to CRB core. That custom functionality what I wrote, runs into small issues when having complex, map etc fields.

89gsc commented 5 years ago

This sort of feature would be pretty valuable for a site where content managment is done heavily using CF's for example I have built the theme based off using CF's complex feilds in a similar fashion to using ACF's flexible content layouts.

I would in hindsight have gone the ACF route if I had known the client wanted revision support sooner in the project as ACF supports revisions out of the box.

emohamed commented 5 years ago

@gsc89 thanks for the feedback. We realize that this is an important feature and we intend to build it for Carbon Fields.

For time being, you can work around the missing feature by following the approach @timiwahalahti suggested in an earlier comment. Hope that this will be sufficient for your project.

89gsc commented 5 years ago

Yeah I appericiate this is not a commerical project and everyone is giving up free time to work on things like this and the difficulty in implimenting it given the way meta is stored and retrived with carbon fields.

I was just a little bummed when I came across the lack of revision support when a client asked me why they couldn't see revisions and I had one of those "Oh Sh*t..." moments. I will have a look into the method @timiwahalahti outlines for now.

Thanks for coming back to me @emohamed and everyone who puts time into this project.

kshaner commented 5 years ago

@gsc89, this has been what i've used in the meantime: https://wordpress.org/plugins/wp-post-meta-revisions/

I look forward to it being in the core plugin. I started a fork to implement this a while back, but abandoned it before the 2.0 rewrite and haven't been able to revisit.

89gsc commented 5 years ago

Thanks @kshaner appreciate the link I will take a look, do you know of any crevats in functionality using that pluing in combination with CF?

emohamed commented 5 years ago

Just wanted to note that CF V3 will come with revisions support -- the feature is being developed in branch v3-revisions

emohamed commented 5 years ago

This feature has shipped in v3 🚢

PayteR commented 5 years ago

Hi, @emohamed

  1. is there a way to disable this feature? I don't want to bloat my postmeta table
  2. is there a way to store nothing on blank (null, false or "") value?

thank you

atanas-vasilev-dev commented 5 years ago

Hello @PayteR

There's a per-container method (Post meta only) that allows you to disable the revisions. The method is called set_revisions_disabled. You can call it while defining your container and it's chainable like the other regular container methods.

PayteR commented 5 years ago

@atanas-angelov-dev it works, thank you. It's worth to note, that argument true must be passed:

->set_revisions_disabled(true)

Could you answer my second question too please?

atanas-dev commented 5 years ago

@PayteR wrong Atanas lol pinging @atanas-vasilev-dev for you :)

atanas-vasilev-dev commented 5 years ago

@PayteR That's correct, you can disable the revisions if you pass true or enable them if you pass false (they are enabled by default).

The documentation for post meta containers will be updated with information on post meta revisions soon.

atanas-vasilev-dev commented 5 years ago

Sorry, just realized that I didn't reply to this one:

is there a way to store nothing on blank (null, false or "") value?

No, there's no option to store a blank value.

PayteR commented 5 years ago

@atanas-vasilev-dev do you plan to add this feature, or filter to make it possible?