wp_revisions_to_keep

函式
wp_revisions_to_keep ( $post )
引數
  • (WP_Post) $post The post object.
    Required:
返回值
  • (int) The number of revisions to keep.
定義位置
相關方法
wp_revisions_enabledwp_post_revision_title_wp_upgrade_revisions_of_postwp_get_session_tokenwp_print_revision_templates
引入
3.6.0
棄用
-

wp_revisions_to_keep: 這是一個WordPress的函式,用來獲取一個特定的文章型別所要保留的文章修訂數量。它以文章型別為引數,並返回需要保留的修訂數量。

決定為一個給定的文章保留多少次修訂。

預設情況下,會保留無限多的修訂。

常數WP_POST_REVISIONS可以在wp-config中設定,以指定要保留的修訂次數限制。

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

常見問題

FAQs
檢視更多 >