What Are Entities?
Entities represent WordPress data objects. Each editor can fetch, edit, and save multiple entity records simultaneously.Example: Editing a Page in Site Editor
When opening a page in the Site Editor, you can edit:- Properties of the page itself (title, content)
- Properties of the page’s template (content, design)
- Properties of template parts used in the template (header, footer)
@wordpress/core-data package.
Entity Identification
Each entity is identified by three pieces of information:- Kind - The type of entity (e.g.,
postType,taxonomy) - Name - The specific entity name (e.g.,
post,page,wp_template) - Record ID - The unique identifier for the record (e.g.,
1,42)
Common Entities
Post Types:{ kind: 'postType', name: 'post' }- Blog posts{ kind: 'postType', name: 'page' }- Pages{ kind: 'postType', name: 'wp_block' }- Reusable blocks{ kind: 'postType', name: 'wp_template' }- Templates{ kind: 'postType', name: 'wp_template_part' }- Template parts
{ kind: 'taxonomy', name: 'category' }- Categories{ kind: 'root', name: 'user' }- Users{ kind: 'root', name: 'site' }- Site settings
Editing Entities
Loading an Entity
Before editing, you must fetch and load the entity into thecore store:
Entity Record State
For each fetched entity record,core-data tracks:
Persisted Record:
The last state of the record as fetched from the backend.
List of Edits:
Unsaved local modifications for one or several properties.
Making Edits
UseeditEntityRecord to modify entity properties:
Saving Changes
UsesaveEditedEntityRecord to persist changes:
Architectural Decision
Data layer: Uses@wordpress/data(Redux-like stores). Edit entities throughcore-dataactions (editEntityRecord/saveEditedEntityRecord), not direct state manipulation.
The Undo/Redo System
Since WordPress editors allow editing multiple entity records simultaneously,core-data maintains a common undo/redo stack.
Undo/Redo Stack Structure
Each step in the stack contains a list of edits that should be undone or redone together.Edit Information
Each modification stores:- Entity kind and name - The identifier pair (e.g.,
postType,post) - Entity Record ID - The ID of the modified record
- Property - The name of the modified property
- From - Previous value (for undo)
- To - New value (for redo)
Example Undo/Redo Stack
User actions:- Edits post title
- Modifies post slug
- Changes reusable block title
Undo/Redo Pointer
The store maintains a pointer to the current step:- By default, points to the last item
- Updated when user performs undo or redo
- Enables bidirectional history traversal
Cached Changes
The undo/redo system supports cached modifications—changes not immediately stored in the undo/redo stack.Why Cached Changes?
When a user types in a text field:- Value updates in the store immediately
- But we don’t create an undo step for each character
- Instead, changes are cached until:
- User moves to the next word
- A few milliseconds pass
__unstableCreateUndoLevelis called- Next non-cached modification occurs
Using Cached Changes
By default,editEntityRecord calls are non-cached. Use the isCached option:
Cached Changes Storage
Cached modifications are kept outside the main undo/redo stack in a “cache” area. They’re only added to the stack when:- Explicitly calling
__unstableCreateUndoLevel - Next modification is not cached
Multi-Entity Editing
The system’s true power is handling multiple entities simultaneously.Example: Site Editor Session
Checking Entity State
Has Unsaved Changes?
Get Current Edits
Get All Entities to Save
Best Practices
Always Use Actions
Don’t manipulate state directly—useeditEntityRecord and saveEditedEntityRecord.
Load Before Editing
Ensure entities are loaded before editing:Handle Multiple Entities
When working with templates, remember you’re editing multiple entities simultaneously.Use Cached Changes Wisely
Only useisCached: true for rapid, frequent updates like typing.
Integration with Block Editor
The block editor content is stored as an entity property:- Blocks are the
contentproperty of post entities - Changes to blocks create entity edits
- Saving the post saves the block content