admin管理员组

文章数量:1122832

I am updating my post status with following snippet:

dispatch("core/editor").editPost( {
    status: 'draft' 
} );

My problem is, that this action creates a new undo-entry. Is it possible to avoid this (eg. "undo: false" or something similar)?

Thank you in advance

I am updating my post status with following snippet:

dispatch("core/editor").editPost( {
    status: 'draft' 
} );

My problem is, that this action creates a new undo-entry. Is it possible to avoid this (eg. "undo: false" or something similar)?

Thank you in advance

Share Improve this question edited Jun 18, 2024 at 21:22 Tom J Nowell 60.7k7 gold badges77 silver badges147 bronze badges asked Jun 18, 2024 at 18:09 AlexAlex 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Yes, editPost is a wrapper around editEntityRecord which according to the core/data docs takes an options object that supports undoIgnore:

  • options Object: Options for the edit.
  • options.undoIgnore [boolean]: Whether to ignore the edit in undo history or not.

While you could use this, generally the need to use it implies a mistake or misunderstanding somewhere, or that the draft status is being set too late and should be set earlier.

A Warning: Editing vs Saving

Using editPost and editEntityRecord to set your post status to draft might not edit the database, it just changes the block editors internal state. It still needs to be saved/published to take effect.

This is why we have a saveEntityRecord function too, and it's how the editor knows what posts/templates to list in the checkbox list when you click publish ( e.g. it'll prompt if you want to update nav menus and synced templates etc )

For this reason, you might want to keep the undo/redo record.

本文标签: postseditPost without undo entry