How to Customize the Form Revisions Limit

Would you like to customize the form revisions limit for WPForms? Using a small PHP snippet, you can easily adjust how many revisions are saved or just disable this completely. In this tutorial, we’ll walk you through exactly how to achieve this.

By default, WPForms is automatically enabled to unlimited form revisions for all of your forms. However, post revisions can be disabled globally on a WordPress or server level. To learn more about post revisions from WordPress, please review their documentation.

If this is the case, you would use this tutorial to ensure that the revisions and the number of revisions you wish to store are controlled by you and the filter we will use in this tutorial.

To learn more about WPForms form revisions, please review the documentation.

Form Revision Limit

Before we create our form, we’re going to start by adding this snippet to our site.

If you need any assistance in how and where to add snippets to your site, please check out this tutorial.

Disabling form revisions

If you would like to disable the form revisions completely, just add this snippet to your site.

/**
 * Disable form revisions
 *
 * @link https://wpforms.com/developers/how-to-customize-the-form-revisions-limit/
 */

function wpf_dev_revisions_to_keep( $num, $post ) {
	
	// -1 for unlimited form revisions, set to 0 to disable form revisions completely
	// Control the form revisions number by setting the return value to a specific number
	return 0; 
	
}
add_filter( 'wp_wpforms_revisions_to_keep', 'wpf_dev_revisions_to_keep', 10, 2 );

By using this snippet, form revisions have been disabled. This doesn’t affect your global post revisions, only the WPForms revisions.

disable the form revisions by setting the return value to zero

Customizing the form revisions limit

If you have global post revisions enabled but you want to customize the WPForms form revisions limit, please use the following snippet.

/**
 * Customize form revisions limit
 *
 * @link https://wpforms.com/developers/how-to-customize-the-form-revisions-limit/
 */

function wpf_dev_revisions_to_keep( $num, $post ) {
	
	// -1 for unlimited form revisions, set to 0 to disable form revisions completely
	// Control the form revisions number by setting the return value to a specific number
	return 4; 
	
}
add_filter( 'wp_wpforms_revisions_to_keep', 'wpf_dev_revisions_to_keep', 10, 2 );

With this snippet, we’re storing the last 4 revisions. You can use any number here and that is the number of revisions WPForms will store.

this snippet is limiting the forms revision to store the last 4 revisions

Please see the next section to set the form revisions limit to unlimited.

Enabling unlimited form revisions

This snippet is designed specifically if your post revisions on WordPress or your server are disabled. Using this snippet would not only enable WPForms form revisions but will also set the form revisions limit to unlimited.

WPForms will display a message to let you know if the global setting for post revisions is disabled.

you will see a message letting you know if your global post revisions are disabled

For the purpose of this tutorial, we not only want to enable form revisions, we also want to set the form revisions to store an unlimited amount. To do this, we’re going to add this snippet to our site.

/**
 * Enable unlimited post revisions for WPForms
 *
 * @link https://wpforms.com/developers/how-to-customize-the-form-revisions-limit/
 */

function wpf_dev_revisions_to_keep( $num, $post ) {
	
	// -1 for unlimited form revisions, set to 0 to disable form revisions completely
	// Control the form revisions number by setting the return value to a specific number
	return -1; 
	
}
add_filter( 'wp_wpforms_revisions_to_keep', 'wpf_dev_revisions_to_keep', 10, 2 );

With this snippet, you won’t see a message at all since the form revisions limit is now set to -1, which is unlimited. You’ll only see a list of all the revisions.

using this snippet will not only make sure WPForms form revisions are enabled, it also sets the form revisions to unlimited

And that’s all you need! Would you like to set a default image for all of your post submissions? Check out our tutorial on How to Set a Default Featured Image for Post Submissions.