Skip to content

Post revisions

The WordPress revisions system 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 of the branch that deploys to the environment.

Behavior of values set for WP_POST_REVISIONS:

  • -1: Store every revision (default).
  • (int) > 0: Store that many revisions (+1 autosave) per post; old revisions are automatically deleted.
  • 0: Do not store any revisions (except the one autosave per post).

Post revisions in imported databases

If a database is imported 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
<?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. 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 to a value higher than 60.

vip-config/vip-config.php
define('AUTOSAVE_INTERVAL', 300 );

Last updated: September 23, 2024

Relevant to

  • WordPress