返回介绍

wp_revisions_to_keep()

发布于 2017-09-11 12:46:41 字数 3018 浏览 1028 评论 0 收藏 0

wp_revisions_to_keep( WP_Post $post )

Determine how many revisions to retain for a given post.


description

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.


参数

$post

(WP_Post) (Required) The post object.


返回值

(int) The number of revisions to keep.


源代码

File: wp-includes/revision.php

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 );
}

更新日志

Versiondescription
3.6.0Introduced.

相关函数

Uses

  • wp-includes/plugin.php: apply_filters()
  • wp-includes/post.php: post_type_supports()
  • wp-includes/revision.php: wp_revisions_to_keep

Used By

  • wp-includes/revision.php: wp_revisions_enabled()
  • wp-includes/revision.php: wp_save_post_revision()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Example

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

    
    /**
     * Notify the User When they are editing a post that has reached the limit defined by wp_revisions_to_keep
     */
    function wpdocs_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
        }
    }
    add_action( 'admin_notices', 'wpdocs_myplugin_admin_notices' );
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文