Home › Forums › Front-end Issues › No revision when update from front end › Reply To: No revision when update from front end
UPDATE: disregard this hack. See next post for a more complete solution.
Ok so I’ve made a little progress on the concept of revisioning with acf_form() but is admittedly a hack. It will revision a post but for some reason, not until the 2nd change. I’m still working on it but I’m posting it here in hopes that someone else can expand on or replace with a more elegant solution.
Basically I’m hijacking ‘pre_save_post’ and instead of letting it alter post meta for the existing post, I’m forcing the creation of a revision and letting acf act on that new post ID instead. Of course we still want the active post to get updated so I’m manually calling an un-documented acf function which obviously is a very bad approach.
function my_pre_save_post( $post_id ) {
// bail early if editing in admin
if( is_admin() ) {
return;
}
// bail if this is a brand new post
if ( ! is_numeric($post_id) ) {
return $post_id;
}
acf_save_post( $post_id );
add_filter( 'wp_save_post_revision_check_for_changes', 'on_forced_revision', 10, 3 );
$new_id = wp_save_post_revision( $post_id );
remove_filter( 'wp_save_post_revision_check_for_changes', 'on_forced_revision', 10 );
// return the new ID
return $new_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post', 1, 2 );
function on_forced_revision($check_for_changes, $last_revision, $post) {
if( isset($_POST['_acfchanged']) && $_POST['_acfchanged'] == '1' )
{
return false;
}
return $check_for_changes;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.