Migrate learnDash version 2 to 4 - createIT
Get a free advice now!

    Pick the topic
    Developer OutsourcingWeb developingApp developingDigital MarketingeCommerce systemseEntertainment systems

    Thank you for your message. It has been sent.

    Migrate learnDash version 2 to 4

    January 12, 2023
    Last update: February 8, 2023
    4 min read
    25
    0
    0
    Migrate learnDash version 2 to 4

    Challenge: migrate multisite learnDash courses, lessons and quizzes to a new site

    Solution: set up a single WordPress site, migrate the subsite and run data upgrader

    LearnDash is an LMS (learning management system) plugin for WordPress. It is used by universities and training organizations for online courses. LearnDash courses use: Lessons, Topic, Quizzes and Questions.

    You might be using an old version of the plugin (version 2) and you may want to migrate to the newest one (version 4), but not sure how to do it? Thousands of quizzes and questions already configured and migration to the new website looks time-consuming or even impossible? In this article, we will describe a solution for LearnDash data migration!

    sfwd-lms multisite

    It’s quite common to have an e-learning platform set up as a multisite. Different types of courses are configured to use custom subdomains and the entire WordPress site uses a common Administration Panel. Although it has some disadvantages, website administrators experience performance issues, problems with updating plugins and managing all the different subsites of a big multisite platform. The shared database contains all of the data and it’s starting to be a performance bottleneck for the entire site.

    Our old multisite website contains hundreds of courses and thousands of questions. We have decided to migrate the subsite of the multisite to a new domain, upgrade LearnDash to the newest version. Also, we will update all WP plugins and the WordPress core.

    The original website setup was:

    • WordPress 4.7.3
    • PHP 5.6
    • LearnDash 2.3.3
    • 15 subsites in the multisite
    • database .sql size – over 5GB
    • old subsite url: http://elearning.oldsite.com

    Here are our destination website parameters:

    • WordPress 6.0.1
    • PHP 7.4.1
    • LearnDash 4.2.1.2
    • single WordPress installation
    • fresh database
    • new domain: https://newsite.com

    Migrate multisite to standard WP

    The WP-Cli command line tool for managing WordPress will be our choice to speed up the process. First, we need to install new wp files:

    wp core download

    We need to export proper tables from the old multisite installation, only those starting with ‘wp_20’. This can be done manually in phpmyadmin or faster, using the WP CLI command:

    # export tables for subsite starting with prefix: 'wp_20' from multisite installation
    wp db export --tables=$(wp db tables 'wp_20*' --format=csv)

    Now, we have a .sql file generated. We’re going to copy this file to the new server and import .sql to the new DB:

    # import .sql to new website
    wp db import oldsite-2022-07-13-9b6a875.sql

    The database now contains the old siteurl and domain strings. These need to be replaced. The data in the database is serialized so we need to use a special tool to do the replacements: https://github.com/interconnectit/Search-Replace-DB . An alternative, faster solution is this command:

    # replace urls in database
    wp search-replace 'elearning.oldsite.com' 'newsite.com' --all-tables
    wp search-replace 'http://newsite.com' 'https://newsite.com' --all-tables
    # still todo: setup wp-config.php prefix

    wp-config.php prefix

    Now our database is migrated and urls are replaced. For the site to work properly, we need to set up proper a WordPress table prefix in the configuration file: wp-config.php

    /**
    * WordPress database table prefix.
    *
    * You can have multiple installations in one database if you give each
    * a unique prefix. Only numbers, letters, and underscores please!
    */
    $table_prefix = 'wp_20_';

    New files + admin user

    We need to remember about copying new plugins to wp-content/plugins/ and adding some standard wp theme. To be able to log in to wp-admin area, we will add a new user with Administrator privileges:

    wp user create newadmin [email protected] --role=administrator --allow-root
    wp user update newadmin --user_pass=secretPasswordHere --allow-root

    Log in to the new site

    The new site should be set up now and work properly. We can open /wp-admin/ url in the browser and log in using the new Administrator account. LearnDash version 2 has similar database structure to version 4, so most of the contents should already be working correctly and have everything set up like at the old multisite. There are some minor adjustments that we will make in the next part of the article.

    Upgrade data format

    In the older LearnDash version, questions were stored in a custom table. For a course to work properly, we need to migrate data to custom post types. Go to: Wp-admin / LearnDash LMS / Settings / Advanced / Data Upgrades and look for: ‘Upgrade Quiz Questions’ – by clicking ‘Upgrade’ – the conversion will be started (it can take a while, questions will be processed in batch by the admin ajax function).

    WP dashboard with red panel on the left and a lot of text

    Renaming table

    Another option worth mention – is “Rename WPProQuiz DB Tables”. It’s changing name of pro_quiz tables, new prefix will be: wp_20_learndash_pro_quiz_ . Before clicking ‘Upgrade’ for this option – it is recommended to enable maintenance mode for your site.

    Options menu, white page with a lot of text

    Database cleanup

    That’s it. At this point all LearnDash data is migrated: courses, lessons, topics, quizzes and questions. Database structures for questions are converted to version 4 standards. In last step – we can do some database cleanup. In case there are some old, not used custom post types in wp_20_posts table (some multisite leftovers) – we can easily delete those. Here is command for ‘news’ custom post type:

    # Delete old posts (custom post-type 'news')
    wp post delete $(wp post list --post_type='news' --format=ids) --force

    Summary

    Migration process was speed up by using WP CLI commands. Data was imported in .sql and original post Ids were keeped. We avoided conflicts connected with Ids collisions or necessity to convert old postmeta post_id to new values. At this point – LearnDash plugin data is migrated to new version. We can add more contents manually or invite users to register on our elearning platform.

    That’s it for today’s tutorial. Don’t forget to subscribe to our newsletter to stay up to date on other useful articles.

    Support – Tips and Tricks
    All tips in one place, and the database keeps growing. Stay up to date and optimize your work!

    Contact us