Skip to content

Prroffessorr/campus-lms-bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Campus LMS Bridge

A secured REST API bridge for WordPress that enables an external Laravel admin dashboard to manage LearnDash courses, lessons, users, and WooCommerce statistics. Utilizes WordPress Application Passwords for authentication.

Features

  • πŸ”’ Secure Authentication - Uses WordPress Application Passwords with Basic Auth
  • πŸ“š Course Management - Full CRUD operations for LearnDash courses
  • πŸ“ Lesson Management - Create, update, delete, and organize lessons
  • πŸ‘₯ User Management - List users, manage enrollments, and change roles
  • πŸ“Š Statistics Dashboard - WooCommerce sales data, revenue tracking, and subscription metrics
  • πŸ” Permission-Based Access - Admin-level permissions required for all endpoints

Requirements

  • WordPress 5.6 or higher
  • PHP 7.4 or higher
  • LearnDash LMS plugin
  • WooCommerce (for statistics features)
  • WooCommerce Subscriptions (optional, for subscription metrics)
  • Application Passwords enabled

Installation

  1. Upload the plugin files to /wp-content/plugins/campus-lms-bridge/ directory
  2. Activate the plugin through the 'Plugins' screen in WordPress
  3. Ensure LearnDash and WooCommerce are installed and activated
  4. Generate an Application Password for API access

Authentication

All API endpoints require authentication using WordPress Application Passwords.

Creating an Application Password

  1. Go to Users β†’ Profile in WordPress admin
  2. Scroll to Application Passwords section
  3. Enter a name (e.g., "Laravel Dashboard")
  4. Click Add New Application Password
  5. Copy the generated password

Using Authentication

Use Basic Authentication with your WordPress username and the Application Password:

curl -X GET https://your-site.com/wp-json/campus/v1/courses \
  -u username:application-password

API Endpoints

Base URL: /wp-json/campus/v1

Courses

Method Endpoint Description
GET /courses List all courses
GET /courses/{id} Get a single course
POST /courses Create a new course
PUT /courses/{id} Update a course
DELETE /courses/{id} Delete a course

Query Parameters for GET /courses:

  • page - Page number (default: 1)
  • per_page - Items per page (default: 20, max: 100)
  • status - Post status (default: any)

POST/PUT Parameters:

  • title - Course title (required for POST)
  • content - Course description
  • status - Post status (publish, draft, etc.)
  • price - Course price
  • access_mode - Access type (free, open, closed, etc.)

Lessons

Method Endpoint Description
GET /courses/{course_id}/lessons List all lessons for a course
POST /courses/{course_id}/lessons Create a new lesson
PUT /lessons/{id} Update a lesson
DELETE /lessons/{id} Delete a lesson

POST/PUT Parameters:

  • title - Lesson title (required for POST)
  • content - Lesson content
  • order - Lesson order/menu order

Users

Method Endpoint Description
GET /users List all users
GET /users/{id} Get a single user
POST /users/{id}/enroll Enroll user in a course
POST /users/{id}/unenroll Unenroll user from a course
PUT /users/{id}/role Change user role

Query Parameters for GET /users:

  • page - Page number (default: 1)
  • per_page - Items per page (default: 20, max: 100)
  • search - Search term

Enrollment Parameters:

  • course_id - Course ID (required)

Role Change Parameters:

  • role - WordPress role (subscriber, student, teacher, administrator, etc.)

Statistics

Method Endpoint Description
GET /stats Get comprehensive dashboard statistics

Statistics Response Includes:

  • total_users - Total registered users
  • total_courses - Total published courses
  • total_revenue - Lifetime WooCommerce revenue
  • active_subscriptions - Active subscription count
  • mrr - Monthly Recurring Revenue
  • enrollments_this_month - Current month enrollments
  • monthly_revenue - Revenue breakdown by month (chart data)
  • subscription_breakdown - Subscription status distribution
  • daily_enrollments - Daily enrollment trends (chart data)
  • top_products - Best-selling products

Usage Examples

List Courses with Pagination

curl -X GET "https://your-site.com/wp-json/campus/v1/courses?page=1&per_page=10" \
  -u username:app-password

Create a New Course

curl -X POST https://your-site.com/wp-json/campus/v1/courses \
  -u username:app-password \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Introduction to WordPress",
    "content": "Learn the basics of WordPress development",
    "status": "publish",
    "price": "99.00",
    "access_mode": "open"
  }'

Update a Course

curl -X PUT https://your-site.com/wp-json/campus/v1/courses/123 \
  -u username:app-password \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Advanced WordPress Development",
    "price": "149.00"
  }'

Create a Lesson

curl -X POST https://your-site.com/wp-json/campus/v1/courses/123/lessons \
  -u username:app-password \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Lesson 1: Getting Started",
    "content": "Welcome to the course!",
    "order": 1
  }'

Enroll a User in a Course

curl -X POST https://your-site.com/wp-json/campus/v1/users/456/enroll \
  -u username:app-password \
  -H "Content-Type: application/json" \
  -d '{
    "course_id": 123
  }'

Get Dashboard Statistics

curl -X GET https://your-site.com/wp-json/campus/v1/stats \
  -u username:app-password

Security

  • βœ… All endpoints require authentication via Application Passwords
  • βœ… Admin-level permissions (manage_options) required
  • βœ… Input sanitization on all parameters
  • βœ… WordPress nonces not required (using Application Passwords)
  • βœ… HTTPS recommended for production environments

Error Responses

The API returns standard HTTP status codes:

  • 200 - Success
  • 201 - Created
  • 400 - Bad Request
  • 401 - Unauthorized (authentication required)
  • 403 - Forbidden (insufficient permissions)
  • 404 - Not Found
  • 500 - Internal Server Error

Example error response:

{
  "code": "campus_rest_unauthorized",
  "message": "Authentication required. Use an Application Password via Basic Auth.",
  "data": {
    "status": 401
  }
}

File Structure

campus-lms-bridge/
β”œβ”€β”€ campus-lms-bridge.php          # Main plugin file
β”œβ”€β”€ README.md                       # This file
└── includes/
    β”œβ”€β”€ class-campus-auth.php       # Authentication handler
    β”œβ”€β”€ class-campus-courses.php    # Courses REST controller
    β”œβ”€β”€ class-campus-lessons.php    # Lessons REST controller
    β”œβ”€β”€ class-campus-users.php      # Users REST controller
    └── class-campus-stats.php      # Statistics REST controller

Development

Constants

  • CAMPUS_BRIDGE_VERSION - Plugin version
  • CAMPUS_BRIDGE_PATH - Plugin directory path
  • CAMPUS_BRIDGE_NS - REST API namespace (campus/v1)

Filters & Hooks

The plugin uses standard WordPress hooks:

  • plugins_loaded - Initialize plugin classes
  • rest_api_init - Register REST API routes

Support

For issues and feature requests, please contact WebCoders Dev.

Changelog

Version 1.0.0

  • Initial release
  • Course CRUD operations
  • Lesson management
  • User management and enrollment
  • WooCommerce statistics integration
  • Application Password authentication

License

This plugin is proprietary software developed by WebCoders Dev.


Author: WebCoders Dev
Version: 1.0.0
Requires: WordPress 5.6+, LearnDash, WooCommerce

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages