_wp_post_revision_data

函数
_wp_post_revision_data ( $post = array(), $autosave = false )
Access
Private
参数
  • (array|WP_Post) $post Optional. A post array or a WP_Post object to be processed for insertion as a post revision. Default empty array.
    Required:
    Default: array()
  • (bool) $autosave Optional. Is the revision an autosave? Default false.
    Required:
    Default: false
返回值
  • (array) Post array ready to be inserted as a post revision.
定义位置
相关方法
_wp_post_revision_fieldswp_post_revision_title_wp_put_post_revisionwp_is_post_revisionwp_get_post_revision
引入
4.5.0
弃用
-

_wp_post_revision_data: 这是一个私有函数,用于检索一个文章的修订数据。它返回给定文章ID的元数据数组,包括修订ID、作者ID、时间戳和标题。

返回一个文章数组,准备作为一个文章修订版插入到文章表中。

function _wp_post_revision_data( $post = array(), $autosave = false ) {
	if ( ! is_array( $post ) ) {
		$post = get_post( $post, ARRAY_A );
	}

	$fields = _wp_post_revision_fields( $post );

	$revision_data = array();

	foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) {
		$revision_data[ $field ] = $post[ $field ];
	}

	$revision_data['post_parent']   = $post['ID'];
	$revision_data['post_status']   = 'inherit';
	$revision_data['post_type']     = 'revision';
	$revision_data['post_name']     = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version.
	$revision_data['post_date']     = isset( $post['post_modified'] ) ? $post['post_modified'] : '';
	$revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : '';

	return $revision_data;
}

常见问题

FAQs
查看更多 >