### all() Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/ImportCommand.md Complete site import from a zip package. Creates new multisite site if needed and handles all setup. ```APIDOC ## all() ### Description Complete site import from a zip package. Creates new multisite site if needed and handles all setup. ### Method ```php public function all( array $args = array(), array $assoc_args = array() ): void ``` ### Parameters #### Positional Arguments - `args` (array) - Optional - Positional arguments: `[0]` = input zip filename #### Named Arguments - `blog_id` (int) - Optional - Existing blog ID to import into (multisite) - `new_url` (string) - Optional - New URL for the imported site (overrides zip metadata) - `mysql-single-transaction` (flag) - Optional - Wrap SQL in transaction (single commit) - `verbose` (flag) - Optional - Show detailed progress messages - `uid_fields` (string) - Optional - Comma-separated custom user ID meta field names ### Processing Steps 1. Extracts zip file to temporary directory 2. Validates required files (JSON metadata, CSV users, SQL tables) 3. Creates new multisite site (if no `blog_id` provided and in multisite) 4. Imports database tables with prefix rewriting 5. Moves and activates plugins (respecting original activation state) 6. Moves uploads folder to site-specific location 7. Moves themes to theme directory 8. Imports users and creates ID map 9. Updates post author IDs using ID map 10. Flushes rewrite rules 11. Cleans up temporary files ### Behavior by Context - Single-site WordPress: overwrites current site - Multisite without `blog_id`: creates new site automatically - Multisite with `blog_id`: imports into existing site ### Custom User ID Fields Example ```bash wp mu-migration import all site.zip --uid_fields=_content_owner,_reviewer_id ``` ### Example ```bash # Import as new site into multisite wp mu-migration import all site.zip --new_url=multisite.dev/newsite # Import into existing multisite blog wp mu-migration import all site.zip --blog_id=3 --new_url=multisite.dev/site3 # Import with custom fields and transactions wp mu-migration import all site.zip \ --new_url=staging.example.com \ --uid_fields=_content_owner,_assigned_to \ --mysql-single-transaction \ --verbose ``` ``` -------------------------------- ### Site Metadata Object Example Source: https://github.com/10up/mu-migration/blob/master/_autodocs/types.md An example of the Site Metadata JSON object, illustrating typical values for site configuration and plugin data. ```json { "url": "https://oldsite.com", "name": "My Blog", "admin_email": "admin@oldsite.com", "site_language": "en-US", "db_prefix": "wp_", "plugins": { "akismet/akismet.php": {} }, "blog_plugins": [ "akismet/akismet.php", "jetpack/jetpack.php" ], "network_plugins": {}, "blog_id": 1 } ``` -------------------------------- ### Install Dependencies for MU-Migration Plugin Source: https://github.com/10up/mu-migration/blob/master/README.md Installs project dependencies using Composer after cloning the MU-Migration plugin repository into your plugins folder. ```bash composer install ``` -------------------------------- ### Multisite Subsite Uploads Path Example Source: https://github.com/10up/mu-migration/blob/master/_autodocs/types.md Demonstrates the directory structure for uploads in multisite subsites, including the blog ID in the path. ```bash wp-content/uploads/sites/2/ wp-content/uploads/sites/3/ ``` -------------------------------- ### Import as New Multisite Site Source: https://github.com/10up/mu-migration/blob/master/_autodocs/configuration.md Use this command to import a site as a new multisite installation. Specify the new URL for the site. ```bash wp mu-migration import all export.zip --new_url=multisite.dev/site1 ``` -------------------------------- ### Complete Migration Workflow Example Source: https://github.com/10up/mu-migration/blob/master/_autodocs/endpoints.md Execute these commands sequentially to perform a full site migration. Ensure the migration zip file is transferred to the target server before proceeding with the import. ```bash # Step 1: Export source site wp mu-migration export all migration.zip --plugins --themes --uploads ``` ```bash # Step 2: Transfer migration.zip to target server ``` ```bash # Step 3: Import on target multisite wp mu-migration import all migration.zip --new_url=multisite.dev/newsite ``` ```bash # Step 4: Update post authors using generated map wp mu-migration posts update_author mu-migration-temp*/users_map.json --blog_id=2 ``` ```bash # Step 5: Reset user passwords and send reset emails wp mu-migration users update_passwords --reset --blog_id=2 --send_email ``` -------------------------------- ### Install MU-Migration via WP-CLI Source: https://github.com/10up/mu-migration/blob/master/README.md Installs the MU-Migration plugin using the WP-CLI package manager. Ensure you have WP-CLI version 0.23 or higher. ```bash wp package install 10up/mu-migration ``` -------------------------------- ### Multisite Subsite Table Name Example Source: https://github.com/10up/mu-migration/blob/master/_autodocs/types.md Shows how table names are constructed for subsites by combining the blog ID prefix with the base table name. ```sql wp_2_posts wp_2_postmeta wp_3_posts wp_3_postmeta ``` -------------------------------- ### maybe_switch_to_blog() Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/Helpers.md Conditionally switches to a specified blog context if the site is running in multisite mode. Does nothing if not on a multisite installation. ```APIDOC ## maybe_switch_to_blog(int $blog_id) ### Description Switches to a blog context if running on multisite, otherwise does nothing. ### Method `maybe_switch_to_blog` ### Parameters #### Path Parameters - **blog_id** (int) - Required - Blog ID to switch to ### Response #### Success Response (200) - **void** - This function does not return a value. ### Example ```php Helpers\maybe_switch_to_blog(2); ``` ``` -------------------------------- ### User CSV Export Example Row Source: https://github.com/10up/mu-migration/blob/master/_autodocs/types.md An example data row from the user CSV export, demonstrating the format for standard user fields. Serialized metadata is stored as strings. ```csv 1,admin,encrypted_hash,admin,admin@example.com,https://example.com,2024-01-01 12:00:00,administrator,0,Administrator,true,sunrise,true,John,Doe,johndoe,aim_name,yim_name,jabber_name,My biography ``` -------------------------------- ### MU Migration Import Data Flow Source: https://github.com/10up/mu-migration/blob/master/_autodocs/INDEX.md Details the steps involved in importing a migration zip file into a target installation. ```bash migration.zip ↓ ImportCommand.all() ├── extract ZIP → temp ├── parse metadata JSON ├── create new multisite site (if needed) ├── import tables SQL (rewrite prefix/URL) ├── move plugins → activate ├── move themes → enable ├── move uploads → site folder ├── import users CSV → create user map ├── update post authors → use user map ├── flush rewrite rules └── cleanup ↓ Target Installation ``` -------------------------------- ### Post-Migration User Setup Source: https://github.com/10up/mu-migration/blob/master/_autodocs/START_HERE.md Update author information for posts using a user mapping file and reset user passwords, optionally sending email notifications, after a migration is complete. These commands are typically run on the target multisite environment. ```bash # After import is complete wp mu-migration posts update_author user_map.json --blog_id=2 wp mu-migration users update_passwords --reset --blog_id=2 --send_email ``` -------------------------------- ### Import Site Data with WP-CLI Source: https://github.com/10up/mu-migration/blob/master/_autodocs/INDEX.md Use these commands to import data into your WordPress installation. The 'all' command imports from a ZIP package. ```bash wp mu-migration import users wp mu-migration import tables wp mu-migration import all ``` -------------------------------- ### User ID Mapping JSON Example Source: https://github.com/10up/mu-migration/blob/master/_autodocs/types.md An example of a user ID mapping JSON object, showing how specific old IDs are linked to new IDs. Note that multiple old IDs can map to the same new ID. ```json { "1": "5", "2": "6", "3": "6", "5": "8" } ``` -------------------------------- ### Set All Users to Specific Password (CLI) Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/UsersCommand.md Example of setting a new password for all users on a specific blog ID using the WP-CLI command. ```bash # Set all users to specific password wp mu-migration users update_passwords 'newpassword123' --blog_id=2 ``` -------------------------------- ### Import Site from Zip Package Source: https://github.com/10up/mu-migration/blob/master/README.md Imports a site from a zip package. If importing into a multisite, it creates a new site; if into a single install, it overrides the existing site. ```bash $ wp mu-migration import all site.zip ``` -------------------------------- ### mu-migration info Source: https://github.com/10up/mu-migration/blob/master/_autodocs/endpoints.md Displays general information about MU-Migration and the WordPress installation, including its version, creator, and GitHub repository. ```APIDOC ## mu-migration info ### Description Displays general information about MU-Migration and WordPress installation. ### Command `wp mu-migration info` ### Handler `TenUp\MU_Migration\Commands\MUMigration::__invoke()` ### Parameters None ### Output - MU-Migration version - Creator information - GitHub repository link ### Example ```bash $ wp mu-migration info MU-Migration version: v0.3.2 Created by Nícholas André at 10up Github: https://github.com/10up/MU-Migration ``` ``` -------------------------------- ### Multisite Subsite Table Prefix Example Source: https://github.com/10up/mu-migration/blob/master/_autodocs/types.md Illustrates the naming convention for database tables in multisite subsites, where the blog ID is incorporated into the prefix. ```sql wp_2_ wp_3_ wp_10_ ``` -------------------------------- ### Display MU-Migration Info Source: https://github.com/10up/mu-migration/blob/master/_autodocs/endpoints.md Use this command to view general information about the MU-Migration plugin and your WordPress installation. It displays the plugin version, creator, and repository link. ```bash $ wp mu-migration info MU-Migration version: v0.3.2 Created by Nícholas André at 10up Github: https://github.com/10up/MU-Migration ``` -------------------------------- ### Reset All Users and Send Reset Emails (CLI) Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/UsersCommand.md Example of resetting all users' passwords to random ones and sending them a password reset email on a specific blog ID. ```bash # Reset all users and send reset emails wp mu-migration users update_passwords --reset --blog_id=2 --send_email ``` -------------------------------- ### MU Migration Export Data Flow Source: https://github.com/10up/mu-migration/blob/master/_autodocs/INDEX.md Illustrates the process of exporting data from a WordPress installation to create a migration zip file. ```bash WordPress Installation ↓ ExportCommand.all() ├── collect site metadata → JSON ├── export users → CSV ├── export tables → SQL ├── copy plugins → folder ├── copy themes → folder ├── copy uploads → folder └── create ZIP ↓ migration.zip ``` -------------------------------- ### Import Site Zip Package Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/ImportCommand.md Imports a complete site from a zip package. Can create a new multisite, import into an existing multisite blog, or overwrite a single-site installation. Use `--uid_fields` for custom user ID meta fields. ```bash wp mu-migration import all site.zip --new_url=multisite.dev/newsite ``` ```bash wp mu-migration import all site.zip --blog_id=3 --new_url=multisite.dev/site3 ``` ```bash wp mu-migration import all site.zip \ --new_url=staging.example.com \ --uid_fields=_content_owner,_assigned_to \ --mysql-single-transaction \ --verbose ``` -------------------------------- ### Export Specific Blog Tables Source: https://github.com/10up/mu-migration/blob/master/_autodocs/configuration.md Exports tables from a specific blog in a multisite setup. Use the --blog_id parameter to specify the target blog. ```bash wp mu-migration export tables export.sql --blog_id=2 ``` -------------------------------- ### Export for Staging/Local Development Source: https://github.com/10up/mu-migration/blob/master/_autodocs/START_HERE.md Export a production site's content, plugins, themes, and uploads for use in a staging or local development environment. Import it by specifying the new URL for the staging/local setup. ```bash # On production wp mu-migration export all prod-export.zip --plugins --themes --uploads # Transfer to staging/local # On staging/local wp mu-migration import all prod-export.zip --new_url=staging.local ``` -------------------------------- ### Multisite to Multisite Table Import Source: https://github.com/10up/mu-migration/blob/master/_autodocs/configuration.md This command facilitates importing tables between multisite installations, including rewriting prefixes and URLs, and handling original blog IDs for correct path rewriting. It's essential for migrating specific sites within a multisite network. ```bash wp mu-migration import tables export.sql \ --blog_id=3 \ --old_prefix=wp_2_ \ --new_prefix=wp_3_ \ --original_blog_id=2 \ --old_url=old-multisite.dev/blog2 \ --new_url=new-multisite.dev/blog3 ``` -------------------------------- ### Exclude Certain Users (CLI) Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/UsersCommand.md Example of resetting passwords and sending emails to all users on a specific blog ID, except for a comma-separated list of user IDs. ```bash # Exclude certain users wp mu-migration users update_passwords --reset \ --blog_id=2 \ --exclude=1,2 \ --send_email ``` -------------------------------- ### Wrap SQL File with Transaction Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/Helpers.md Wraps a given SQL file with `START TRANSACTION` and `COMMIT` statements to ensure atomic imports. This prevents partial imports if an error occurs during execution. ```php function addTransaction(string $orig_filename): void ``` ```php // Used when --mysql-single-transaction flag provided Helpers\addTransaction('site.sql'); // site.sql now starts with START TRANSACTION and ends with COMMIT ``` -------------------------------- ### Export Site Tables to SQL Source: https://github.com/10up/mu-migration/blob/master/_autodocs/endpoints.md Exports specified database tables to an SQL file. You can export all default tables, tables from a specific blog ID in a multisite setup, or a custom list of tables. ```bash # Export all default tables for main site wp mu-migration export tables output.sql ``` ```bash # Export blog 2 tables wp mu-migration export tables output.sql --blog_id=2 ``` ```bash # Export specific tables wp mu-migration export tables output.sql --tables=wp_posts,wp_postmeta,wp_comments ``` ```bash # Export with custom tables wp mu-migration export tables output.sql --non-default-tables=wp_custom1,wp_custom2 ``` -------------------------------- ### Get Multisite Database Prefix Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/Helpers.md Retrieves the correct database table prefix for a given blog ID in a WordPress multisite installation. ```php $prefix = Helpers\get_db_prefix(2); // Returns: 'wp_2_' ``` -------------------------------- ### Export Main Site with Components Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/ExportCommand.md Use this command to export the main site, including the plugins, themes, and uploads directories. The output will be a zip file named 'site.zip'. ```bash wp mu-migration export all site.zip --plugins --themes --uploads ``` -------------------------------- ### Export Complete Site to ZIP Source: https://github.com/10up/mu-migration/blob/master/_autodocs/endpoints.md Creates a ZIP package of the entire site, including database tables, user data, site metadata, and optionally plugins, themes, and uploads folders. Use the --verbose flag for detailed progress. ```bash # Export main site with all optional content wp mu-migration export all site.zip --plugins --themes --uploads ``` ```bash # Export subsite from multisite wp mu-migration export all subsite.zip --blog_id=2 ``` ```bash # Export with custom tables wp mu-migration export all site.zip \ --non-default-tables=wp_custom1,wp_custom2 \ --plugins --uploads ``` ```bash # Export with verbose output wp mu-migration export all site.zip --plugins --themes --uploads --verbose ``` -------------------------------- ### Import Complete Site from ZIP Source: https://github.com/10up/mu-migration/blob/master/_autodocs/endpoints.md Imports a complete site from a ZIP package. Can create a new multisite site or import into an existing blog. Supports URL overrides, verbose output, and atomic transactions. ```bash wp mu-migration import all site.zip --new_url=multisite.dev/site1 ``` ```bash wp mu-migration import all site.zip --blog_id=3 --new_url=multisite.dev/site3 ``` ```bash wp mu-migration import all site.zip \ --new_url=staging.dev/site \ --uid_fields=_content_owner,_assigned_to \ --verbose ``` ```bash wp mu-migration import all site.zip \ --blog_id=2 \ --mysql-single-transaction ``` -------------------------------- ### Full Verbose Import Source: https://github.com/10up/mu-migration/blob/master/_autodocs/configuration.md Perform a comprehensive site import with detailed progress messages, a new URL, and custom user ID fields. ```bash wp mu-migration import all export.zip \ --new_url=multisite.dev/site \ --uid_fields=_custom_owner,_assigned_user \ --verbose ``` -------------------------------- ### is_woocommerce_active() Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/Helpers.md Checks if the WooCommerce plugin is currently active in the WordPress installation. ```APIDOC ## is_woocommerce_active() ### Description Checks if the WooCommerce plugin is active. ### Method `function` ### Parameters None ### Returns - bool: `true` if WooCommerce is active, `false` otherwise. ### Example ```php if (Helpers\is_woocommerce_active()) { // Handle WooCommerce-specific fields } ``` ``` -------------------------------- ### Import Site to Target Source: https://github.com/10up/mu-migration/blob/master/_autodocs/START_HERE.md Import the migration ZIP file to the target server, automatically creating a new multisite if needed and rewriting database prefixes. ```bash # On target server wp mu-migration import all migration.zip --new_url=newsite.example.com ``` -------------------------------- ### get_db_prefix() Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/Helpers.md Retrieves the database table prefix for a specific blog ID within a WordPress multisite installation. ```APIDOC ## get_db_prefix(int $blog_id) ### Description Gets the database table prefix for a given blog ID in multisite. ### Method `function` ### Parameters #### Path Parameters - **blog_id** (int) - Required - Blog ID to get prefix for ### Returns - string: Database table prefix for the blog. ### Example ```php $prefix = Helpers\get_db_prefix(2); // Returns: 'wp_2_' ``` ``` -------------------------------- ### Check if WooCommerce is Active Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/Helpers.md Use this function to conditionally execute code only when the WooCommerce plugin is installed and activated. ```php if (Helpers\is_woocommerce_active()) { // Handle WooCommerce-specific fields } ``` -------------------------------- ### Update Only Administrators (CLI) Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/UsersCommand.md Example of updating passwords only for users with the 'administrator' role on a specific blog ID. ```bash # Update only administrators wp mu-migration users update_passwords 'newpass' --blog_id=2 --role=administrator ``` -------------------------------- ### Import Site Data with MU-MIGRATION Source: https://github.com/10up/mu-migration/blob/master/_autodocs/00_READ_ME_FIRST.txt Use the 'import all' command to restore a site from a migration zip file. Specify the new URL for the target site. ```bash wp mu-migration import all migration.zip --new_url=newsite.example.com ``` -------------------------------- ### Export Entire Site with Files Source: https://github.com/10up/mu-migration/blob/master/README.md Exports all site data, including plugins, themes, and uploads, into a zip file. This is useful for migrating a complete site. ```bash $ wp mu-migration export all site.zip --plugins --themes --uploads ``` -------------------------------- ### maybe_restore_current_blog() Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/Helpers.md Conditionally restores the current blog context if the site is running in multisite mode. Does nothing if not on a multisite installation. ```APIDOC ## maybe_restore_current_blog() ### Description Restores blog context if running on multisite, otherwise does nothing. ### Method `maybe_restore_current_blog` ### Parameters None ### Response #### Success Response (200) - **void** - This function does not return a value. ### Example ```php Helpers\maybe_restore_current_blog(); ``` ``` -------------------------------- ### Import to Existing Blog Source: https://github.com/10up/mu-migration/blob/master/_autodocs/configuration.md Import a site into an existing blog on a multisite network by specifying the blog ID. ```bash wp mu-migration import all export.zip --blog_id=3 ``` -------------------------------- ### Import with Atomic Transaction Source: https://github.com/10up/mu-migration/blob/master/_autodocs/configuration.md Import a site into an existing blog, wrapping the SQL import in a single atomic transaction for data integrity. ```bash wp mu-migration import all export.zip \ --blog_id=2 \ --mysql-single-transaction ``` -------------------------------- ### Import with URL and Custom Fields Source: https://github.com/10up/mu-migration/blob/master/_autodocs/configuration.md Import a site, overriding the site URL and specifying custom user ID meta fields to update. ```bash wp mu-migration import all export.zip \ --new_url=staging.example.com/imported \ --uid_fields=_content_owner,_assigned_to ``` -------------------------------- ### Import Site with New URL and Blog ID Source: https://github.com/10up/mu-migration/blob/master/README.md Imports a site from a zip package, sets a new URL, and specifies a blog ID to override an existing subsite. This provides granular control over the import process. ```bash $ wp mu-migration import all site.zip --new_url=multisite.dev/site --blog_id=3 ``` -------------------------------- ### Typical Usage Flow for PostsCommand Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/PostsCommand.md This sequence outlines the typical workflow for migrating posts, including exporting, importing, and then updating post authors using the generated user map. ```bash # 1. Export site wp mu-migration export all site.zip ``` ```bash # 2. Extract zip on target server # 3. Import site (creates user_map.json) wp mu-migration import all site.zip --blog_id=2 ``` ```bash # 4. Update post authors using generated map wp mu-migration posts update_author user_map.json --blog_id=2 ``` -------------------------------- ### Import All Site Data from ZIP with WP-CLI Source: https://github.com/10up/mu-migration/blob/master/_autodocs/START_HERE.md Import all site data from a ZIP archive. Specify the ZIP file, blog ID, and optionally the new URL. Use --mysql-single-transaction for atomic imports. ```bash wp mu-migration import all [--blog_id=X] [--new_url=X] [--mysql-single-transaction] [--uid_fields=X] [--verbose] ``` -------------------------------- ### Typical Migration Password Reset Flow (CLI) Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/UsersCommand.md Demonstrates the common workflow for resetting all user passwords after an import and sending reset emails. ```bash # After import is complete, reset all user passwords wp mu-migration users update_passwords --reset --blog_id=2 --send_email # Users receive email with password reset link # They use link to set their own password ``` -------------------------------- ### Update Specific User IDs Only (CLI) Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/UsersCommand.md Example of resetting passwords and sending emails only to a comma-separated list of user IDs on a specific blog ID. ```bash # Update specific user IDs only wp mu-migration users update_passwords --reset \ --blog_id=2 \ --include=1,5,7 \ --send_email ``` -------------------------------- ### Import users to main site Source: https://github.com/10up/mu-migration/blob/master/_autodocs/configuration.md Use this command to import users from a CSV file to the main site. Ensure the CSV file and map file path are correct. ```bash wp mu-migration import users users.csv --map_file=user_map.json ``` -------------------------------- ### Import Tables from SQL Source: https://github.com/10up/mu-migration/blob/master/_autodocs/endpoints.md Imports database tables from an SQL file. Requires blog ID, old prefix, and new prefix. Supports optional URL replacement for search-replace operations. ```bash wp mu-migration import tables site.sql \ --blog_id=2 \ --old_prefix=wp_ \ --new_prefix=wp_2_ ``` ```bash wp mu-migration import tables site.sql \ --blog_id=2 \ --old_prefix=wp_ \ --new_prefix=wp_2_ \ --old_url=old.example.com \ --new_url=new.example.com ``` -------------------------------- ### MU Migration Command Structure Source: https://github.com/10up/mu-migration/blob/master/_autodocs/INDEX.md Overview of the main commands and their sub-commands within the MU Migration tool. ```bash MUMigration (info) │ ├── ExportCommand (extends MUMigrationBase) │ ├── tables() — export tables │ ├── users() — export users │ └── all() — export complete site │ ├── ImportCommand (extends MUMigrationBase) │ ├── users() — import users │ ├── tables() — import tables │ └── all() — import complete site │ ├── PostsCommand (extends MUMigrationBase) │ └── update_author() — update post authors │ └── UsersCommand (extends MUMigrationBase) └── update_passwords() — manage passwords ``` -------------------------------- ### Get User Export CSV Headers Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/ExportCommand.md Retrieves the standard CSV headers for user export files. The filter `mu_migration/export/user/headers` can be used to customize these headers. ```php public static function getCSVHeaders(): array ``` ```php $headers = ExportCommand::getCSVHeaders(); // Returns: ['ID', 'user_login', 'user_pass', ...] ``` -------------------------------- ### Export Site Data with MU-MIGRATION Source: https://github.com/10up/mu-migration/blob/master/_autodocs/00_READ_ME_FIRST.txt Use the 'export all' command to create a zip archive of site data including plugins, themes, and uploads. Specify the output file name. ```bash wp mu-migration export all migration.zip --plugins --themes --uploads ``` -------------------------------- ### SQL Dump Transaction Wrapper Source: https://github.com/10up/mu-migration/blob/master/_autodocs/types.md When the `--mysql-single-transaction` option is used during import, the SQL dump file is wrapped with START TRANSACTION and COMMIT statements. ```sql START TRANSACTION; [original SQL] COMMIT; ``` -------------------------------- ### WP-CLI Command Reference - Import Source: https://github.com/10up/mu-migration/blob/master/_autodocs/00_READ_ME_FIRST.txt Reference for 'wp mu-migration import' commands, including options for users, tables, and all site data. Requires map files and specifies target blog ID and URL. ```bash wp mu-migration import users --map_file [--blog_id] ``` ```bash wp mu-migration import tables --blog_id --old_prefix --new_prefix [--old_url] [--new_url] ``` ```bash wp mu-migration import all [--blog_id] [--new_url] [--mysql-single-transaction] [--uid_fields] ``` -------------------------------- ### MU Migration Main Commands Source: https://github.com/10up/mu-migration/blob/master/_autodocs/INDEX.md Provides an overview of the main WP-CLI commands for site migration operations. ```APIDOC ## WP-CLI Commands ### Main Plugin File **File:** `mu-migration.php` Loads all command classes and registers WP-CLI commands: - `mu-migration info` — Display version and info - `mu-migration export` — Export site data - `mu-migration import` — Import site data - `mu-migration posts` — Update post authors - `mu-migration users` — Manage passwords ### Export Commands - **`wp mu-migration export tables`** — Export database to SQL - **`wp mu-migration export users`** — Export users to CSV - **`wp mu-migration export all`** — Export everything to ZIP ### Import Commands - **`wp mu-migration import users`** — Import users from CSV - **`wp mu-migration import tables`** — Import database from SQL - **`wp mu-migration import all`** — Import everything from ZIP ### Post-Migration Commands - **`wp mu-migration posts update_author`** — Update post author IDs - **`wp mu-migration users update_passwords`** — Reset user passwords ``` -------------------------------- ### Basic Table Import with Prefix Rewriting Source: https://github.com/10up/mu-migration/blob/master/_autodocs/configuration.md Use this command for a basic import where you need to rewrite table prefixes. Ensure the input SQL file is available and the target blog ID, old prefix, and new prefix are correctly specified. ```bash wp mu-migration import tables export.sql \ --blog_id=2 \ --old_prefix=wp_ \ --new_prefix=wp_2_ ``` -------------------------------- ### Reset All Users to Random Password (CLI) Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/UsersCommand.md Example of resetting all users' passwords to a randomly generated one on a specific blog ID using the WP-CLI command. ```bash # Reset all users to random password wp mu-migration users update_passwords --reset --blog_id=2 ``` -------------------------------- ### addTransaction() Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/Helpers.md Wraps a given SQL file with `START TRANSACTION` and `COMMIT` statements to ensure atomic imports, preventing partial data imports in case of errors. ```APIDOC ## addTransaction(string $orig_filename) ### Description Wraps SQL file with `START TRANSACTION` and `COMMIT` statements for atomic imports. ### Method `addTransaction` ### Parameters #### Path Parameters - **orig_filename** (string) - Required - Path to SQL file to wrap ### Response #### Success Response (200) - **void** - This function does not return a value. ### Example ```php // Used when --mysql-single-transaction flag provided Helpers\addTransaction('site.sql'); ``` ``` -------------------------------- ### Import Database Tables from SQL with WP-CLI Source: https://github.com/10up/mu-migration/blob/master/_autodocs/START_HERE.md Import database tables from an SQL file. You must provide the input file, blog ID, old prefix, and new prefix. Optionally, specify old and new URLs. ```bash wp mu-migration import tables --blog_id=X --old_prefix=X --new_prefix=X [--old_url=X] [--new_url=X] ``` -------------------------------- ### Export with Verbose Output Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/ExportCommand.md This command exports the site with detailed progress messages enabled. It includes the plugins and themes directories and outputs to 'site.zip'. ```bash wp mu-migration export all site.zip --plugins --themes --verbose ``` -------------------------------- ### Export with Custom Tables Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/ExportCommand.md This command exports the site along with specified non-default database tables. Provide a comma-separated list of table names to include in the export. ```bash wp mu-migration export all site.zip --non-default-tables=wp_custom1,wp_custom2 ``` -------------------------------- ### all() Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/ExportCommand.md Performs a complete site export to a single zip file. This includes users, tables, metadata, and optionally plugins, themes, and uploads. ```APIDOC ## all() ### Description Complete site export to a single zip file containing users, tables, metadata, and optional plugins/themes/uploads. ### Method ```php public function all( array $args = array(), array $assoc_args = array() ): void ``` ### Parameters #### args - **args** (array) - Optional - Positional arguments: `[0]` = output zip filename (auto-generated if omitted) #### assoc_args - **assoc_args** (array) - Optional - Named arguments: - **blog_id** (int) - Optional - Blog ID to export from (multisite only) - **tables** (string) - Optional - Comma-separated list of specific tables - **non-default-tables** (string) - Optional - Comma-separated list of custom tables - **plugins** (flag) - Optional - Include plugins folder if flag present - **themes** (flag) - Optional - Include themes folder if flag present - **uploads** (flag) - Optional - Include uploads folder if flag present - **verbose** (flag) - Optional - Show detailed progress messages ### Return Type void ### Output Files in ZIP - `mu-migration-{random}-{sitename}.csv` — Users file - `mu-migration-{random}-{sitename}.sql` — Database tables - `mu-migration-{random}-{sitename}.json` — Site metadata - `wp-content/plugins/` — (optional) Plugins directory - `wp-content/themes/` — (optional) Theme directories - `wp-content/uploads/` — (optional) Uploads directory ### Site Metadata (JSON) ```json { "url": "https://example.com", "name": "Site Name", "admin_email": "admin@example.com", "site_language": "en-US", "db_prefix": "wp_", "plugins": {...}, "blog_plugins": [...], "network_plugins": {...}, "blog_id": 1 } ``` ### Processing Steps 1. Collects site metadata (URL, name, email, plugins, etc.) 2. Exports users to CSV 3. Exports database tables to SQL 4. Optionally copies plugins, themes, and uploads 5. Zips all files together 6. Cleans up temporary files ### Exits on Error Yes (via `WP_CLI::error()`) ### Warns on Issues Yes (non-fatal warnings from zip operation) ### Example ```php // Export main site with all optional components wp mu-migration export all site.zip --plugins --themes --uploads // Export subsite from multisite wp mu-migration export all subsite.zip --blog_id=2 // Export with custom tables wp mu-migration export all site.zip --non-default-tables=wp_custom1,wp_custom2 // Export with verbose output wp mu-migration export all site.zip --plugins --themes --verbose ``` ``` -------------------------------- ### Export Multisite Subsite to Multisite Source: https://github.com/10up/mu-migration/blob/master/_autodocs/START_HERE.md Export a specific subsite from a multisite installation, including plugins, themes, and uploads. Then, import it into another multisite environment, specifying the target subsite ID and new URL. ```bash # On source (multisite) wp mu-migration export all export.zip --blog_id=2 --plugins --themes --uploads # Transfer export.zip to target server # On target (multisite) wp mu-migration import all export.zip --blog_id=3 --new_url=target.dev/site ``` -------------------------------- ### Import Command Source: https://github.com/10up/mu-migration/blob/master/_autodocs/START_HERE.md Imports site data. Allows specifying target blog, overriding URLs, and handling table prefixes. ```APIDOC ## Import Command ### Description Imports site data. Allows specifying target blog, overriding URLs, and handling table prefixes. ### Command `wp mu-migration import` ### Parameters #### Common Import Parameters - **blog_id** (int) - Required - Target blog or new blog ID - **new_url** (string) - Optional - Override site URL - **old_prefix** (string) - Optional - Original table prefix - **new_prefix** (string) - Optional - New table prefix - **mysql-single-transaction** (flag) - Optional - Atomic SQL import - **uid_fields** (string) - Optional - Custom user ID fields - **map_file** (string) - Optional - User ID mapping output ``` -------------------------------- ### Import Site with New URL Source: https://github.com/10up/mu-migration/blob/master/README.md Imports a site from a zip package and sets a new URL for the imported site. This is useful for migrating to staging or local environments. ```bash $ wp mu-migration import all site.zip --new_url=multisite.dev/site ``` -------------------------------- ### WP-CLI Command Reference - Export Source: https://github.com/10up/mu-migration/blob/master/_autodocs/00_READ_ME_FIRST.txt Reference for 'wp mu-migration export' commands, including options for tables, users, and all site data. Specify the output file and optional blog ID. ```bash wp mu-migration export tables [--blog_id] [--tables] [--non-default-tables] ``` ```bash wp mu-migration export users [--blog_id] ``` ```bash wp mu-migration export all [] [--blog_id] [--plugins] [--themes] [--uploads] ``` -------------------------------- ### Import Entire Site Source: https://github.com/10up/mu-migration/blob/master/_autodocs/INDEX.md Use this command to import an entire WordPress site from a zip archive. You can specify a new URL for the imported site. This command also supports updating author mappings and user passwords. ```bash wp mu-migration import all site.zip --new_url=example.com ``` ```bash wp mu-migration posts update_author user_map.json --blog_id=2 ``` ```bash wp mu-migration users update_passwords --reset --send_email --blog_id=2 ``` -------------------------------- ### Table Import with URL Replacement Source: https://github.com/10up/mu-migration/blob/master/_autodocs/configuration.md This configuration is for importing tables and performing a search-replace on URLs. It's useful when migrating a site to a new domain or subdomain. Both old and new URLs must be provided. ```bash wp mu-migration import tables export.sql \ --blog_id=2 \ --old_prefix=wp_ \ --new_prefix=wp_2_ \ --old_url=old.example.com/site \ --new_url=multisite.dev/newsite ``` -------------------------------- ### ImportCommand::tables() Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/ImportCommand.md Imports database tables from a SQL file, rewriting table prefixes and URLs. It requires specific parameters for blog ID, old and new prefixes, and optionally handles URL search-replace and multisite uploads path updates. ```APIDOC ## ImportCommand::tables() ### Description Imports database tables from a SQL file, rewriting table prefixes and URLs. This method handles database prefix rewriting, URL replacements, and multisite uploads path updates. ### Method `tables(array $args = array(), array $assoc_args = array(), bool $verbose = true): void` ### Parameters #### Positional Arguments - **args** (array) - Optional - `[]` - Positional arguments: `[0]` = input SQL filename - **verbose** (bool) - Optional - `true` - Output progress messages #### Named Arguments - **blog_id** (int) - Required - Blog ID to import tables into - **old_prefix** (string) - Required - Original database table prefix - **new_prefix** (string) - Required - New database table prefix for target site - **old_url** (string) - Optional - Original site URL for search-replace - **new_url** (string) - Optional - New site URL for search-replace - **original_blog_id** (int) - Optional - Original blog ID in multisite (for uploads path) ### Processing Steps 1. Validates `blog_id` is provided. 2. Verifies `sed` command is available. 3. Rewrites database table prefixes using `sed` (if `new_prefix` provided). 4. Imports SQL file via `wp db import`. 5. Performs URL search-replace (if `old_url` and `new_url` provided). 6. Updates uploads paths for multisite (if original blog_id > 1). 7. Updates `wp_user_roles` option key for new prefix. ### Uploads Path Handling - Single site → multisite blog 2: updates paths from `wp-content/uploads` to `wp-content/uploads/sites/2`. - Multisite blog 2 → multisite blog 3: updates paths from `wp-content/uploads/sites/2` to `wp-content/uploads/sites/3`. ### Requires `sed` command-line tool ### Exits on Error Yes (if sed not available or blog_id missing) ### Example ```php $import = new ImportCommand(); $import->tables( array('site.sql'), array( 'blog_id' => 2, 'old_prefix' => 'wp_', 'new_prefix' => 'wp_2_', 'old_url' => 'old.example.com', 'new_url' => 'new.example.com', 'original_blog_id' => 1 ) ); ``` ``` -------------------------------- ### Export Site Data with WP-CLI Source: https://github.com/10up/mu-migration/blob/master/_autodocs/INDEX.md Use these commands to export different parts of your WordPress site. The 'all' command creates a ZIP package. ```bash wp mu-migration export tables wp mu-migration export users wp mu-migration export all ``` -------------------------------- ### Add User to Blog (Lightweight) Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/Helpers.md Adds a user to a specific blog with a given role without switching the current blog context. Useful for bulk operations where context switching is undesirable. ```php function light_add_user_to_blog( int $blog_id, int $user_id, string $role ): \WP_Error ``` ```php Helpers\light_add_user_to_blog(2, 5, 'editor'); // Adds user 5 as editor to blog 2 ``` -------------------------------- ### zip() Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/Helpers.md Creates a ZIP file from a specified list of files and directories, allowing for custom internal paths within the archive. ```APIDOC ## zip() ### Description Creates a ZIP file from files and directories. ### Method Not applicable (PHP function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **zip_file** (string) - Required - Output ZIP file path - **files_to_zip** (array) - Required - Array of file/dir paths to include. The array format should be `'internal/path' => '/absolute/source/path'`. ### Request Example ```php Helpers\zip('export.zip', array( 'users.csv' => '/tmp/users.csv', 'tables.sql' => '/tmp/tables.sql', 'wp-content/uploads' => '/var/www/html/wp-content/uploads', )); ``` ### Response #### Success Response void #### Response Example None (void return type) ``` -------------------------------- ### WP-CLI Command Reference - Post-Migration Source: https://github.com/10up/mu-migration/blob/master/_autodocs/00_READ_ME_FIRST.txt Reference for post-migration commands like updating post authors and resetting user passwords. These commands require specific files and blog IDs. ```bash wp mu-migration posts update_author --blog_id [--uid_fields] ``` ```bash wp mu-migration users update_passwords [] [--blog_id] [--reset] [--send_email] ``` -------------------------------- ### Export All Site Data to ZIP with WP-CLI Source: https://github.com/10up/mu-migration/blob/master/_autodocs/START_HERE.md Export all site data, including plugins, themes, and uploads, into a ZIP archive. Use the --verbose flag for more detailed output. ```bash wp mu-migration export all [] [--blog_id=X] [--plugins] [--themes] [--uploads] [--verbose] ``` -------------------------------- ### Import Database Tables with Prefix and URL Rewriting Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/ImportCommand.md Imports database tables from a SQL file. This method is crucial for migrating data between sites with different table prefixes and URLs, especially in multisite environments. Requires the 'sed' command-line tool. ```php $import = new ImportCommand(); $import->tables( array('site.sql'), array( 'blog_id' => 2, 'old_prefix' => 'wp_', 'new_prefix' => 'wp_2_', 'old_url' => 'old.example.com', 'new_url' => 'new.example.com', 'original_blog_id' => 1 ) ); ``` -------------------------------- ### light_add_user_to_blog() Source: https://github.com/10up/mu-migration/blob/master/_autodocs/api-reference/Helpers.md Adds a user to a multisite blog with a specified role without switching the blog context. This is a lighter alternative to WordPress's `add_user_to_blog()` for bulk operations. ```APIDOC ## light_add_user_to_blog(int $blog_id, int $user_id, string $role) ### Description Adds user to multisite blog with specified role without switching context. ### Method `light_add_user_to_blog` ### Parameters #### Path Parameters - **blog_id** (int) - Required - Blog ID to add user to - **user_id** (int) - Required - User ID to add - **role** (string) - Required - Role to assign to user ### Response #### Success Response (200) - **WP_Error** - Error object if user doesn't exist, otherwise empty. ### Example ```php Helpers\light_add_user_to_blog(2, 5, 'editor'); ``` ``` -------------------------------- ### Import Users from CSV Source: https://github.com/10up/mu-migration/blob/master/_autodocs/endpoints.md Imports user data from a CSV file. Requires a map file for ID mappings and optionally accepts a blog ID for multisite imports. ```bash wp mu-migration import users users.csv --map_file=user_map.json ``` ```bash wp mu-migration import users users.csv --map_file=user_map.json --blog_id=2 ``` -------------------------------- ### Export All Site Data to ZIP Source: https://github.com/10up/mu-migration/blob/master/_autodocs/configuration.md Performs a complete site export, including database tables, user data, and optionally plugins, themes, and uploads, into a ZIP archive. The filename can be specified or will be auto-generated. ```bash wp mu-migration export all complete.zip --plugins --themes --uploads ``` ```bash wp mu-migration export all subsite.zip --blog_id=2 --plugins --themes --uploads ``` ```bash wp mu-migration export all export.zip \ --non-default-tables=wp_custom1,wp_custom2 \ --plugins ``` ```bash wp mu-migration export all export.zip \ --plugins --themes --uploads --verbose ``` ```bash wp mu-migration export all export.zip ``` -------------------------------- ### Post-Migration Commands with WP-CLI Source: https://github.com/10up/mu-migration/blob/master/_autodocs/INDEX.md Run these commands after migration to fix post authors or reset user passwords. ```bash wp mu-migration posts update_author wp mu-migration users update_passwords ``` -------------------------------- ### Import users to a specific multisite blog Source: https://github.com/10up/mu-migration/blob/master/_autodocs/configuration.md To import users into a specific multisite blog, provide the blog ID using the `--blog_id` parameter. This ensures users are added to the correct subsite. ```bash wp mu-migration import users users.csv \ --map_file=user_map.json \ --blog_id=2 ```