Title: Post revisions
Author: WordPress VIP Documentation
Published: February 11, 2021
Last modified: November 7, 2024

---

 1. [WordPress on VIP](https://docs.wpvip.com/wordpress-on-vip/)
 2. Post revisions

#  Post revisions

[The revisions system in WordPress](https://wordpress.org/documentation/article/revisions/)
stores a record of each saved draft or published update. By default, the WordPress
VIP Platform sets revisions for a WordPress environment to unlimited (`-1`). This
default can be overridden by defining `WP_POST_REVISIONS` with a custom integer 
value in `[vip-config.php](https://docs.wpvip.com/wordpress-skeleton/vip-config-directory/)`
of the branch that deploys to the environment.

## Post revisions in imported databases

If a [database is imported](https://docs.wpvip.com/databases/import/) to a VIP environment
as part of a site migration, and a custom value for `WP_POST_REVISIONS` is _not_
defined in the application codebase for that environment, all revisions in the imported
database will be preserved.

If a custom value for `WP_POST_REVISIONS` _is_ defined in the application codebase
for that environment, the number of revisions that are preserved for a post will
be equal to the value set for `WP_POST_REVISIONS` the next time that post is edited.

## Set revision values per-network site

Logic can be added to define a custom value of `WP_POST_REVISIONS` to individual
network site(s) on a WordPress multisite environment. In this code example, the 
value of `WP_POST_REVISIONS` is defined as `500` for `example.com`, as `200` for`
example.org`, and as `100` for all other sites on the network.

vip-config/vip-config.php

    ```lang-php
    <?php

    // Use `$_SERVER['HTTP_HOST']` to fetch the current domain.
    // This ensures that the code applies the correct setting based on the active domain.
    if ( isset( $_SERVER['HTTP_HOST'] ) ) {
        $current_domain = $_SERVER['HTTP_HOST'];

        /*
         * Set post revisions limit based on domain.
         * 
         * - For `example.com`: Limit post revisions to 500.
         * - For `example.org`: Limit post revisions to 200.
         * 
         * Limiting revisions enhances performance by reducing the number of revisions 
         * stored in the database, which can significantly improve site performance 
         * on sites with frequent content updates.
         */
        $revisions_limit = match ($current_domain) {
            'example.com' => 500,
            'example.org' => 200,
            default => 100,
        };

        // Define the WP_POST_REVISIONS constant based on the matched domain.
        if ( ! defined( 'WP_POST_REVISIONS' ) ) {
            define('WP_POST_REVISIONS', $revisions_limit);
        }
    }
    ```

## Post draft autosave intervals

By default, WordPress automatically [saves a post draft every 60 seconds](https://developer.wordpress.org/reference/functions/wp_functionality_constants/).
Every autosave makes a post request in the background, sending the current content
to the database and saving it as a post revision. Increasing the amount of time 
between autosaves can have a positive effect on site performance, and is primarily
advantageous for a site that often has a large number of editors working concurrently.

To increase the time between autosave intervals, define `AUTOSAVE_INTERVAL` in [`vip-config.php`](https://docs.wpvip.com/wordpress-skeleton/vip-config-directory/)
to a value higher than `60`.

vip-config/vip-config.php

    ```lang-php
    define('AUTOSAVE_INTERVAL', 300 );
    ```

Last updated: November 07, 2024