Skip to content
Subset

For developers

Developer reference

The WP-CLI commands, the actions fired around a migration, and the settings that can be locked from wp-config.php.

Everything the admin screen does is also a WP-CLI command, and every migration — started from either — fires the same actions.

WP-CLI

wp subset migration connection-info
wp subset migration pull Staging --media --dry-run
wp subset migration push https://staging.example.com <key> --exclude-tables=actionscheduler_*
wp subset migration export site.sql.gz --target-url=https://example.com
wp subset migration import site.sql.gz --confirm-production=example.com
wp subset migration resume
wp subset migration backups
wp subset migration history

push, pull, export and import accept --format=json: progress goes to STDERR and STDOUT gets one JSON summary at the end. Replacing a production site’s database also needs --confirm-production=<domain>; --yes alone is not enough.

When a migration finishes

<?php
add_action( 'wpmig_migration_finished', function ( string $event, array $summary ) {
	// $event is done, failed or cancelled. $summary has the intent
	// (push, pull, export or import), the remote, and start and end times.
}, 10, 2 );

It fires exactly once per migration, whether it was started from the admin screen or WP-CLI.

Keeping data across the swap

<?php
// Options that stay with the destination when its database is replaced.
add_filter( 'wpmig_preserved_options', function ( array $options ): array {
	$options[] = 'my_plugin_license_key';
	return $options;
} );

// Fires on the destination just before the swap, while its own content is still live.
add_action( 'wpmig_before_swap', function ( array $tables, ?string $swap_id ) {
	// Record what you need into an option named by wpmig_preserved_options.
}, 10, 2 );

Locking settings in wp-config.php

<?php
define( 'WPMIG_ALLOW_PUSH', false );
define( 'WPMIG_ALLOW_PULL', true );
define( 'WPMIG_IS_PRODUCTION', true );
define( 'WPMIG_VERIFY_SSL', true );

A locked setting shows as disabled on the Connection settings screen, and nothing a migration or restore writes to the database can change its effect.