@wordpress/core-data package manages these records and provides a unified undo/redo system across multiple simultaneous edits.
What Are Entities?
An entity represents a data source. Each item within the entity is called an entity record. Entities are defined in the core-data package and map to WordPress REST API endpoints.Entity Configuration
Entities are configured with the following properties:kind
Groups related entities together (e.g.,root, postType):
name
Unique identifier within the kind:baseURL
REST API endpoint path:Accessing Entities
Entities are accessed usingkind and name:
Dynamic Methods
Forroot kind entities, the package creates convenience methods:
Entity Record States
The core-data store tracks two versions of each entity record:Persisted Record
The last state fetched from the backend:Edited Record
The persisted record with local edits applied:Edited entity records contain raw values as strings, not objects with
rendered and raw properties. This is because JavaScript cannot render server-side dynamic content.Editing Entities
Basic Edit Flow
- Fetch the entity (automatically happens when you call a selector)
- Apply edits using
editEntityRecord - Save changes using
saveEditedEntityRecord
Edit Tracking
The store maintains a list of edits for each record:Complete Edit Example
Creating New Records
For new records without an ID, usesaveEntityRecord instead:
- Use
saveEntityRecord(notsaveEditedEntityRecord) - Pass the complete record object (not just an ID)
- No
editEntityRecordcall needed
Undo/Redo System
The WordPress editors support simultaneous editing of multiple entity records. The undo/redo system tracks all changes across entities.How It Works
When editing in the Site Editor:- Edit page title → Creates undo step
- Edit template content → Creates undo step
- Edit header template part → Creates undo step
- Press undo → Reverts the last change
Undo/Redo Stack Structure
Each modification stores:- Entity kind and name: Identifies the entity (e.g.,
postType,page) - Entity Record ID: The specific record modified
- Property: The modified property name (e.g.,
title) - From: Previous value (for undo)
- To: New value (for redo)
Using Undo/Redo
Cached Changes
Not all edits are immediately added to the undo/redo stack. Some modifications are “cached” to avoid creating excessive undo levels.When Cached Changes Are Used
- Typing in text fields (creates undo level after a delay)
- Rapid successive changes
- Changes marked with
isCached: trueoption
Transient Edits
Some edits don’t create undo levels at all:- UI state
- Temporary values
- Computed properties
Multiple Simultaneous Edits
The editor can edit multiple records at once:Entity Record Lifecycle
Best Practices
Always Use getEditedEntityRecord for Forms
Check for Edits Before Saving
Handle Save Errors
Clear Edits When Needed
Next Steps
- Working with Data - Learn useSelect and useDispatch patterns
- Building Forms - Create complete entity editing forms