Add open student registration with email confirmation and approval
CI / Tests (PHP 8.1) (pull_request) Successful in 1m18s
CI / Tests (PHP 8.2) (pull_request) Successful in 1m18s
CI / No Debug Code (pull_request) Successful in 2s
CI / PHPStan (pull_request) Successful in 3m20s
CI / Coding Standards (pull_request) Successful in 3m25s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m33s
CI / Build Plugin Zip (pull_request) Skipped

Students could previously join by invite only. Add an optional
self-approval mode, toggled from Studio Settings → Registration: anyone
may sign up on the existing [us_student_register] page, confirm their
email via a tokenised link, and then be approved by a studio admin
before the account is usable.

- Enabling the toggle mirrors WordPress's own membership settings
  (users_can_register + default_role = us_student) and snapshots their
  previous values so disabling restores them.
- WordPress's native registration form is blocked while open
  registration is on (login_init redirect + registration_errors
  fail-safe + register_url) so it cannot bypass signup policy acceptance.
- Pending accounts: unconfirmed email cannot log in; confirmed but
  unapproved can log in but the booking capability is withheld and the
  booking page shows an "awaiting approval" screen.
- Approve/reject from Students → Pending Students; reject hard-deletes
  the account so the email is freed to re-apply.
- Invite registration is unchanged; both modes coexist.

Account lifecycle lives in user meta (RegistrationStatus); no new tables.

Closes #63

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
2026-07-18 10:50:21 -03:00
co-authored by Claude Opus 4.8
parent e7d8257973
commit 7370755951
23 changed files with 1713 additions and 88 deletions
+92
View File
@@ -0,0 +1,92 @@
<?php
declare(strict_types=1);
if (! defined('ABSPATH')) {
exit;
}
use Unsupervised\Schedular\Auth\RegistrationApprovalController;
/**
* @var array<int, \WP_User> $awaitingApproval Confirmed, awaiting a decision.
* @var array<int, \WP_User> $awaitingConfirmation Not yet confirmed their email.
*/
?>
<div class="wrap">
<h1><?php esc_html_e('Pending Students', 'unsupervised-schedular'); ?></h1>
<div class="notice notice-info inline">
<p>
<?php esc_html_e('Students who signed themselves up appear here. Once they confirm their email you can approve them into a full student account, or reject the application to remove it.', 'unsupervised-schedular'); ?>
</p>
</div>
<h2><?php esc_html_e('Awaiting approval', 'unsupervised-schedular'); ?></h2>
<?php if (empty($awaitingApproval)) : ?>
<p><?php esc_html_e('No students are awaiting approval.', 'unsupervised-schedular'); ?></p>
<?php else : ?>
<table class="widefat striped">
<thead>
<tr>
<th><?php esc_html_e('Name', 'unsupervised-schedular'); ?></th>
<th><?php esc_html_e('Email', 'unsupervised-schedular'); ?></th>
<th><?php esc_html_e('Registered', 'unsupervised-schedular'); ?></th>
<th><?php esc_html_e('Actions', 'unsupervised-schedular'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($awaitingApproval as $user) : ?>
<tr>
<td><?php echo esc_html((string) $user->display_name); ?></td>
<td><?php echo esc_html((string) $user->user_email); ?></td>
<td><?php echo esc_html((string) $user->user_registered); ?></td>
<td>
<form method="post" style="display:inline">
<?php wp_nonce_field(RegistrationApprovalController::NONCE_ACTION); ?>
<input type="hidden" name="user_id" value="<?php echo esc_attr((string) $user->ID); ?>">
<button type="submit" name="usc_action" value="approve" class="button button-primary"><?php esc_html_e('Approve', 'unsupervised-schedular'); ?></button>
</form>
<form method="post" style="display:inline" onsubmit="return confirm('<?php echo esc_js(__('Reject and delete this application?', 'unsupervised-schedular')); ?>');">
<?php wp_nonce_field(RegistrationApprovalController::NONCE_ACTION); ?>
<input type="hidden" name="user_id" value="<?php echo esc_attr((string) $user->ID); ?>">
<button type="submit" name="usc_action" value="reject" class="button button-link-delete"><?php esc_html_e('Reject', 'unsupervised-schedular'); ?></button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<h2><?php esc_html_e('Awaiting email confirmation', 'unsupervised-schedular'); ?></h2>
<?php if (empty($awaitingConfirmation)) : ?>
<p><?php esc_html_e('No students are awaiting email confirmation.', 'unsupervised-schedular'); ?></p>
<?php else : ?>
<table class="widefat striped">
<thead>
<tr>
<th><?php esc_html_e('Name', 'unsupervised-schedular'); ?></th>
<th><?php esc_html_e('Email', 'unsupervised-schedular'); ?></th>
<th><?php esc_html_e('Registered', 'unsupervised-schedular'); ?></th>
<th><?php esc_html_e('Actions', 'unsupervised-schedular'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($awaitingConfirmation as $user) : ?>
<tr>
<td><?php echo esc_html((string) $user->display_name); ?></td>
<td><?php echo esc_html((string) $user->user_email); ?></td>
<td><?php echo esc_html((string) $user->user_registered); ?></td>
<td>
<form method="post" style="display:inline" onsubmit="return confirm('<?php echo esc_js(__('Reject and delete this application?', 'unsupervised-schedular')); ?>');">
<?php wp_nonce_field(RegistrationApprovalController::NONCE_ACTION); ?>
<input type="hidden" name="user_id" value="<?php echo esc_attr((string) $user->ID); ?>">
<button type="submit" name="usc_action" value="reject" class="button button-link-delete"><?php esc_html_e('Reject', 'unsupervised-schedular'); ?></button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
+22
View File
@@ -15,6 +15,7 @@ if (! defined('ABSPATH')) {
* @var string $etransferEmail
* @var float $hstRate
* @var bool $stripeConfigured
* @var bool $openRegistration
*/
?>
<div class="wrap">
@@ -88,6 +89,27 @@ if (! defined('ABSPATH')) {
</td>
</tr>
</table>
<h2><?php esc_html_e('Registration', 'unsupervised-schedular'); ?></h2>
<table class="form-table">
<tr>
<th scope="row"><?php esc_html_e('Student sign-up', 'unsupervised-schedular'); ?></th>
<td>
<fieldset>
<label>
<input type="checkbox" name="open_registration" value="1" <?php checked($openRegistration); ?>>
<?php esc_html_e('Allow anyone to sign up (email confirmation + admin approval)', 'unsupervised-schedular'); ?>
</label>
<p class="description">
<?php esc_html_e('Off by default — students join by invite only. When on, anyone can register on the student registration page; each new account must confirm its email and then be approved by a studio admin under Students → Pending Students before it can be used.', 'unsupervised-schedular'); ?>
</p>
<p class="description">
<?php esc_html_e('Turning this on also switches on Settings → General → “Anyone can register” and sets the default new-user role to Student. Turning it off restores those two settings to what they were before.', 'unsupervised-schedular'); ?>
</p>
</fieldset>
</td>
</tr>
</table>
<?php submit_button(esc_html__('Save Settings', 'unsupervised-schedular')); ?>
</form>
</div>
+60 -44
View File
@@ -9,60 +9,76 @@ if (! defined('ABSPATH')) {
* @var \Unsupervised\Schedular\Auth\Invite|null $invite
* @var string $token Raw invite token from the request (only its hash is stored).
* @var bool $canRegister
* @var bool $success
* @var bool $open Whether open (self-approval) registration is enabled.
* @var string $successType '' | 'invite' (created + logged in) | 'confirm' (check email).
* @var string $confirmResult '' | '1' (email confirmed) | 'expired'.
* @var string $error
* @var list<array{policy: \Unsupervised\Schedular\Policy\Policy, version: \Unsupervised\Schedular\Policy\PolicyVersion}> $policyForms
*/
?>
<div class="us-register-form">
<?php if ($success) : ?>
<?php if ($successType === 'invite') : ?>
<p class="us-success"><?php esc_html_e('Your account has been created and you are now logged in.', 'unsupervised-schedular'); ?></p>
<?php elseif (! $canRegister) : ?>
<p><?php esc_html_e('Registration is by invitation only. Please use the link from your invitation email, or contact the studio.', 'unsupervised-schedular'); ?></p>
<?php elseif ($successType === 'confirm') : ?>
<p class="us-success"><?php esc_html_e('Your account has been created. Check your email for a link to confirm your address — once you do, a studio admin will review and approve your account.', 'unsupervised-schedular'); ?></p>
<?php else : ?>
<?php if ($error !== '') : ?>
<p class="us-error" role="alert"><?php echo esc_html($error); ?></p>
<?php if ($confirmResult === '1') : ?>
<p class="us-success"><?php esc_html_e('Thanks — your email is confirmed. Your account is now awaiting studio approval; we will email you when it is ready.', 'unsupervised-schedular'); ?></p>
<?php elseif ($confirmResult === 'expired') : ?>
<p class="us-error" role="alert"><?php esc_html_e('That confirmation link is invalid or has expired. Please contact the studio.', 'unsupervised-schedular'); ?></p>
<?php endif; ?>
<form method="post" action="">
<?php wp_nonce_field('us_student_register'); ?>
<input type="hidden" name="us_invite" value="<?php echo esc_attr($token); ?>">
<p>
<label for="us-reg-email"><?php esc_html_e('Email', 'unsupervised-schedular'); ?></label>
<input type="email" id="us-reg-email" value="<?php echo esc_attr($invite->email); ?>" readonly>
</p>
<p>
<label for="us-reg-name"><?php esc_html_e('Your name', 'unsupervised-schedular'); ?></label>
<input type="text" name="display_name" id="us-reg-name" autocomplete="name" required>
</p>
<p>
<label for="us-reg-pass"><?php esc_html_e('Password', 'unsupervised-schedular'); ?></label>
<input type="password" name="password" id="us-reg-pass" autocomplete="new-password" minlength="8" required>
</p>
<?php if (! empty($policyForms)) : ?>
<fieldset class="us-policies">
<legend><?php esc_html_e('Policies', 'unsupervised-schedular'); ?></legend>
<?php foreach ($policyForms as $form) : ?>
<div class="us-policy">
<h4><?php echo esc_html($form['policy']->title); ?></h4>
<div class="us-policy-body"><?php echo wp_kses_post((string) $form['version']->body); ?></div>
<label>
<input type="checkbox" name="accept[]" value="<?php echo esc_attr((string) $form['version']->id); ?>" required>
<?php
/* translators: %s: policy title */
echo esc_html(sprintf(__('I have read and agree to the %s.', 'unsupervised-schedular'), $form['policy']->title));
?>
</label>
</div>
<?php endforeach; ?>
</fieldset>
<?php if (! $canRegister) : ?>
<p><?php esc_html_e('Registration is by invitation only. Please use the link from your invitation email, or contact the studio.', 'unsupervised-schedular'); ?></p>
<?php else : ?>
<?php if ($error !== '') : ?>
<p class="us-error" role="alert"><?php echo esc_html($error); ?></p>
<?php endif; ?>
<p>
<input type="submit" name="us_register" value="<?php esc_attr_e('Create Account', 'unsupervised-schedular'); ?>">
</p>
</form>
<form method="post" action="">
<?php wp_nonce_field('us_student_register'); ?>
<input type="hidden" name="us_invite" value="<?php echo esc_attr($token); ?>">
<p>
<label for="us-reg-email"><?php esc_html_e('Email', 'unsupervised-schedular'); ?></label>
<?php if ($invite !== null) : ?>
<input type="email" id="us-reg-email" value="<?php echo esc_attr($invite->email); ?>" readonly>
<?php else : ?>
<input type="email" name="email" id="us-reg-email" autocomplete="email" required>
<?php endif; ?>
</p>
<p>
<label for="us-reg-name"><?php esc_html_e('Your name', 'unsupervised-schedular'); ?></label>
<input type="text" name="display_name" id="us-reg-name" autocomplete="name" required>
</p>
<p>
<label for="us-reg-pass"><?php esc_html_e('Password', 'unsupervised-schedular'); ?></label>
<input type="password" name="password" id="us-reg-pass" autocomplete="new-password" minlength="8" required>
</p>
<?php if (! empty($policyForms)) : ?>
<fieldset class="us-policies">
<legend><?php esc_html_e('Policies', 'unsupervised-schedular'); ?></legend>
<?php foreach ($policyForms as $form) : ?>
<div class="us-policy">
<h4><?php echo esc_html($form['policy']->title); ?></h4>
<div class="us-policy-body"><?php echo wp_kses_post((string) $form['version']->body); ?></div>
<label>
<input type="checkbox" name="accept[]" value="<?php echo esc_attr((string) $form['version']->id); ?>" required>
<?php
/* translators: %s: policy title */
echo esc_html(sprintf(__('I have read and agree to the %s.', 'unsupervised-schedular'), $form['policy']->title));
?>
</label>
</div>
<?php endforeach; ?>
</fieldset>
<?php endif; ?>
<p>
<input type="submit" name="us_register" value="<?php esc_attr_e('Create Account', 'unsupervised-schedular'); ?>">
</p>
</form>
<?php endif; ?>
<?php endif; ?>
</div>