How to migrate from Thinkific to WordPress. Part 4: Reviews import
In the previous article, the third part of this 5-article series, I described the implementation of the
WP-CLI command to import the progress of courses for users.
In part four, I will describe the functionality of the
WP-CLI command to import reviews given by users to the courses.
Below, I also provide you with the list of articles in the series:
Table of contents
Declaring the review import method
I start again with declaring the method and the helper variables for reading from the file:
I also declared a variable of type array with the list of files containing reviews for courses, which I will iterate through using
foreach ($files as $file).
Reading from file
JSON file structure
I'm putting here again the structure of the review file in
As in the previous articles, reading from files is done in a similar way, but this time I won't use the helper method
parse_csv_content to compose the vector with lines from the
Instead, I will use the
json_decode function to interpret the
I also declared a few more variables that will be useful later on.
I made sure that the course
names in the review files in the name field match the names of the courses created in
I then started looping through the reviews in the
review vector in the
JSON and proceeded like this:
I performed a search for the user's name to retrieve their ID from the database using the helper method
search_user_by_name, described below.
Then, I used the
wp_insert_comment function to create the review, to which I passed the necessary values:
- The ID of the course to which the review belongs
- The author's name
- The review date (slightly reformatted)
- The review content
- The custom values of the
Tutor LMSplugin to categorize the review as one of the
Tutor LMScourse reviews
- The user's ID
- The review rating
The method for searching for a user by name and surname is here:
In the initial phase, I performed a small normalization of the name, specifically removing spaces from the ends and replacing double spaces in the name with a single space.
I noticed many discrepancies of this kind in the
JSON-exported file obtained from
Thinkific course pages.
Then (in lines 3-5), I split the name by space to be able to obtain the first and last names, even when the full name consists of 3 names.
In this case, I used
ChatGPT, resulting in the combination of the
Furthermore, I used the
WP_User_Query class for the complex query to find the user by their first and last names, and finally, I returned the ID.
With the execution of the last
WP-CLI command, we now have the reviews added:
The migration is complete, and in the next article, I will make a few adjustments to the theme,
Tutor LMS, and
If you need such a migration, click below, and let's discuss.Contact me