CI / Tests (PHP 8.2) (pull_request) Successful in 44s
CI / Tests (PHP 8.1) (pull_request) Successful in 49s
CI / No Debug Code (pull_request) Successful in 2s
CI / PHPStan (pull_request) Successful in 2m49s
CI / Coding Standards (pull_request) Successful in 2m55s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m40s
CI / Build Plugin Zip (pull_request) Skipped
Group classes can now be marked invite-only (us_offerings.access_mode). Invite-only classes are hidden from the public catalog and reachable only when the instructor lets someone in via one of three paths, managed from My Lessons -> My Group Classes: - Add students directly: enrols them now with a pending payment. - Make available: grants registered students access to self-enrol through the normal paid flow (multi-select, emailed a notice). - Invite by email: tokenised registration invite tied to the class for a non-account address; after they register the class becomes enrollable. Reuses an existing pending invite instead of sending a second link. New us_group_access table records grants; GET /offerings merges granted invite-only classes for the caller; enrolment requires a grant (403 invite_required) and flips it to enrolled on success. composer test (487), composer lint, composer cs all pass. Co-Authored-By: Claude Opus 4.8 <[email protected]>
164 lines
5.1 KiB
PHP
164 lines
5.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Auth;
|
|
|
|
use Unsupervised\Schedular\Val;
|
|
|
|
/**
|
|
* Transactional emails for the self-approval registration flow: the email
|
|
* confirmation link, the studio-admin heads-up that someone is ready to
|
|
* approve, and the approval / rejection notices to the student.
|
|
*/
|
|
class RegistrationMailer {
|
|
|
|
/**
|
|
* Email the new student a link to confirm their address. Returns false when
|
|
* there is no recipient.
|
|
*/
|
|
public function sendConfirmation( \WP_User $user, string $confirmUrl ): bool {
|
|
if ( '' === (string) $user->user_email ) {
|
|
return false;
|
|
}
|
|
|
|
$subject = sprintf(
|
|
/* translators: %s: site name */
|
|
__( 'Confirm your email for %s', 'unsupervised-schedular' ),
|
|
$this->siteName()
|
|
);
|
|
|
|
$body = sprintf(
|
|
/* translators: 1: site name, 2: confirmation URL */
|
|
__( "Thanks for signing up at %1\$s.\n\nPlease confirm your email address by opening this link:\n%2\$s\n\nOnce confirmed, a studio admin will review and approve your account. You'll get another email when it's ready.", 'unsupervised-schedular' ),
|
|
$this->siteName(),
|
|
$confirmUrl
|
|
);
|
|
|
|
return (bool) wp_mail( $user->user_email, $subject, $body );
|
|
}
|
|
|
|
/**
|
|
* Tell the studio admins a self-signup has confirmed their email and is
|
|
* waiting for approval. Sent to the site admin email.
|
|
*/
|
|
public function notifyAdminsPending( \WP_User $user ): bool {
|
|
$adminEmail = Val::string( get_option( 'admin_email', '' ) );
|
|
if ( '' === $adminEmail ) {
|
|
return false;
|
|
}
|
|
|
|
$subject = __( 'A new student is awaiting approval', 'unsupervised-schedular' );
|
|
$body = sprintf(
|
|
/* translators: 1: student name, 2: student email */
|
|
__( "%1\$s (%2\$s) has confirmed their email and is awaiting approval.\n\nReview them under Students → Pending Students in wp-admin.", 'unsupervised-schedular' ),
|
|
(string) $user->display_name,
|
|
(string) $user->user_email
|
|
);
|
|
|
|
return (bool) wp_mail( $adminEmail, $subject, $body );
|
|
}
|
|
|
|
/**
|
|
* Tell the student their account has been approved. Returns false when there
|
|
* is no recipient.
|
|
*/
|
|
public function sendApproved( \WP_User $user ): bool {
|
|
if ( '' === (string) $user->user_email ) {
|
|
return false;
|
|
}
|
|
|
|
$subject = sprintf(
|
|
/* translators: %s: site name */
|
|
__( 'Your %s account is approved', 'unsupervised-schedular' ),
|
|
$this->siteName()
|
|
);
|
|
$body = sprintf(
|
|
/* translators: 1: site name, 2: login URL */
|
|
__( "Good news — your account at %1\$s has been approved. You can now log in and book:\n%2\$s", 'unsupervised-schedular' ),
|
|
$this->siteName(),
|
|
wp_login_url()
|
|
);
|
|
|
|
return (bool) wp_mail( $user->user_email, $subject, $body );
|
|
}
|
|
|
|
/**
|
|
* Tell an applicant their registration was declined. Takes the email address
|
|
* directly, since the account is deleted as part of rejection.
|
|
*/
|
|
public function sendRejected( string $email ): bool {
|
|
if ( '' === $email ) {
|
|
return false;
|
|
}
|
|
|
|
$subject = sprintf(
|
|
/* translators: %s: site name */
|
|
__( 'Your %s registration', 'unsupervised-schedular' ),
|
|
$this->siteName()
|
|
);
|
|
$body = sprintf(
|
|
/* translators: %s: site name */
|
|
__( 'Thank you for your interest in %s. We are unable to approve your registration at this time. Please contact the studio if you have any questions.', 'unsupervised-schedular' ),
|
|
$this->siteName()
|
|
);
|
|
|
|
return (bool) wp_mail( $email, $subject, $body );
|
|
}
|
|
|
|
/**
|
|
* Tell a registered student they have been given access to an invite-only
|
|
* group class and can now enrol. Returns false when there is no recipient.
|
|
*/
|
|
public function sendClassAccessGranted( \WP_User $user, string $className ): bool {
|
|
if ( '' === (string) $user->user_email ) {
|
|
return false;
|
|
}
|
|
|
|
$subject = sprintf(
|
|
/* translators: %s: class title */
|
|
__( 'You have been invited to %s', 'unsupervised-schedular' ),
|
|
$className
|
|
);
|
|
$body = sprintf(
|
|
/* translators: 1: class title, 2: site name, 3: login URL */
|
|
__( "You have been given access to the group class \"%1\$s\" at %2\$s.\n\nLog in and open the group classes page to enrol:\n%3\$s", 'unsupervised-schedular' ),
|
|
$className,
|
|
$this->siteName(),
|
|
wp_login_url()
|
|
);
|
|
|
|
return (bool) wp_mail( $user->user_email, $subject, $body );
|
|
}
|
|
|
|
/**
|
|
* Email a tokenised registration link to someone invited to a group class who
|
|
* does not yet have an account. Returns false when there is no recipient.
|
|
*/
|
|
public function sendClassInvite( string $email, string $link, string $className ): bool {
|
|
if ( '' === $email ) {
|
|
return false;
|
|
}
|
|
|
|
$subject = sprintf(
|
|
/* translators: %s: class title */
|
|
__( 'You are invited to join %s', 'unsupervised-schedular' ),
|
|
$className
|
|
);
|
|
$body = sprintf(
|
|
/* translators: 1: class title, 2: site name, 3: registration URL */
|
|
__( "You have been invited to the group class \"%1\$s\" at %2\$s.\n\nCreate your account using this link, then choose to enrol in the class:\n%3\$s", 'unsupervised-schedular' ),
|
|
$className,
|
|
$this->siteName(),
|
|
$link
|
|
);
|
|
|
|
return (bool) wp_mail( $email, $subject, $body );
|
|
}
|
|
|
|
private function siteName(): string {
|
|
$name = (string) get_bloginfo( 'name' );
|
|
|
|
return '' !== $name ? $name : __( 'the studio', 'unsupervised-schedular' );
|
|
}
|
|
}
|