Support

Account

Home Forums General Issues Save Post Revisions Reply To: Save Post Revisions

  • I have recently found something new that might help those looking to prevent multiple revisions. Please note that I have not tested this and it is just speculation at this time.

    This filter in WP is called just before saving a post revision

    
    $post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post );
    

    So, using this hook you could

    
    add_filter('wp_save_post_revision_post_has_changed', 'my_prevent_post_revisions', 10, 3);
    function my_prevent_post_revisions($post_has_changed, $last_revision, $post) {
      // here you can do some checking
      // for example if you only want to prevent revisions on a specific post type
      // return false to prevent post revision
    
      return $post_has_changed;
    }
    

    Then in your filter or function where you want the revision to be saved

    
    // remove the prevent post revision filter
    remove_filter('wp_save_post_revision_post_has_changed', 'my_prevent_post_revisions', 10);
    
    // update the post
    wp_update_post($args)
    
    // add the filter again
    add_filter('wp_save_post_revision_post_has_changed', 'my_prevent_post_revisions', 10, 3);
    
    

    If anyone has a chance to test this let us know.