function wp_create_post_autosave( $post_id ) {}

Creates autosave data for the specified post from $_POST data.


  • $post_id

Source code

function wp_create_post_autosave( $post_id ) {

	$translated = _wp_translate_postdata( true );

	if ( is_wp_error( $translated ) )

		return $translated;

	// Only store one autosave.  If there is already an autosave, overwrite it.

	if ( $old_autosave = wp_get_post_autosave( $post_id ) ) {

		$new_autosave = _wp_post_revision_fields( $_POST, true );

		$new_autosave['ID'] = $old_autosave->ID;

		$new_autosave['post_author'] = get_current_user_id();

		return wp_update_post( $new_autosave );


	// _wp_put_post_revision() expects unescaped.

	$_POST = stripslashes_deep($_POST);

	// Otherwise create the new autosave as a special post revision

	return _wp_put_post_revision( $_POST, true );



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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: