Skip to content

State: Autosave should be treated as regular save for same-user draft post #7124

@aduth

Description

@aduth

Related: #7122 (comment)

When an autosave occurs for an auto-draft or draft post authored by the same user, the server treats it as a regular save:

if ( ( 'draft' === $post->post_status || 'auto-draft' === $post->post_status ) && $post->post_author == $user_id ) {
// Draft posts for the same author: autosaving updates the post and does not create a revision.
// Convert the post object to an array and add slashes, wp_update_post expects escaped array.
$autosave_id = wp_update_post( wp_slash( (array) $prepared_post ), true );

This should also be respected in the client, meaning:

  • There should be no prompts for unsaved changes after this occurs
  • The post's "current" values, i.e. state.currentPost, should reflect anything included in the autosave request

A couple possible implementations may include:

  • Testing as a condition of the save effect to consider isAutosave as false when the autosave is draft for current user
  • Handling as a case in the currentPost reducer
  • Dispatch resetPost after autosave completes successfully, when autosave is draft for current user

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrameworkIssues related to broader framework topics, especially as it relates to javascriptREST API InteractionRelated to REST API[Type] TaskIssues or PRs that have been broken down into an individual action to take

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions