Skip to content

WP-CLI Commands

Learnomy adds a wp learnomy command group. It is useful for the jobs that are painful in the browser: enrolling a list of people, checking why one student’s progress looks wrong, repairing data after an import, and migrating from another LMS.

Everything here runs on your own server over SSH or a local shell. If you have never used WP-CLI, the only thing you need to know is that commands run from your WordPress directory.

Several commands check that the person running them may do the thing being asked. WP-CLI has no logged-in user, so those checks fail with a permissions error unless you say who you are:

Terminal window
wp --user=1 learnomy enroll --user-id=42 --course=17

Use --user=1 (or any administrator’s ID) on anything that writes. Read-only commands like stats and inspect do not need it.

Terminal window
wp --user=1 learnomy enroll --user-id=42 --course=17
wp --user=1 learnomy enroll --user-id=42 --course=17 --source=manual
wp --user=1 learnomy unenroll --user-id=42 --course=17

--source records how the enrollment happened. Leave it off unless you are reproducing a purchase.

Terminal window
wp learnomy progress --user-id=42 --course=17
wp learnomy earnings --user-id=7

progress prints where a student has got to in a course, which is the fastest answer to “the site says I have not finished”. earnings does the same for an instructor’s revenue share.

Terminal window
wp learnomy stats

Counts across courses, students, enrollments and revenue. Useful as a before-and-after when you have run something that changes data in bulk.

inspect prints one record in full, which is quicker than clicking through the admin when you are chasing a specific problem.

Terminal window
wp learnomy inspect course 17
wp learnomy inspect user 42
wp learnomy inspect enrollment 512
wp learnomy inspect quiz 8
wp learnomy inspect attempt 91
wp learnomy inspect cert 30
wp learnomy inspect subscription 14
wp learnomy inspect transaction 260
wp learnomy inspect db
Terminal window
wp learnomy repair data-integrity --dry-run
wp learnomy repair data-integrity
wp learnomy repair lesson-content
wp learnomy repair student-count

data-integrity is the one to reach for after an import or a bulk delete. It finds orphaned rows, drifted counters and progress that no longer matches the curriculum, and reports what it would change. Always run it with --dry-run first and read the report before letting it write.

student-count recomputes the enrolled figure shown on course cards when it has drifted. lesson-content repairs lesson bodies left malformed by an older import.

Terminal window
wp learnomy cleanup orphan-enrollments --dry-run
wp learnomy cleanup orphan-certs
wp learnomy cleanup orphan-commissions

Removes rows whose parent is gone. Same rule: dry-run first.

Terminal window
wp learnomy module list
wp learnomy module info membership
wp learnomy module enable membership
wp learnomy module disable pwa

Most Learnomy features are modules, and several ship switched off. This is the scriptable equivalent of the Modules screen, which is handy when you set up sites repeatedly. See Enabling Features and Modules.

Terminal window
wp learnomy course list
wp learnomy course create --title="Course title" --author_id=7
wp learnomy course delete 17 --yes
wp learnomy membership list
wp learnomy membership create --name="Pro" --price=19 --interval=monthly
Terminal window
wp learnomy content snapshot
wp learnomy content restore
wp learnomy content migrate

snapshot saves lesson content before a migration so restore can put it back. Take one before any bulk content operation you have not run on this site before.

Terminal window
wp learnomy migrate preview
wp learnomy migrate run
wp learnomy migrate status
wp learnomy migrate runs
wp learnomy migrate undo

preview reports what would be imported without writing anything. runs lists past imports and status reports on one; undo reverses an import that went wrong, which is the reason to prefer the CLI over the browser importer on a site with real data.

The browser importer covers the same ground with a UI. Use the CLI version for very large sites, where a browser import can time out. See Migrating from Another LMS.

Three types are available: courses, students and earnings.

Terminal window
wp learnomy export students --file=/tmp/students.csv
wp learnomy export courses --file=/tmp/courses.csv
wp learnomy export earnings --file=/tmp/earnings.csv
Terminal window
wp learnomy selfcheck run
wp learnomy db migrate

selfcheck run verifies the install: tables present, routes registered, scheduled jobs in place. Run it after an update if something feels wrong. db migrate applies any pending schema change, which normally happens automatically on update.

Terminal window
wp learnomy protect-attachments --dry-run
wp learnomy protect-attachments

Moves lesson attachments behind a permission check so a direct URL cannot be shared outside the course.

seed, seed-cleanup, seed-model-site, seed-quiz-attempts, seed-usecase and test are development and demo tools. They live in a directory that is stripped from the distributed plugin, so they will not appear on a normal install. If you see them, you are on a development checkout.