Transform Learning with a Powerful Enterprise LMS

Learn more
WordPress LMS

Building a Custom LMS Plugin for WordPress: Data Model and Architecture

How to structure a custom WordPress LMS plugin: what belongs in post types and what needs custom tables, how LearnDash, LifterLMS and Tutor LMS split their data, and the code decisions that are hard to change later.

Learn more about this topic with AI

Gemini opens with the prompt copied - paste it into the chat to start.

Concept illustration of a custom WordPress LMS plugin architecture with post types, custom tables and APIs stacked as layers

The architecture of a custom WordPress LMS plugin comes down to one decision made early: what lives in WordPress's own tables and what gets custom tables. Put the content (courses, lessons, quizzes) in custom post types so it gets the editor, revisions, permalinks and the REST API for free. Put the per-learner records (enrolments, progress, quiz attempts, activity) in your own indexed tables, because they grow with users times courses and need queries that post meta and user meta handle badly. Around that you need a capability model, one access-check function every screen uses, hooks and REST routes for extension, a background job queue and a versioned schema upgrade path.

This article is for developers deciding whether to build a custom WordPress LMS plugin and how to structure it if they do. It shows how the established plugins split their data, proposes a data model, and covers the code-level decisions that are expensive to change later. Checked against the WordPress Plugin Handbook and REST API handbook, and the data models in the source of LearnDash 4.18.0.1, LifterLMS 8.0.1 and Tutor LMS 4.1.3 (October 2026). Code samples are not run on a live site; test on staging first.

Build custom or extend an existing LMS plugin?

Most projects should extend an existing plugin. The established ones already handle enrolment, progress, quizzes, certificates and payments, and they are maintained. A custom build earns its cost when:

  • the learning model does not fit courses, lessons and quizzes, for example competency frameworks, clinical sign-offs or apprenticeship evidence;
  • you need to own the data model for reporting, integration or audit reasons and do not want to depend on another vendor's storage choices;
  • the LMS is a small part of a larger product and you only need a narrow set of features, built your way;
  • performance at your scale needs a schema you control.

If none of those apply, compare the existing plugins first; our best WordPress LMS plugins roundup is a starting point. If you do build, the rest of this article applies.

How established LMS plugins store their data

The three most widely used plugins all mix custom post types with custom tables, but they draw the line in different places. All three keep course content in posts; they differ in where learner state lives.

LearnDash 4.18.0.1LifterLMS 8.0.1Tutor LMS 4.1.3
Course contentPost types such as sfwd-courses, sfwd-lessons, sfwd-quiz; settings in one serialized meta array per post (_sfwd-courses)Post types course, section, lesson, llms_quiz and llms_questionPost types courses, lesson, tutor_quiz; quiz questions in a custom table
Course structureCourse meta ld_course_steps, plus ld_course_{id} meta on each step for shared stepsParent IDs in post meta (_llms_parent_course, _llms_parent_section)post_parent relations through a topics post type
EnrolmentUser meta course_{id}_access_fromRows in lifterlms_user_postmeta, newest _status row winsOne tutor_enrolled post per enrolment
Progress and activityUser meta _sfwd-course_progress plus the learndash_user_activity and learndash_user_activity_meta tableslifterlms_user_postmetaUser meta and comments
Quiz attemptsWP Pro Quiz tables plus user meta _sfwd-quizzeslifterlms_quiz_attempts tabletutor_quiz_attempts table

The pattern to take from this: content in posts works well for all three. Learner state is where they diverge, and where most reporting and performance work ends up. LearnDash keeps progress both in user meta and in its activity tables, so reports have two places to look. A new plugin can choose one home for learner state from the start.

The content model: custom post types

Register courses, lessons and any other authored content as custom post types. You get the block editor, revisions, autosave, trash, permalinks, search and REST endpoints without writing them. Give the types their own capability type so editors of normal pages cannot edit courses by default.

add_action( 'init', 'acme_lms_register_types' );

function acme_lms_register_types() {
	$caps = array( 'acme_course', 'acme_courses' );

	register_post_type( 'acme_course', array(
		'labels'          => array(
			'name'          => __( 'Courses', 'acme-lms' ),
			'singular_name' => __( 'Course', 'acme-lms' ),
		),
		'public'          => true,
		'has_archive'     => true,
		'rewrite'         => array( 'slug' => 'courses' ),
		'supports'        => array( 'title', 'editor', 'thumbnail', 'excerpt', 'revisions' ),
		'show_in_rest'    => true,
		'capability_type' => $caps,
		'map_meta_cap'    => true,
	) );

	register_post_type( 'acme_lesson', array(
		'labels'          => array(
			'name'          => __( 'Lessons', 'acme-lms' ),
			'singular_name' => __( 'Lesson', 'acme-lms' ),
		),
		'public'          => true,
		'supports'        => array( 'title', 'editor', 'revisions', 'page-attributes' ),
		'show_in_rest'    => true,
		'capability_type' => $caps,
		'map_meta_cap'    => true,
	) );

	register_post_meta( 'acme_lesson', 'acme_course_id', array(
		'type'              => 'integer',
		'single'            => true,
		'show_in_rest'      => true,
		'sanitize_callback' => 'absint',
		'auth_callback'     => function ( $allowed, $meta_key, $post_id ) {
			return current_user_can( 'edit_post', $post_id );
		},
	) );
}

Decisions to make here:

  • Structure. A lesson belongs to a course through a meta key, post_parent or a relationship table. A single meta key is simplest. If a lesson can appear in several courses, use a relationship table with the course ID, step ID, step type and sort order, so ordering is a cheap indexed query rather than a serialized array.
  • Settings. Prefer individual registered meta keys over one serialized settings array. Individual keys can be queried, exposed in REST with a schema and changed without rewriting the whole array.
  • Quiz questions. If question banks will be large, shared across quizzes and reported on per question, a table is cleaner than a post per question. If authors need to edit questions as content with revisions, posts are easier. Tutor LMS and LearnDash made opposite choices here; both work.

The learner data model: custom tables

The WordPress Plugin Handbook says post meta is the preferred method "when possible/practical" and that a separate table suits data that grows over time. Enrolments, progress and attempts are exactly that: they grow with every learner and every course, and you query them in ways meta tables do not index well, such as "all learners in this course whose enrolment expires this month". A minimal schema:

TableOne row perKey columns and indexes
acme_lms_enrolmentsUser and courseuser_id, course_id, status, source, enrolled_at, expires_at, completed_at; unique (user_id, course_id); index (course_id, status)
acme_lms_progressUser and stepuser_id, course_id, step_id, status, started_at, completed_at; unique (user_id, step_id); index (course_id, user_id)
acme_lms_attemptsQuiz attemptuser_id, quiz_id, course_id, started_at, ended_at, score, max_score, passed, answers (JSON)
acme_lms_eventsLearning eventuser_id, object_id, verb, context, created_at; append-only, for reporting and export

Create tables with dbDelta(), which the handbook describes as "rather picky": each field on its own line, two spaces between PRIMARY KEY and the definition, KEY rather than INDEX, no backticks around field names, lowercase field types and a length on every field that takes one.

define( 'ACME_LMS_DB_VERSION', '1.0.0' );

function acme_lms_install() {
	global $wpdb;
	require_once ABSPATH . 'wp-admin/includes/upgrade.php';

	$charset_collate = $wpdb->get_charset_collate();
	$table           = $wpdb->prefix . 'acme_lms_enrolments';

	$sql = "CREATE TABLE $table (
  id bigint(20) unsigned NOT NULL auto_increment,
  user_id bigint(20) unsigned NOT NULL,
  course_id bigint(20) unsigned NOT NULL,
  status varchar(20) NOT NULL default 'active',
  source varchar(50) NOT NULL default '',
  enrolled_at datetime NOT NULL,
  expires_at datetime NULL,
  completed_at datetime NULL,
  PRIMARY KEY  (id),
  UNIQUE KEY user_course (user_id,course_id),
  KEY course_status (course_id,status)
) $charset_collate;";

	dbDelta( $sql );
	update_option( 'acme_lms_db_version', ACME_LMS_DB_VERSION );
}
register_activation_hook( __FILE__, 'acme_lms_install' );

add_action( 'plugins_loaded', 'acme_lms_maybe_upgrade' );
function acme_lms_maybe_upgrade() {
	if ( get_option( 'acme_lms_db_version' ) !== ACME_LMS_DB_VERSION ) {
		acme_lms_install();
	}
}

The plugins_loaded check matters: the handbook notes that since WordPress 3.1 the activation hook does not run when a plugin is updated, so schema changes in a new version need a version check on another hook. Store dates in UTC, decide early whether the attempt answers column is JSON or a child table, and remember that on multisite $wpdb->prefix gives each site its own tables.

Roles, capabilities and the access check

With capability_type set to acme_course and map_meta_cap on, WordPress maps edits to capabilities such as edit_acme_courses, edit_others_acme_courses and publish_acme_courses. Grant them to administrators and to an instructor role in the activation routine with add_role() and add_cap(). Roles are stored in the database, so do this on activation or upgrade, not on every request.

Learner access is a separate question from editing rights. Put it in one function that every template, REST route, shortcode and block calls, and make it filterable so integrations can extend it without patching:

function acme_lms_is_enrolled( $user_id, $course_id ) {
	global $wpdb;

	$user_id   = absint( $user_id );
	$course_id = absint( $course_id );
	if ( ! $user_id || ! $course_id ) {
		return false;
	}

	$table  = $wpdb->prefix . 'acme_lms_enrolments';
	$status = $wpdb->get_var(
		$wpdb->prepare(
			"SELECT status FROM {$table} WHERE user_id = %d AND course_id = %d AND ( expires_at IS NULL OR expires_at > %s )",
			$user_id,
			$course_id,
			current_time( 'mysql', true )
		)
	);

	return (bool) apply_filters( 'acme_lms_is_enrolled', 'active' === $status, $user_id, $course_id );
}

Every enrolment change should go through one function too, for example acme_lms_enrol( $user_id, $course_id, $source ), which writes the row, logs an event and fires an action. Payment gateways, membership plugins, CSV imports and admin screens then all behave the same way.

Hooks and REST routes for extension

A custom LMS rarely stays standalone; it ends up talking to a CRM, an HR system or a store. Plan the extension surface from the start:

  • Actions on state changes: acme_lms_enrolled, acme_lms_step_completed, acme_lms_course_completed, acme_lms_attempt_submitted. Fire them after the database write, with IDs rather than objects.
  • Filters on decisions: the access check, completion rules and passing scores.
  • REST routes under your own namespace for anything that is not a post. Since WordPress 5.5, leaving out permission_callback triggers a _doing_it_wrong notice; public routes should say so with __return_true, and everything else should check capabilities or enrolment.
add_action( 'rest_api_init', function () {
	register_rest_route( 'acme-lms/v1', '/courses/(?P<id>\d+)/progress', array(
		'methods'             => WP_REST_Server::READABLE,
		'callback'            => 'acme_lms_rest_get_progress',
		'permission_callback' => function ( WP_REST_Request $request ) {
			return is_user_logged_in()
				&& acme_lms_is_enrolled( get_current_user_id(), (int) $request['id'] );
		},
	) );
} );

For deeper integration patterns, see our article on BuddyBoss and LMS integration architecture.

Background jobs, performance and uninstall

Background work. Bulk enrolments, certificate generation, report builds and outbound syncs should not run inside a page request. WP-Cron only runs when the site gets traffic, so for queues of real work use a job library. Action Scheduler, maintained by Automattic, describes itself as "a scalable, traceable job queue for background processing large queues of tasks in WordPress"; LearnDash 4.18.0.1 bundles version 3.7.0 of it. It provides functions such as as_enqueue_async_action() and as_schedule_single_action() and keeps its queue in its own actionscheduler_* tables.

Performance. Index the columns you filter on, keep reporting queries off the request path, and cache per-user lookups such as the access check with the object cache for the length of a request. Load-test with a realistic number of learners and enrolments before launch, not just with sample courses.

Uninstall. Ship an uninstall.php that checks WP_UNINSTALL_PLUGIN and, only when the site owner has opted in, drops your tables, options, roles, capabilities and scheduled actions. Learner records are often subject to retention rules, so never delete them silently on uninstall.

Build order that keeps rework low

  1. Write down the learning model: what a course, step, attempt and completion mean for this organisation.
  2. Design the schema and the access and enrolment functions before any templates.
  3. Register post types and meta, then the tables with a versioned installer.
  4. Build the admin authoring flow, then the learner flow, both on top of the same functions.
  5. Add hooks and REST routes, then integrations.
  6. Add background jobs and reporting last, against realistic data volumes.

Our WordPress LMS development guide covers testing, deployment and the wider stack around a plugin like this.

How we can help

We design and build custom WordPress LMS plugins and extend existing ones when that is the better option. If you are weighing the two, or need a data model reviewed before you commit, see our LMS plugin development services or get in touch through our contact page.

Frequently asked questions

Should a WordPress LMS plugin use custom tables or post meta?

Use post types and post meta for authored content, and custom tables for per-learner records such as enrolments, progress and quiz attempts. The WordPress Plugin Handbook prefers post meta where practical and suggests a separate table for data that grows over time, which is what learner records do.

How do LearnDash, LifterLMS and Tutor LMS store enrolments?

In the versions we checked, LearnDash stores direct enrolment in user meta (course_{id}_access_from), LifterLMS in its lifterlms_user_postmeta table, and Tutor LMS as one tutor_enrolled post per enrolment.

How do I update custom tables when my plugin is updated?

Store a schema version in an option and compare it on plugins_loaded. If it differs, run dbDelta() with the new table definition and save the new version. The activation hook does not run on updates.

Is it better to build a custom LMS plugin or extend LearnDash, LifterLMS or Tutor LMS?

Extending an existing plugin is usually cheaper. A custom build makes sense when the learning model does not fit courses and lessons, when you must own the data model, or when you only need a narrow feature set inside a larger product.

Free 30-minute consultation

Not sure where to start? Talk to an LMS engineer.

Tell us what platform you run and what you need. You’ll get honest, practical advice - even if the answer is that you don’t need us.

Sources & references

  1. Creating Tables with Plugins - WordPress.org
  2. REST API changes in WordPress 5.5 - WordPress.org (Make Core)
  3. register_post_type() - WordPress.org
  4. Action Scheduler - Automattic
Add as a preferred source on Google

Add All-in-One LMS as a preferred source to see more of our articles in Google’s Top Stories.

Learn more about this topic with AI

Gemini opens with the prompt copied - paste it into the chat to start.

Keep reading

Before you go - get a free LMS audit

Tell us which LMS you use and what is not working. An engineer replies within one business day.

Choose which optional cookies we may use. You can change this at any time from "Cookie preferences" in the footer. Cookie policy · Privacy policy