Notify instructors on new bookings and enrolments
CI / Coding Standards (pull_request) Successful in 27s
CI / Tests (PHP 8.1) (pull_request) Successful in 37s
CI / No Debug Code (pull_request) Successful in 9s
CI / Tests (PHP 8.3) (pull_request) Successful in 36s
CI / Tests (PHP 8.5) (pull_request) Successful in 40s
CI / Tests (PHP 8.2) (pull_request) Successful in 42s
CI / Static Analysis (pull_request) Successful in 48s
CI / Build Plugin Zip (pull_request) Skipped

Add an opt-in, per-instructor email notice sent when someone books one of
their lessons or enrols in one of their group classes. Off by default and
set from My Availability → Notifications; covers both the student/guardian
REST flows and the studio's wp-admin "book/add for a student" forms.

The opt-in check lives in InstructorNotificationMailer so no booking path
can drift on who is mailed; lessons fire from LessonBooker::settle (the one
step both booking paths reach), enrolments from EnrollmentEndpoint::enroll
and GroupClassController::addDirect. The notice is a courtesy and never
fails a booking or enrolment that otherwise succeeded.

Co-authored-by: anthropic/claude-opus-4-8
This commit is contained in:
2026-09-18 16:18:43 -03:00
co-authored by anthropic/claude-opus-4-8
parent 56fc0bd57d
commit 12765d8f13
16 changed files with 583 additions and 3 deletions
+54
View File
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace Unsupervised\Schedular\Auth;
use Unsupervised\Schedular\Val;
/**
* An instructor's own choice of whether the studio emails them when someone
* enrols in one of their group classes or books one of their lessons.
*
* It is a per-instructor preference, kept in user meta rather than a studio-wide
* option, because the people it emails are the ones who should decide: one
* instructor wants a heads-up for every booking, another already lives in the
* roster and wants no extra mail. The instructor sets it from their own
* {@see \Unsupervised\Schedular\Availability\AvailabilityController My
* Availability} page.
*
* It defaults **off**. The notification is a new capability, and turning it on
* for every instructor on an existing site the day it ships would mail people
* who never asked to be mailed; an instructor who wants it opts in.
*/
class InstructorNotificationPref {
/**
* User-meta key holding the per-instructor toggle. Stored as `'1'` / `'0'`,
* mirroring the `us_*` string-boolean convention the plugin's options use.
*/
public const META_NOTIFY = 'us_notify_on_booking';
/**
* Whether the given instructor has asked to be emailed about new enrolments
* and bookings. Absent meta — the default for every account — reads as off.
*/
public function wants( int $instructorId ): bool {
if ( $instructorId <= 0 ) {
return false;
}
return '1' === Val::string( get_user_meta( $instructorId, self::META_NOTIFY, true ) );
}
/**
* Record an instructor's choice. Stored as `'0'` rather than deleted so a
* deliberate "no" is told apart from an account that never chose.
*/
public function set( int $instructorId, bool $wants ): void {
if ( $instructorId <= 0 ) {
return;
}
update_user_meta( $instructorId, self::META_NOTIFY, $wants ? '1' : '0' );
}
}