Overview
For more details, see the block deprecation tutorial on the WordPress Developer Blog. When updating blocks, you can:- Create a new block with a different name (no deprecation needed)
- Provide deprecated versions to upgrade existing content
How deprecations work
Deprecations are not a chain of sequential updates. Instead:- If the current
savedoesn’t match, the first deprecation is tried - If that deprecation’s
saveproduces valid content, it’s used to parse attributes - If it has a
migratefunction, that runs with the parsed attributes - If the first deprecation fails, subsequent deprecations are tried
- Once a valid deprecation is found, attributes pass to the current
save - The block is now valid and the process stops
Deprecation structure
Deprecations are defined in thedeprecated array:
object
required
The attribute definition from the deprecated version
object
The supports definition from the deprecated version
function
required
The save function from the deprecated version
function
Function to transform old attributes to new formatParameters:
attributes(object) - Old attributesinnerBlocks(array) - Old inner blocks
object | [object, array]- New attributes or[attributes, innerBlocks]
function
Determines if a technically valid block should still be migratedParameters:
attributes(object) - Raw block attributesinnerBlocks(array) - Current inner blocksdata(object) - ContainsblockNodeandblock
boolean- Whether to run this deprecation
Basic example: Changing markup
Changing from<p> to <div>:
Renaming attributes
Use themigrate function to transform attributes:
Migrating to inner blocks
Move attribute content to inner blocks:Using isEligible
Migrate technically valid blocks that still need updates:Best practices
Version organization
Store each deprecation as a named constant:Maintain fixtures
Keep test fixtures for each version:Avoid function imports
Imported functions can change and break deprecations:Update multiple deprecations
If adding a migration (e.g., moving to InnerBlocks), update themigrate function in all affected deprecations:
Common scenarios
Changing attribute source
Adding new attributes
Changing supports
Testing deprecations
Always test that:- Old content migrates successfully
- Multiple deprecation versions work
- The
migratefunction handles edge cases