Skip to content

Add first lesson url placeholder to Welcome to Course email - #8127

Draft
faisalahammad wants to merge 6 commits into
Automattic:trunkfrom
faisalahammad:fix/8076-first-lesson-url
Draft

Add first lesson url placeholder to Welcome to Course email#8127
faisalahammad wants to merge 6 commits into
Automattic:trunkfrom
faisalahammad:fix/8076-first-lesson-url

Conversation

@faisalahammad

Copy link
Copy Markdown

Resolves #8076

Proposed Changes

The Welcome to Course email links new students only to the generic course page, and instructors can't hardcode a lesson URL that would be correct for every course. This change lets the email point students straight at the course's starting point.

  • Adds a [course:first_lesson_url] placeholder to the Welcome to Course email that resolves to the permalink of the course's first published lesson.
  • The default email pattern's "Start Course" button now uses this placeholder instead of [course:url].
  • The first lesson follows the course's saved lesson order (_lesson_order, the drag-and-drop order on the course page) when present.
  • Courses with no published lessons fall back to the course URL, so the button always has a valid target.
  • The placeholder is also registered on the email preview so the admin preview shows a token instead of an unreplaced tag.

Existing installs keep their user-customized email content (emails are editable content and are not rewritten on upgrade); the new button appears on fresh installs and after using the "Recreate Emails" tool.

Testing Instructions

  • On a fresh install (or after Recreate Emails), create a course with two published lessons, enroll a student, and trigger the Welcome email. The "Start Course" button links to the first lesson's permalink.
  • Reorder the course's lessons on the course page so a non-first lesson comes first, enroll another student, and trigger the email. The button links to the first lesson per the custom order, not by creation date.
  • Create a course with no lessons, enroll a student, and trigger the email. The button falls back to the course page URL.
  • Open the email preview in Sensei > Emails > Welcome. The button link renders as a preview token, not the raw [course:first_lesson_url] placeholder.

New/Updated Hooks

No hooks added or changed.

Deprecated Code

No code deprecated.

Changelog entry

Welcome to Course email now links the Start Course button to the first lesson with a new first lesson placeholder, so new students go straight to where learning begins.

- Add course:first_lesson_url replacement in the Course_Welcome generator,
  falling back to the course URL when the course has no published lessons.
- Use the placeholder for the Start Course link in the welcome email pattern.
- Include the placeholder in the email preview placeholder list.
- Update the Course_Welcome tests.

Fixes Automattic#8076
The WPML copy test asserts the full replacements array, which now includes
the course:first_lesson_url key (falling back to the course URL).
The first lesson url now follows the lesson order saved on the course page
(_lesson_order meta) when present, instead of only the course_lessons order,
so the welcome email links match what students see on the course page.

Adds a test covering the custom order.
Adds a changelog entry for the new course:first_lesson_url placeholder in
the Welcome to Course email.
- Format the test file per WP coding standards (short arrays to array(),
  realign `=>`/`=`).
- Coalesce course and first-lesson permalinks to definite strings before
  passing to esc_url() (Psalm 104).
- Guard against a falsy course_lessons() result with empty() instead of
  an is_array() check (Psalm 155 docblock contradiction).
- Narrow the WP_Post|int union from course_lessons() before casting to
  int in get_first_lesson_id() (Psalm 103).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Email: Add a first-lesson URL placeholder for the Welcome to Course email

1 participant