=== Course Access Debugger for LearnDash ===
Contributors: rajaamanullah
Tags: learndash, course access, enrollment, troubleshooting, lms
Requires at least: 5.8
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Find out why a LearnDash user can or cannot access a course. A check-by-check access report and a per-course enrollment audit.

== Description ==

"My student can't open the course." Every LearnDash site owner gets this support ticket. [Course Access Debugger for LearnDash](https://rajaamanullah.com/product/course-access-debugger-for-learndash/) answers it in seconds: pick a user and a course, and see exactly why that user can or cannot access it.

LearnDash decides course access through around ten different mechanisms — direct enrolment, groups, the course price type, WooCommerce orders, access expiry, prerequisites, course points, drip schedules and linear progression. When a learner is locked out, LearnDash tells you nothing about which one said "no". You end up checking the enrolment, then the group, then the order, then the expiry setting, one screen at a time. Forty minutes later you find a refunded order or an expired enrolment.

This plugin runs every one of those checks for you, in order, and shows the result on one screen. Each check is marked **Pass**, **Fail** or **Not applicable**, with a plain-English explanation and a link straight to the setting that fixes it.

= The Access Debugger =

Go to **LearnDash LMS → Access Debugger**, choose a user and a course, and click **Analyze access**. At the top you get the verdict — the user CAN or CANNOT access the course — taken directly from LearnDash's own `sfwd_lms_has_access()` function, so it always matches what the learner actually sees. Below it, the full access-decision chain:

1. **Capability override** — is this an administrator or a group leader who bypasses the normal rules?
2. **Direct enrolment** — is the user enrolled, and when? It also tells you when a user *was* enrolled but LearnDash removed the enrolment because access expired — something LearnDash itself does not show.
3. **Group membership** — names the exact LearnDash group that grants the course, or confirms that none of the user's groups include it.
4. **Course price type** — explains what Open, Free, Buy Now, Recurring or Closed means for this user.
5. **WooCommerce order state** — if the course is sold through WooCommerce, finds the linked products and the user's orders, and flags a refunded, cancelled or failed order that removed access.
6. **Access expiry** — when access runs out, or when it expired.
7. **Prerequisites** — names the specific course the user still has to complete.
8. **Course points** — for example "requires 10 points, the user has 5".
9. **Drip / scheduled release** — choose a lesson, topic or quiz and see whether it is available yet for this user, and when it unlocks.
10. **Linear progression** — names the exact earlier step the learner must finish first.

Every failing check comes with a **Where to fix it** link that opens the right course, lesson, group or product settings.

= The Enrollment Audit =

**LearnDash LMS → Enrollment Audit** answers the opposite question: "Who is actually in this course, and how did they get access?"

Pick a course and you get a roster of every user with access, showing:

* User and email address
* **Access source** — direct enrolment, a named group, a WooCommerce order (with a link to it), an open course, or admin capability
* The date access was granted
* The expiry date
* Course progress as a percentage

**Expired learners are included too.** When course access expires, LearnDash removes the enrolment and the learner quietly disappears from your lists. The Enrollment Audit shows everyone who had access and lost it, and when — so you can renew them, follow up or win them back.

The audit is built for large courses:

* A summary line at the top, for example "142 users have access: 30 direct, 104 via 3 groups, 8 via WooCommerce — plus 4 expired"
* Filter by access source and search by name, username or email
* Sort by user, access source, granted date or expiry date
* Paginated, with pages loading instantly without a full reload
* **Export to CSV** — the file matches the filters you have applied, so you can hand someone an "expired learners" list in seconds

= Read-only and safe =

The plugin never changes anything. It does not modify enrolments, orders, progress, groups or settings — it only reads them and explains them. It adds no database tables and saves no options, so there is nothing to clean up if you remove it.

Both screens are available to administrators only, every request is protected with a nonce, and all output is escaped.

= Works with large sites =

On sites with more than a thousand users, the user dropdown is replaced with a lookup box that accepts a user ID, email address or username, so the page stays fast and any account can still be checked.

= Who it is for =

* **Course creators and LearnDash site owners** who answer "I can't access my course" emails
* **Support teams and agencies** maintaining LearnDash sites for clients
* **Training companies and membership sites** that sell courses through WooCommerce or grant them through groups
* **Developers** debugging custom enrolment flows, drip schedules or prerequisites

= For developers =

Add, remove or reorder checks with the `rau_cad_rules` filter. A custom rule — for example one for your own membership plugin — appears in the same Pass / Fail table as the built-in checks.

The plugin is translation ready and includes a `.pot` file.

= Also from the same developer =

* [Inactive Students for LearnDash](https://wordpress.org/plugins/inactive-students-for-learndash/) — find students who started a course and stopped, see exactly which lesson they quit at, and export the list.
* [Structure Audit for LearnDash](https://wordpress.org/plugins/structure-audit-for-learndash/) — finds orphaned lessons, empty courses, quizzes with no questions and broken course links in one screen.

= Documentation and support =

Documentation, setup guides and support are available on the developer's website: [rajaamanullah.com](https://rajaamanullah.com/). Read the [full documentation](https://rajaamanullah.com/docs/course-access-debugger-for-learndash/), visit the [plugin page](https://rajaamanullah.com/product/course-access-debugger-for-learndash/), or use the wordpress.org support forum.

= Disclaimer =

This is an independent plugin. It is not affiliated with, endorsed by or sponsored by LearnDash. "LearnDash" is used here only to describe the plugin this one works with.

== Installation ==

1. In your WordPress admin go to **Plugins → Add New**, search for "Course Access Debugger for LearnDash", then install and activate it. You can also upload the `course-access-debugger-for-learndash` folder to `/wp-content/plugins/`.
2. Make sure LearnDash LMS is active. Without it the plugin does nothing and shows a notice saying so.
3. Go to **LearnDash LMS → Access Debugger**, choose a user and a course, and click **Analyze access**.
4. To check a specific lesson, topic or quiz for drip and linear progression, choose it in the **Step** field and analyze again.
5. Go to **LearnDash LMS → Enrollment Audit**, choose a course and click **Audit course** to see everyone with access and how they got it.

There are no settings to configure.

== Frequently Asked Questions ==

= Why can't a user access a LearnDash course? =

The most common reasons are: the user is not enrolled, their access has expired, the WooCommerce order that granted access was refunded or cancelled, they have not completed a prerequisite course, they do not have enough course points, or the course is closed and they are not in a group that includes it. The Access Debugger checks all of these at once and tells you which one is blocking the user.

= How do I check a user's course access in LearnDash? =

Go to LearnDash LMS → Access Debugger, select the user and the course, and click Analyze access. You get a CAN or CANNOT verdict and a table of every access check with Pass, Fail or Not applicable.

= Does the verdict match what the student actually sees? =

Yes. The headline verdict comes from LearnDash's own `sfwd_lms_has_access()` function, the same function LearnDash uses on the front end. The checks underneath explain why that verdict was reached.

= Will this plugin change anything on my site? =

No. It is strictly read-only. It never changes enrolments, orders, progress, groups or settings, and it does not store any data of its own.

= Why is a lesson locked when the user has access to the course? =

Course access and lesson access are different. Choose the lesson, topic or quiz in the Step field and analyze again: the drip check shows whether the step has been released yet for this user, and the linear progression check names the earlier step they must finish first.

= Can I see which users have access to a LearnDash course? =

Yes. LearnDash LMS → Enrollment Audit lists every user with access to the chosen course, how they got access, when it was granted, when it expires and their progress.

= How do I find LearnDash users whose course access expired? =

Open the Enrollment Audit for the course. Users who had access and lost it are included and marked Expired, with the date. Filter the access source to "Expired" and export the list to CSV.

= Does it work with LearnDash groups? =

Yes. The Access Debugger names the group that grants the course, and the Enrollment Audit shows group-based access with the group's name.

= Does it work with courses sold through WooCommerce? =

Yes. When a course is linked to WooCommerce products, the plugin finds the user's orders for those products and shows their status, including refunded, cancelled or failed orders that removed access. WooCommerce is optional; the order check is simply marked Not applicable when it is not used.

= Can I export the enrollment list? =

Yes. The Export CSV button on the Enrollment Audit exports the roster with your current filters applied.

= Will the Enrollment Audit cope with courses that have thousands of students? =

Yes. The roster is built with a small number of bulk queries, and the table is paginated with search, filtering and sorting.

= My site has thousands of users. Can I still pick one? =

Yes. On sites with more than a thousand users, the dropdown is replaced with a lookup box. Enter a user ID, email address or username.

= Who can use the debugger? =

Administrators. Both screens require the manage_options capability.

= Can I add my own access checks? =

Yes. Use the `rau_cad_rules` filter to add, remove or reorder checks. Your rule is shown in the same table as the built-in checks.

= Does it work without LearnDash? =

No. LearnDash LMS must be installed and active. If it is not, the plugin shows a notice and does nothing else.

== Screenshots ==

1. Access Debugger — a user who cannot access a course, with the failing checks (enrolment, group, prerequisites and course points) and a link to fix each one.
2. Access Debugger — a user who can access a course through a LearnDash group, with the group named.
3. Access Debugger with a lesson selected — expired access, the drip schedule and the linear progression step that blocks the lesson.
4. Enrollment Audit — every user with access to a course, the access source, granted and expiry dates and progress, including expired learners.

== Changelog ==

= 1.0.0 =
* Initial release.
* Access Debugger: 10-check access-decision chain, optional per-step drip and progression analysis, WooCommerce order inspection.
* Enrollment Audit: per-course roster with access source, granted and expiry dates, progress, source filter, search, sortable columns, CSV export and summary counts.

== Upgrade Notice ==

= 1.0.0 =
Initial release.
