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中设置,以指定要保留的修订次数限制。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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
查看更多 >