Learndash rest api

From Lonsdale201/wp-agent-skills · View interactive version

Learndash rest api is an AI agent skill from the GitHub repository Lonsdale201/wp-agent-skills. Build or audit LearnDash REST API integrations for courses, lessons, topics, quizzes, groups, users, course steps, enrollments, group memberships, progress, and the modern LearnDash REST manifest/OpenAPI docs. Use when code mentions ldlms/v2, learndash/v1, LearnDash_REST_API, learndash_rest_api_enab

How to use this skill

Skill file

LearnDash REST API

Use this when building or reviewing a REST/headless integration for LearnDash.

Prefer source-verified routes and schemas over guessed endpoint shapes.

LearnDash 5.1.9 exposes two relevant REST surfaces:

The v2 endpoints are still the practical surface for course, group, user,

progress, and course-steps CRUD. The learndash/v1 manifest/docs surface is the

discovery contract and includes newer endpoint metadata.

When to use this skill

Trigger when ANY of these appears:

learndash_rest_api_enabled, or learndash-rest-api-controllers.

groups, users, course progress, quiz progress, or assignments.

progress data.

/steps payload errors.

Enablement and namespaces

REST availability requires both:

LearnDash_REST_API::enabled() also exposes the

learndash_rest_api_enabled filter.

Classic LearnDash REST namespace defaults to ldlms; v2 routes use

ldlms/v2. The namespace constant is LEARNDASH_REST_API_NAMESPACE.

Do not hard-code every route base. LearnDash settings allow REST base overrides

for courses, lessons, topics, quizzes, groups, users, and relation subroutes.

Default important v2 bases:

Discovery workflow

For learndash/v1, do not guess parameters. The local source declares the

manifest as the mandatory discovery workflow.

Use:

Most learndash/v1 endpoints are experimental and require:

Learndash-Experimental-Rest-Api: allow

The manifest and OpenAPI documentation endpoints are public and not

experimental in 5.1.9.

Course steps endpoint

Creating lesson/topic/quiz posts is not enough to build a course outline.

Update the course steps relationship.

Endpoint:

GET/POST /wp-json/ldlms/v2/sfwd-courses/{course_id}/steps

Read permission:

learndash_rest_course_steps_allow_anonymous_read returns true.

Update permission:

Expected update body shape is an object keyed by LearnDash post types. Lesson,

topic, and quiz IDs are object keys, not list items:

{
  "sfwd-lessons": {
    "123": {
      "sfwd-topic": {
        "456": {
          "sfwd-quiz": {
            "789": {}
          }
        }
      },
      "sfwd-quiz": {}
    }
  },
  "sfwd-quiz": {
    "999": {}
  }
}

Common bug: sending [123, 456] arrays. The controller expects nested objects

where IDs are keys.

Course custom pagination in 5.1.7+

Course REST fields expose lessons_per_page, lesson_per_page_custom, and

topic_per_page_custom. When custom pagination is enabled, use positive

integers for both custom values. LearnDash 5.1.7+ normalizes empty or zero

values to the corresponding global setting, then to

LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE if the global value is also invalid.

Do not use zero to mean "show all" for these course-specific fields. Disable

custom pagination when the course should inherit the global values.

Enrollment and relation endpoints

Course users:

The controller calls ld_update_course_access() for enrollment and rejects open

courses with learndash_rest_rejected_course_open. It can skip admin users

when admin auto-enroll is enabled.

User courses:

enrolled_at.

Group courses:

Group users:

User groups:

Permission model:

controllers.

Extending REST safely

LearnDash's v2 REST loader registers controllers on rest_api_init and exposes

the controller list through learndash-rest-api-controllers. Prefer adding a

separate namespaced WP REST controller for custom app APIs unless the task

specifically needs to extend LearnDash's own route catalog.

For custom fields on LearnDash posts:

posts controller and the specific post-type controller before inventing field

names.

enrollment writes publicly.

Progress routes are read-only

The v2 user progress routes expose course headers, ordered steps, quiz

progress, and challenge-exam state through GET requests. In 5.1.9,

/users/{id}/course-progress, its /{course} route, /{course}/steps, and

/{course}/exam do not register a general progress-write method.

Do not invent a PATCH contract from the response schema. For a custom mutation

endpoint, authorize the actor against the target user and call LearnDash's

completion/progress APIs; use learndash-course-progress for that lifecycle.

Headless integration checklist

  1. Check REST is enabled in constants and LearnDash settings.
  2. Discover actual bases from settings or manifest/docs instead of assuming

defaults on customized sites.

  1. Authenticate with Application Password, cookie+nonce, OAuth/JWT layer, or a

site-specific auth plugin.

  1. Fetch course posts and then fetch /steps for the outline.
  2. Use relation endpoints for enrollment/group changes, not raw usermeta.
  3. Use progress endpoints for progress, not direct activity-table writes.
  4. Respect pagination, batch limits, and per-item success/failure responses.
  5. Cache read responses carefully and invalidate on post, access, group, and

progress mutations.

Common mistakes to reject

details.

checking sfwd_lms_has_access().

Cross-references

enrollment semantics.

behavior.

and progress-write behavior.

References

Validated against LearnDash LMS 5.1.9 local source:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.