wp_revisions_to_keep

Determine how many revisions to retain for a given post.

Description

(int) wp_revisions_to_keep( (WP_Post) $post ); 

By default, an infinite number of revisions are kept.

The constant WP_POST_REVISIONS can be set in wp-config to specify the limit of revisions to keep.

Returns (int)

The number of revisions to keep.

Parameters (1)

0. $post (WP_Post)
The post object.

Usage

  1. if ( !function_exists( 'wp_revisions_to_keep' ) ) { 
  2. require_once ABSPATH . WPINC . '/revision.php'; 
  3.  
  4. // The post object. 
  5. $post = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_revisions_to_keep($post); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/revision.php  
  1. function wp_revisions_to_keep( $post ) { 
  2.  
  3. if ( true === $num ) 
  4. $num = -1; 
  5. else 
  6. $num = intval( $num ); 
  7.  
  8. if ( ! post_type_supports( $post->post_type, 'revisions' ) ) 
  9. $num = 0; 
  10.  
  11. /** 
  12. * Filters the number of revisions to save for the given post. 
  13. * Overrides the value of WP_POST_REVISIONS
  14. * @since 3.6.0 
  15. * @param int $num Number of revisions to store. 
  16. * @param WP_Post $post Post object. 
  17. */ 
  18. return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );