Migrate From WordPress

On this page

Overview#

This guide moves users and their password hashes from WordPress to FusionAuth. The guide covers exporting the WordPress user tables, installing a password hashing plugin, and importing the users with scripts. To plan a migration at a higher level, see the FusionAuth migration guide.

Prerequisites#

To import passwords as well as profile data, you need a basic understanding of password hashes and salts. For an introduction, see The Math of Password Hashing Algorithms and Entropy.

You need the following:

  • Node.js and npm, to run the migration scripts.
  • Docker, to run WordPress and FusionAuth locally with the configuration that this guide provides.

Planning Considerations#

Obtaining User Data#

WordPress stores users in a MySQL database. You need access to the database to run the export script.

Mapping User Attributes#

The attributes of the User object in FusionAuth are well documented.

If there is an attribute in your WordPress user which cannot be directly mapped to a FusionAuth attribute, you can place it in the user.data field. This field can store arbitrary JSON values and will be indexed and searchable.

Social Logins#

When WordPress users log in with social login providers, such as Google, Facebook, or Twitter, confirm that FusionAuth supports each provider. For the supported providers, see Identity Providers.

When FusionAuth doesn't support a provider directly, the provider may work through an OIDC or SAML connection. Otherwise, open a feature request.

Migrating users with social logins such as Apple or Facebook requires that you have an existing user Id for that provider. What this unique user Id looks like depends on the particular social identity provider. The unique Id may be an email address, an integer, UUID, or a random string.

Configure the appropriate FusionAuth Identity Provider with the same values (client_id, etc) as the original user management system you are migrating away from.

Import users with the Import API, assigning each user with a social login a random password such as a UUID.

Your next step depends on whether the social login provider's unique identifier is available as part of your migration data. If you have the social login provider's unique identifier, for each user, use the Link API to create a link with the appropriate User Id, Identity Provider Id, and Identity Provider User Id.

  • The User Id is the Id of the recently created FusionAuth User.
  • The Identity Provider Id is found on the corresponding Identity Provider API documentation. Look for identityProvider.id.
  • The Identity Provider User Id is the existing social provider user identifier exported or otherwise extracted from the original system.

You do not need to migrate the social network token, which may or may not be accessible. During the first login of a newly migrated user, FusionAuth finds the unique user in the social login provider based on the migrated Identity Provider User Id, and completes the login. During this process, FusionAuth stores a token on the Link, if the social provider returns one. Depending on the configuration of the social provider, users may see a prompt asking if they want to allow FusionAuth to have access to user data such as email address.

Available since 1.28.0

IdP linking strategies have been available since version 1.28.0. Before that version, users were linked on email.

If you do not have the social login provider's identifier, you need to decide if you want to transparently link the two accounts, which is easier for the end user, or if you want to ask the user to manually link the accounts, which is more accurate, but may be confusing.

To transparently link the accounts, choose a linking strategy of Link On Email or Link On Username, which will create the user if they don't exist. However, if the user has an email address at their social provider which differs from the email address that was used to sign up for your application and which you imported to FusionAuth, then two accounts will be created.

For example, if the user has a Google account richard@gmail.com, but signed up for your application with richard@fusionauth.io, then if you use the Link On Email strategy, two different accounts will be created, since FusionAuth is trying to match on email address and they don't. The same holds true for usernames with the Link on Username strategy.

To prompt the user to link the accounts, choose a linking strategy of Pending, which will prompt the end user to sign into FusionAuth after they sign into the social provider, authoritatively linking the two accounts.

Here's more information about IdP Linking Strategies.

Note

Apple only returns a user's full name the first time the user logs in. Since you have users who have already used Apple to log in to your previous authentication gateway, Apple will not provide the user's name when they log in to FusionAuth now. The only solution is to import the user's name manually from your previous database into FusionAuth.

Other Entities#

Plan to migrate other important entities, such as roles. These entities are usually few, so automating the migration may not pay off. Migrate the configuration by hand or with a script.

Features may differ between WordPress and FusionAuth. User data is simpler: a user who arrives with a login identifier, such as an email address or username, and a password hash can log in to FusionAuth. To learn the differences before you migrate, download FusionAuth and build a proof of concept.

The entities to migrate for your application can include the following:

  • WordPress roles, stored in the wp_capabilities user meta field. This guide creates matching FusionAuth roles.
  • User meta fields that WordPress plugins add. Decide which fields to keep in the FusionAuth user.data field.

Identifiers#

When you create an object with the FusionAuth API, you can set the object's Id. The Id must be a UUID. WordPress user Ids are integers, so FusionAuth can't reuse them. The import script stores each WordPress Id in user.data.WordPress_ID.

Export Users#

In this section, you start a sample WordPress site in Docker, look at the tables that hold users, and export the users with a SQL script.

Clone the Code#

Clone the FusionAuth import scripts repository, and change into the wordpress directory:

$ git clone https://github.com/FusionAuth/fusionauth-import-scripts.git && cd fusionauth-import-scripts/wordpress

Start WordPress and FusionAuth#

Start FusionAuth, WordPress, and their databases:

$ cd docker && docker compose up

When the containers start, open a second terminal in the fusionauth-import-scripts/wordpress/docker directory. Configure WordPress with the WordPress CLI:

$ docker compose exec cli wp core install --url="http://localhost:3000" --title="WP" --admin_user="admin" --admin_password="password" --admin_email="admin@example.org" --skip-email

To confirm that WordPress works, open http://localhost:3000/wp-login.php and log in with the username admin and the password password.

Add a New User#

In the second terminal, create an example user to migrate:

$ docker compose exec cli wp user create richard richard@example.org --role=subscriber --user_pass=password

Explore the Users in the Database#

Connect to the WordPress database with any MySQL client, such as DBeaver. Use the following connection details:

  • Host: localhost
  • Port: 3306
  • Database: mysite
  • Username: admin
  • Password: password

WordPress keeps users in the wp_users and wp_usermeta tables.

The wp_users Table#

The wp_users table holds the identifiers and the password hash of each user. The table looks similar to the following:

ID |user_login |user_pass                                                       |user_nicename |user_email          |user_url              |user_registered     |user_activation_key |user_status |display_name |
---|-----------|----------------------------------------------------------------|--------------|--------------------|----------------------|--------------------|--------------------|------------|-------------
 1 |admin      |$wp$2y$10$/hohy2X3tj5VXTbGNsgL5.gqWXv9fzjHkTsmqV4vHI4QyK351HyHy |admin         |admin@example.org   |http://localhost:3000 |2026-10-16 12:08:24 |                    |0           |admin        |
 2 |richard    |$wp$2y$10$IwsQg/CVVCPO6vUlnr68U.HEEbfAVpzjlITYjjUh7CGI.OkGu/gui |richard       |richard@example.org |                      |2026-10-16 12:08:25 |                    |0           |richard      |

The WordPress Codex lists the columns but doesn't define every column. The following definitions come from how WordPress uses each column:

  • ID: The primary key, an auto-incremented integer.
  • user_login: The username for logging in to WordPress.
  • user_pass: The password hash.
  • user_nicename: A URL-friendly version of the username, used in author URLs.
  • user_email: The email address. Each user has a unique email address.
  • user_url: The URL of the user's website. The field is optional.
  • user_registered: The registration date and time, in YYYY-MM-DD HH:MM:SS format.
  • user_activation_key: A hash for account activation or password resets.
  • user_status: A deprecated field. Core WordPress doesn't use the field and leaves the value at 0.
  • display_name: The name that WordPress shows on posts and comments.

The wp_usermeta Table#

The wp_usermeta table holds every other user detail. WordPress plugins can add rows too. The table looks similar to the following:

umeta_id|user_id|meta_key             |meta_value
--------|-------|---------------------|-------------------------------
1       |1      |nickname             |admin
2       |1      |first_name           |
3       |1      |last_name            |
4       |1      |description          |
5       |1      |rich_editing         |true
6       |1      |syntax_highlighting  |true
7       |1      |comment_shortcuts    |false
8       |1      |admin_color          |modern
9       |1      |use_ssl              |0
10      |1      |show_admin_bar_front |true
11      |1      |locale               |
12      |1      |wp_capabilities      |a:1:{s:13:"administrator";b:1;}
13      |1      |wp_user_level        |10
14      |1      |dismissed_wp_pointers|
15      |1      |show_welcome_panel   |1
16      |2      |nickname             |richard
17      |2      |first_name           |
18      |2      |last_name            |
19      |2      |description          |
20      |2      |rich_editing         |true
21      |2      |syntax_highlighting  |true
22      |2      |comment_shortcuts    |false
23      |2      |admin_color          |modern
24      |2      |use_ssl              |0
25      |2      |show_admin_bar_front |true
26      |2      |locale               |
27      |2      |wp_capabilities      |a:1:{s:10:"subscriber";b:1;}
28      |2      |wp_user_level        |0
29      |2      |dismissed_wp_pointers|

The table has the following columns:

  • umeta_id: The primary key, an auto-incremented integer.
  • user_id: The Id of the user that owns the row. The value matches the ID column of wp_users.
  • meta_key: The name of the field.
  • meta_value: The value of the field. A value can be a string or a serialized PHP array.

The table uses an entity-attribute-value model. WordPress adds a field by adding a row with a new key, not a new column.

When you decide which fields to import, consider the following:

  • Skip blank fields, such as description.
  • Skip fields that only WordPress uses, such as rich_editing.
  • Skip legacy fields, such as wp_user_level.
  • Deserialize fields that hold serialized PHP, such as wp_capabilities. The value a:1:{s:13:"administrator";b:1;} is an array of one element, with the 13-character string key administrator and the boolean value true.

You might find the following keys:

  • wp_capabilities: The roles of the user, as a serialized array. The roles decide what the user can do in WordPress.
  • wp_user_level: A legacy numeric user level, kept for backward compatibility.
  • rich_editing: Whether the user writes with the visual editor, true or false.
  • syntax_highlighting: Whether the code editor highlights syntax, true or false.
  • comment_shortcuts: Whether the user moderates comments with keyboard shortcuts, true or false.
  • admin_color: The color scheme of the WordPress dashboard.
  • use_ssl: Whether WordPress forces SSL for the user's admin pages, 1 or 0.
  • show_admin_bar_front: Whether WordPress shows the admin bar when the user views the site, true or false.
  • locale: The language of the WordPress dashboard.
  • wp_dashboard_quick_press_last_post_id: The Id of the last post that the user created with the Quick Draft widget.
  • dismissed_wp_pointers: The admin pointers that the user dismissed.
  • session_tokens: The user's login sessions across devices.
  • wp_user-settings and wp_user-settings-time: The user's admin area settings, and the time of the last change to the settings.

Export the Users With SQL#

FusionAuth provides the export and import scripts under a permissive open source license. The wordpress/src directory holds the scripts, and wordpress/exampleData holds sample output of each script.

In the second terminal, install the npm dependencies:

$ cd ../src && npm install

Run the remaining script commands in this src directory.

Run 1_exportWordpressUsers.sql against the WordPress database. The script exports each row of wp_users as JSON, with the user's wp_usermeta fields in an array called meta. In DBeaver, view the output as text, and save the json_result column to a file called users.txt in the src directory.

Note

When you have the mysql CLI installed, export the users from the command line instead:

$ mysql -h 127.0.0.1 -P 3306 -u admin -ppassword mysite --raw < 1_exportWordpressUsers.sql > users.txt

Then delete the json_result column name from the first line of users.txt.

Compare your users.txt file with exampleData/1_wordpressExport/users.txt. Each line of the file is a JSON object, but the file as a whole isn't valid JSON. Convert the file to a JSON array:

$ node 2_convertTextToJson.mjs

The script writes users.json. Compare the output with exampleData/1_wordpressExport/users.json.

Import Users#

To import the users, install a password hashing plugin that checks WordPress hashes, map the WordPress fields to FusionAuth fields, and run the import script.

Use a WordPress Password Hash Plugin for FusionAuth#

WordPress 6.8 and later hash passwords with bcryptA password hashing algorithm supported by FusionAuth., after an HMAC-SHA384 prehash of the password. FusionAuth supports plain bcrypt but not the prehashed WordPress format. Earlier WordPress versions hash passwords with phpass. FusionAuth supports phpass hashes natively with the phpass-md5 scheme, but this guide's import script doesn't use the native scheme. For the schemes FusionAuth supports, see Password-Hashing Algorithms.

The contributed password hashing plugins include a WordPress plugin that checks both formats. With the plugin, users from every WordPress version import with one scheme. For more information about plugins, see Custom Password Hashing.

Note

The plugin repository holds several projects. Build and install only the Password Hashing Plugins project.

Clone the plugin repository:

$ git clone https://github.com/fusionauth/fusionauth-contrib.git

The plugin code lives in fusionauth-contrib/Password Hashing Plugins/src/main/java/com/mycompany/fusionauth/plugins/ExampleWordPressPhpassPasswordEncryptor.java:

/*
 * Copyright (c) 2020, FusionAuth, All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 */
package com.mycompany.fusionauth.plugins;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Random;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import com.mycompany.fusionauth.util.Base64Tools;
import io.fusionauth.plugin.spi.security.PasswordEncryptor;
import com.github.wolf480pl.phpass.PHPass;
import com.github.wolf480pl.phpass.BCrypt;

public class ExampleWordPressPhpassPasswordEncryptor implements PasswordEncryptor {

  @Override
  public int defaultFactor() {
    return 8;
  }

  /**
   * @param password the plaintext password to encrypt, not in base64 as it comes from the user input
   * @param salt not the salt. rather give the full previous hashed password in its entirety
   *             encoded in base64. the salt is included in the hash. if this password has
   *             never been hashed before then leave salt as null.
   * @param factor used only when generating a new phpass hash; imported hashes contain their own cost
   * @return the encrypted password including the salt. salt does not need to be stored separately.
   */
  @Override
  public String encrypt(String password, String salt, int factor) {
    try {
        String previousHash = Base64Tools.decode64(salt);
        if (previousHash != null && previousHash.startsWith("$wp")) {
          if (checkWordPressBcrypt(password, previousHash))
            return Base64Tools.encode64(previousHash);
          return Base64Tools.encode64(getRandomPassword());
        }
        PHPass phpass = new PHPass(factor);
        if (previousHash == null)
          return Base64Tools.encode64(phpass.HashPassword(password));
        if (phpass.CheckPassword(password, previousHash))
          return Base64Tools.encode64(previousHash);
        return Base64Tools.encode64(getRandomPassword());
    }
    catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  private boolean checkWordPressBcrypt(String password, String hash) throws Exception {
    // WordPress 6.8+: https://developer.wordpress.org/reference/functions/wp_check_password/
    if (!hash.matches("\\$wp\\$2y\\$[0-9]{2}\\$[./A-Za-z0-9]{53}") ||
        password.getBytes(StandardCharsets.UTF_8).length > 4096)
      return false;
    int cost = Integer.parseInt(hash.substring(7, 9));
    if (cost < 4 || cost > 30)
      return false;
    Mac hmac = Mac.getInstance("HmacSHA384");
    hmac.init(new SecretKeySpec("wp-sha384".getBytes(StandardCharsets.UTF_8), "HmacSHA384"));
    String prehash = Base64.getEncoder().encodeToString(hmac.doFinal(password.getBytes(StandardCharsets.UTF_8)));
    // The bundled BCrypt accepts $2a$, not $2y$. The WordPress prehash is always
    // 64 ASCII characters, so the revisions' high-bit handling cannot differ.
    return BCrypt.checkpw(prehash, "$2a$" + hash.substring(7));
  }

  String getRandomPassword() {
    return String.valueOf(new Random().nextInt(90000000) + 10000000);
  }

}

Most hashing plugins take a plaintext password and a Base64 salt, and return a Base64 hash. A WordPress hash contains the salt and the cost, so the WordPress plugin works differently. The import script saves the full WordPress hash in the salt field. The encrypt function checks the password against that hash:

  • When the password matches, encrypt returns the existing hash, so the hashes compare as equal.
  • When the password doesn't match, encrypt returns a random number, so the hashes never compare as equal.
  • When no existing hash exists, such as for a new password, encrypt returns a new phpass hash.

For a hash that starts with $wp, the plugin computes the same HMAC-SHA384 prehash as WordPress, and checks the prehash against the stored bcrypt hash.

The import script sets the factor to 8. The plugin uses the factor only for new phpass hashes, because imported hashes contain their own cost.

The plugin has the following related files, which you shouldn't need to change:

  • fusionauth-contrib/Password Hashing Plugins/src/test/java/com/mycompany/fusionauth/plugins/ExampleWordPressPhpassPasswordEncryptorTest.java holds the unit tests.
  • fusionauth-contrib/Password Hashing Plugins/src/main/java/com/mycompany/fusionauth/plugins/guice/MyExampleFusionAuthPluginModule.java registers the plugin with FusionAuth.

A WordPress site can replace the default hashing algorithm, for example through a plugin. In that case, write your own Password Encryptor, add a test, and register the class in the Guice module.

WordPress hashes start with a prefix that names the algorithm:

  • $wp$2y$10$: WordPress 6.8 and later. The hash is bcrypt, and the input is the Base64-encoded HMAC-SHA384 prehash of the password, with the key wp-sha384. $2y$ marks bcrypt, and the number that follows is the cost.
  • $P$ followed by a cost character, such as $P$B: phpass, which iterates MD5. WordPress versions earlier than 6.8 use phpass.
  • No prefix, 32 hexadecimal characters: plain MD5, from very old WordPress installations.
  • $1$: MD5 crypt.
  • $2a$, $2x$, or $2y$: bcrypt.
  • $5$ or $6$: SHA-256 crypt or SHA-512 crypt.
  • $argon2i$ or $argon2id$: Argon2.

The import script and the plugin handle only $wp$ and $P$ hashes. The import script stops with an error on any other format.

Build the plugin:

  1. Open a terminal in the fusionauth-contrib directory. Build a Docker image for Java, and start a container with the repository mounted as a volume:

    $ cd .devcontainer && \
    docker build -t javaimage . && \
    cd .. && \
    docker run -it --name javabox -v .:/workspace javaimage
    
  2. In the container, build the plugin and exit:

    $ cd "/workspace/Password Hashing Plugins" && \
    mvn clean install && \
    exit
    

When you have Java and Maven installed locally, run the mvn clean install command without Docker.

All tests pass, and Maven writes the plugin to Password Hashing Plugins/target/fusionauth-example-password-encryptor-0.1.0.jar.

Set Up FusionAuth and Deploy the Plugin#

FusionAuth already runs in the fa container from the earlier Docker Compose command. FusionAuth listens on http://localhost:9011. Log in to the Admin UI with admin@example.com and password.

Deploy the plugin:

  1. In the fusionauth-contrib terminal, copy the jar file into the plugins directory of the FusionAuth container:

    $ docker exec fa mkdir /usr/local/fusionauth/plugins && \
    docker cp "Password Hashing Plugins/target/fusionauth-example-password-encryptor-0.1.0.jar" fa:/usr/local/fusionauth/plugins/fusionauth-example-password-encryptor-0.1.0.jar
    
  2. Restart FusionAuth so FusionAuth loads the plugin. In the terminal that runs Docker Compose, press Ctrl+C, wait for the containers to stop, and run docker compose up again.

Create Roles for Your Users#

The wp_capabilities field gives the exported users the Administrator and Subscriber roles. In a terminal in the fusionauth-import-scripts/wordpress/src directory, create the roles in FusionAuth:

$ node 3_addRoles.mjs

To see the roles, navigate to Applications in the Admin UI, and click Select -> Manage Roles in the row of Example app. Kickstart created the Application from fusionauth-import-scripts/wordpress/docker/kickstart/kickstart.json when FusionAuth started for the first time.

Prepare Users for Import to FusionAuth#

The 4_convertWpUserToFaUser.mjs script maps the fields of users.json to FusionAuth fields. Change the script to skip fields or to map fields differently.

The script reads users.json with the stream-json library, which reads large files incrementally. The processUsers() function calls getFaUserFromUser() for each user, and writes the results to faUsers.json.

The getFaUserFromUser() function does the following:

  • Maps every WordPress field that has a matching FusionAuth field.
  • Stores the other WordPress fields in the data field. To skip a field, add the field to the dataToIgnore list at the top of the file.
  • Skips empty fields and arrays.
  • Sets encryptionScheme to example-wordpress-phpass, the name that the Guice module gives the plugin.
  • Adds a Registration for the Application, with the user's roles. Change the Application Id to match your Application in a real migration.

Helper functions at the bottom of the file read keys and values from the meta array and deserialize PHP values, such as wp_capabilities.

Read the function, and confirm that the script imports the user data that you need. Comment out the lines for data that you don't need. For more information about each user field, see the Users API.

Convert the users:

$ node 4_convertWpUserToFaUser.mjs

Use the Script#

With faUsers.json created and the plugin installed, import the users. In a terminal in the fusionauth-import-scripts/wordpress/src directory, run the import script:

$ node 5_import.mjs

The script calls importUsers() from the FusionAuth Node.js client library, @fusionauth/typescript-client. For more information, see the TypeScript client library.

The script imports one user per request. When the import runs too slowly for a production migration, send many users in each request. For batch sizes, see the Import Users API.

Verify the Import#

Log in to the Example app Application as an imported user:

  1. In the Admin UI, navigate to Applications , and click Select -> View in the row of Example app.

  2. Copy a URL from Login URLs.

    The Application details dialog with the login URLs highlighted.
    The Application details dialog with the login URLs highlighted.
  3. Open the URL in a private browser window, so the Admin UI session doesn't log you in.

  4. Log in with the email richard@example.org and the password password.

Note

After the login, FusionAuth redirects to a URL such as http://localhost:3000/auth/callback?code=FlZF97WIYLNxt4SGD_22qvpRh4fZ6kg_N89ZbBAy1E4&locale=en&userState=AuthenticatedRegistrationNotVerified, and WordPress shows the home page. No web application handles the authorization code redirect yet. To build one, follow a quickstart.

In the Admin UI, review the imported users:

The list of imported users.
The list of imported users.

To review a user's profile, click Select -> Manage in the row of the user. The Source tab shows the user as a JSON object.

Debug With the FusionAuth Database#

When imported users can't log in, check the FusionAuth database to confirm the import and the hashes.

Connect to the FusionAuth database with any PostgreSQL client, such as DBeaver. The connection details come from fusionauth-import-scripts/wordpress/docker/docker-compose.yml and .env:

  • URL: jdbc:postgresql://localhost:5432/fusionauth
  • Host: localhost
  • Port: 5432
  • Database: fusionauth
  • Username: fusionauth
  • Password: hkaLBM3RVnyYeYeqE3WI1w2e4Avpy0Wd5O3s3

Browse to Databases/fusionauth/Schemas/public/Tables, and check the users and identities tables.

What To Do Next#

phpass is a weak algorithm. When you import phpass hashes from WordPress versions earlier than 6.8, rehash the passwords with a stronger scheme at each user's next login. For more information, see Rehashing User Passwords.

After the users move, migrate the other configuration described in Other Entities. The steps vary by configuration, but follow this pattern:

  • Find the matching FusionAuth feature.
  • Configure the feature in FusionAuth, either in the Admin UI or with a script that uses the client libraries or the APIs.
  • Update your application configuration to use the FusionAuth feature.

Register your users with the right FusionAuth Applications in one of the following ways:

  • Add Registrations to the users during the import.
  • Create Registrations after the import with the Registrations API.

Change and test each application, whether custom, open source, or commercial, and confirm the following:

  • Users can log in.
  • The application handles the authorization code redirect.
  • Users get the right permissions and roles from the JWT.
  • The hosted login pages match the look and feel of the application.

When an application talks to WordPress through a standard OAuth, SAML, or OIDC library, the switch to FusionAuth usually takes few changes.

Additional Support#

If you need support in your migration beyond that provided in this guide, you may: