_wp_put_post_revision

Definition:
function _wp_put_post_revision( $post = null, $autosave = false ) {}

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

Parameters

  • int|object|array $post: Post ID, post object OR post array.
  • bool $autosave: Optional. Is the revision an autosave?

Return values

returns:Null or 0 if error, new revision ID if success.

Defined actions

  • _wp_put_post_revision
    do_action( '_wp_put_post_revision', $revision_id );

Source code

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;



	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_fields( $post, $autosave );

	$post = add_magic_quotes($post); //since data is from db



	$revision_id = wp_insert_post( $post );

	if ( is_wp_error($revision_id) )

		return $revision_id;



	if ( $revision_id )

		do_action( '_wp_put_post_revision', $revision_id );

	return $revision_id;

}

4411

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: