Skip to main content

Progressive Migration

Start with legacy storage:

$settings = pu_options('new_theme_settings', [
'migrate_from' => 'legacy_theme_settings',
'migration' => 'preserve',
]);

Read normally:

$heading = $settings->get('heading', 'Default heading');

Move only one field lazily when its data shape changes:

$enabled = $settings->get('enabled', false, [
'migrate_from' => 'show_feature',
'migration' => 'lazy',
'from_legacy' => static fn ($value): bool => in_array($value, [1, '1', true, 'true'], true),
]);

During a rollback-compatible release, synchronize writes to both stores:

$settings->set('enabled', true, [
'migrate_from' => 'show_feature',
'migration' => 'copy',
'to_legacy' => static fn (bool $value): string => $value ? '1' : '0',
]);