Repository navigation
fix(academy): let staff preview unpublished course steps - #1127
Merged
Merged
Conversation
LearnDash redirects non-admins viewing a lesson, topic or quiz outside its course URL to the step's nested permalink. An unpublished step has no slug, so that permalink is the preview URL itself, and Reviewers hit a redirect loop. Skip the check for previews by users who can edit the step.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Reviewers and Content Editors get "too many redirects" when previewing a Draft or Pending lesson, topic or quiz. Admins aren't affected.
With nested course URLs on,
learndash_check_course_stepsends non-admins (anyone withoutmanage_options) who open a step outside its course URL to the step's permalink within its course. An unpublished step has no slug, so that permalink is the preview URL itself, and the request redirects to itself.Fix
cbf-learndash-step-previews.phpunhookslearndash_check_course_stepfromwp(at priority 9) when the request is a preview of a lesson, topic or quiz and the user can edit it. WordPress only treats a request for an unpublished post as a preview when the viewer can edit it, so learners' course URL checks are unchanged. LearnDash has no filter for this check.Testing
Simulated front-end requests on production as a Reviewer (read-only), with the plugin loaded:
Not covered
The toolbar's View Quiz link on an unpublished step points to its nested course URL, which 404s for everyone, admins included, until it's published. That's WordPress behaviour for unpublished posts.