WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp revisions to keep

Description

Determine how many revisions to retain for a given post. By default, an infinite number of revisions are stored if a post type supports revisions.

Parameters

$post
(object) (required) The Post object.
Default: None

Return

(int) 
The number of revisions to keep.

Usage

 <?php wp_revisions_to_keep$post )  ?> 

Example

This code notifies a user when the post they are working has reached the limit defined by wp_revisions_to_keep

add_action( 'admin_notices', 'myplugin_admin_notices' );

/**
 * Notify the User When they are editing a post that has reached the limit defined by wp_revisions_to_keep
 */
function myplugin_admin_notices() {
    global $post;
    $revisions = wp_get_post_revisions( $post->ID );
    if ( isset( $post ) && wp_revisions_to_keep( $post ) <= count( $revisions ) ) { ?>
        <div class="error">
            <p><?php _e( 'Maximum number of revisions reached. Explain some more to your users here', 'myplugin-text-domain' ); ?></p>
        </div>
    <?php
    }
}

Change Log

Source File

wp_revisions_to_keep() is located in wp-includes/revision.php.

Related

Function ref links

This article is marked as in need of editing. You can help Codex by editing it.
This page is marked as incomplete. You can help Codex by expanding it.