wp_revisions_to_keep

The timeline below displays how wordpress function wp_revisions_to_keep has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Determines how many revisions to retain for a given 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.
 *
 * @since 3.6.0
 *
 * @param WP_Post $post The post object.
 * @return int The number of revisions to keep.
 */
function wp_revisions_to_keep($post)
{
    $num = WP_POST_REVISIONS;
    if (true === $num) {
        $num = -1;
    } else {
        $num = (int) $num;
    }
    if (!post_type_supports($post->post_type, 'revisions')) {
        $num = 0;
    }
    /**
     * Filters the number of revisions to save for the given post.
     *
     * Overrides the value of WP_POST_REVISIONS.
     *
     * @since 3.6.0
     *
     * @param int     $num  Number of revisions to store.
     * @param WP_Post $post Post object.
     */
    $num = apply_filters('wp_revisions_to_keep', $num, $post);
    /**
     * Filters the number of revisions to save for the given post by its post type.
     *
     * Overrides both the value of WP_POST_REVISIONS and the {@see 'wp_revisions_to_keep'} filter.
     *
     * The dynamic portion of the hook name, `$post->post_type`, refers to
     * the post type slug.
     *
     * Possible hook names include:
     *
     *  - `wp_post_revisions_to_keep`
     *  - `wp_page_revisions_to_keep`
     *
     * @since 5.8.0
     *
     * @param int     $num  Number of revisions to store.
     * @param WP_Post $post Post object.
     */
    $num = apply_filters("wp_{$post->post_type}_revisions_to_keep", $num, $post);
    return (int) $num;
}

WordPress Version: 5.9

/**
 * Determine how many revisions to retain for a given 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.
 *
 * @since 3.6.0
 *
 * @param WP_Post $post The post object.
 * @return int The number of revisions to keep.
 */
function wp_revisions_to_keep($post)
{
    $num = WP_POST_REVISIONS;
    if (true === $num) {
        $num = -1;
    } else {
        $num = (int) $num;
    }
    if (!post_type_supports($post->post_type, 'revisions')) {
        $num = 0;
    }
    /**
     * Filters the number of revisions to save for the given post.
     *
     * Overrides the value of WP_POST_REVISIONS.
     *
     * @since 3.6.0
     *
     * @param int     $num  Number of revisions to store.
     * @param WP_Post $post Post object.
     */
    $num = apply_filters('wp_revisions_to_keep', $num, $post);
    /**
     * Filters the number of revisions to save for the given post by its post type.
     *
     * Overrides both the value of WP_POST_REVISIONS and the {@see 'wp_revisions_to_keep'} filter.
     *
     * The dynamic portion of the hook name, `$post->post_type`, refers to
     * the post type slug.
     *
     * Possible hook names include:
     *
     *  - `wp_post_revisions_to_keep`
     *  - `wp_page_revisions_to_keep`
     *
     * @since 5.8.0
     *
     * @param int     $num  Number of revisions to store.
     * @param WP_Post $post Post object.
     */
    $num = apply_filters("wp_{$post->post_type}_revisions_to_keep", $num, $post);
    return (int) $num;
}

WordPress Version: 5.8

/**
 * Determine how many revisions to retain for a given 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.
 *
 * @since 3.6.0
 *
 * @param WP_Post $post The post object.
 * @return int The number of revisions to keep.
 */
function wp_revisions_to_keep($post)
{
    $num = WP_POST_REVISIONS;
    if (true === $num) {
        $num = -1;
    } else {
        $num = (int) $num;
    }
    if (!post_type_supports($post->post_type, 'revisions')) {
        $num = 0;
    }
    /**
     * Filters the number of revisions to save for the given post.
     *
     * Overrides the value of WP_POST_REVISIONS.
     *
     * @since 3.6.0
     *
     * @param int     $num  Number of revisions to store.
     * @param WP_Post $post Post object.
     */
    $num = apply_filters('wp_revisions_to_keep', $num, $post);
    /**
     * Filters the number of revisions to save for the given post by its post type.
     *
     * Overrides both the value of WP_POST_REVISIONS and the {@see 'wp_revisions_to_keep'} filter.
     *
     * The dynamic portion of the hook name, `$post->post_type`, refers to
     * the post type slug.
     *
     * @since 5.8.0
     *
     * @param int     $num  Number of revisions to store.
     * @param WP_Post $post Post object.
     */
    $num = apply_filters("wp_{$post->post_type}_revisions_to_keep", $num, $post);
    return (int) $num;
}

WordPress Version: 5.6

/**
 * Determine how many revisions to retain for a given 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.
 *
 * @since 3.6.0
 *
 * @param WP_Post $post The post object.
 * @return int The number of revisions to keep.
 */
function wp_revisions_to_keep($post)
{
    $num = WP_POST_REVISIONS;
    if (true === $num) {
        $num = -1;
    } else {
        $num = (int) $num;
    }
    if (!post_type_supports($post->post_type, 'revisions')) {
        $num = 0;
    }
    /**
     * Filters the number of revisions to save for the given post.
     *
     * Overrides the value of WP_POST_REVISIONS.
     *
     * @since 3.6.0
     *
     * @param int     $num  Number of revisions to store.
     * @param WP_Post $post Post object.
     */
    return (int) apply_filters('wp_revisions_to_keep', $num, $post);
}

WordPress Version: 4.6

/**
 * Determine how many revisions to retain for a given 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.
 *
 * @since 3.6.0
 *
 * @param WP_Post $post The post object.
 * @return int The number of revisions to keep.
 */
function wp_revisions_to_keep($post)
{
    $num = WP_POST_REVISIONS;
    if (true === $num) {
        $num = -1;
    } else {
        $num = intval($num);
    }
    if (!post_type_supports($post->post_type, 'revisions')) {
        $num = 0;
    }
    /**
     * Filters the number of revisions to save for the given post.
     *
     * Overrides the value of WP_POST_REVISIONS.
     *
     * @since 3.6.0
     *
     * @param int     $num  Number of revisions to store.
     * @param WP_Post $post Post object.
     */
    return (int) apply_filters('wp_revisions_to_keep', $num, $post);
}

WordPress Version: 4.1

/**
 * Determine how many revisions to retain for a given 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.
 *
 * @since 3.6.0
 *
 * @param WP_Post $post The post object.
 * @return int The number of revisions to keep.
 */
function wp_revisions_to_keep($post)
{
    $num = WP_POST_REVISIONS;
    if (true === $num) {
        $num = -1;
    } else {
        $num = intval($num);
    }
    if (!post_type_supports($post->post_type, 'revisions')) {
        $num = 0;
    }
    /**
     * Filter the number of revisions to save for the given post.
     *
     * Overrides the value of WP_POST_REVISIONS.
     *
     * @since 3.6.0
     *
     * @param int     $num  Number of revisions to store.
     * @param WP_Post $post Post object.
     */
    return (int) apply_filters('wp_revisions_to_keep', $num, $post);
}

WordPress Version: 3.9

/**
 * 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.
 *
 * @since 3.6.0
 *
 * @uses post_type_supports()
 *
 * @param object $post The post object.
 * @return int The number of revisions to keep.
 */
function wp_revisions_to_keep($post)
{
    $num = WP_POST_REVISIONS;
    if (true === $num) {
        $num = -1;
    } else {
        $num = intval($num);
    }
    if (!post_type_supports($post->post_type, 'revisions')) {
        $num = 0;
    }
    /**
     * Filter the number of revisions to save for the given post.
     *
     * Overrides the value of WP_POST_REVISIONS.
     *
     * @since 3.6.0
     *
     * @param int     $num  Number of revisions to store.
     * @param WP_Post $post Post object.
     */
    return (int) apply_filters('wp_revisions_to_keep', $num, $post);
}

WordPress Version: 3.7

/**
 * 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.
 *
 * @since 3.6.0
 *
 * @uses post_type_supports()
 * @uses apply_filters() Calls 'wp_revisions_to_keep' hook on the number of revisions.
 *
 * @param object $post The post object.
 * @return int The number of revisions to keep.
 */
function wp_revisions_to_keep($post)
{
    $num = WP_POST_REVISIONS;
    if (true === $num) {
        $num = -1;
    } else {
        $num = intval($num);
    }
    if (!post_type_supports($post->post_type, 'revisions')) {
        $num = 0;
    }
    return (int) apply_filters('wp_revisions_to_keep', $num, $post);
}