返回介绍

_wp_put_post_revision()

发布于 2017-09-11 13:49:21 字数 2916 浏览 1016 评论 0 收藏 0

Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_wp_put_post_revision( int|WP_Post|array|null $post = null,  bool $autosave = false )

Inserts post data into the posts table as a post revision.


description


参数

$post

(int|WP_Post|array|null) (Optional) Post ID, post object OR post array.

Default value: null

$autosave

(bool) (Optional) Is the revision an autosave?

Default value: false


返回值

(int|WP_Error) WP_Error or 0 if error, new revision ID if success.


源代码

File: wp-includes/revision.php

function _wp_put_post_revision( $post = null, $autosave = false ) {
	if ( is_object($post) )
		$post = get_object_vars( $post );
	elseif ( !is_array($post) )
		$post = get_post($post, ARRAY_A);

	if ( ! $post || empty($post['ID']) )
		return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );

	if ( isset($post['post_type']) && 'revision' == $post['post_type'] )
		return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) );

	$post = _wp_post_revision_data( $post, $autosave );
	$post = wp_slash($post); //since data is from db

	$revision_id = wp_insert_post( $post );
	if ( is_wp_error($revision_id) )
		return $revision_id;

	if ( $revision_id ) {
		/**
		 * Fires once a revision has been saved.
		 *
		 * @since 2.6.0
		 *
		 * @param int $revision_id Post revision ID.
		 */
		do_action( '_wp_put_post_revision', $revision_id );
	}

	return $revision_id;
}

更新日志

Versiondescription
2.6.0Introduced.

相关函数

Uses

  • wp-includes/revision.php: _wp_post_revision_data()
  • wp-includes/l10n.php: __()
  • wp-includes/formatting.php: wp_slash()
  • wp-includes/plugin.php: do_action()
  • wp-includes/post.php: wp_insert_post()
  • wp-includes/post.php: get_post()
  • wp-includes/revision.php: _wp_put_post_revision
  • wp-includes/load.php: is_wp_error()
  • wp-includes/class-wp-error.php: WP_Error::__construct()
  • Show 4 more uses Hide more uses

Used By

  • wp-admin/includes/post.php: wp_create_post_autosave()
  • wp-includes/revision.php: wp_save_post_revision()

User Contributed Notes

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

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

发布评论

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