WordPress开发者和主题制作者的搜索引擎



wp_get_post_autosave ›

Since2.6.0
已弃用n/a
wp_get_post_autosave ( $post_id, $user_id = 0 )
参数: (2)
  • (int) $post_id The post ID.
    Required: Yes
  • (int) $user_id Optional The post author ID.
    Required: No
    默认:
返回:
  • (WP_Post|false) The autosaved data or false on failure or when no autosave exists.
定义在:
文档:

Retrieve the autosaved data of the specified post.

Returns a post object containing the information that was autosaved for the specified post. If the optional $user_id is passed, returns the autosave for that user otherwise returns the latest autosave.



源码

function wp_get_post_autosave( $post_id, $user_id = 0 ) {
	$revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) );

	foreach ( $revisions as $revision ) {
		if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) {
			if ( $user_id && $user_id != $revision->post_author )
				continue;

			return $revision;
		}
	}

	return false;
}