_wp_put_post_revision

Advertisement

Private Access Private Access

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.

Summery Summery

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

Syntax Syntax

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

Parameters Parameters

$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

Return Return

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

Source Source

File: wp-includes/revision.php

	return false;
}

/**
 * Inserts post data into the posts table as a post revision.
 *
 * @since 2.6.0
 * @access private
 *
 * @param int|WP_Post|array|null $post     Post ID, post object OR post array.
 * @param bool                   $autosave Optional. Is the revision an autosave?
 * @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
 */
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;
	}

Advertisement

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.

Advertisement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.