Let parents register once and book for their children
A parent registers once and manages lessons for one or more children, who need no login of their own. A child is a real wp_users row with the student role but no usable login — so student_id keeps meaning "a WordPress user" on every table, and booking, credits, policies and enrolments work unchanged. A us_guardians link table maps guardian to child. The signup form gains a parent/guardian tick that reveals a block per child, with the account-signup questions asked per child rather than per guardian — they describe the student, not the account holder. Signup policies are recorded once per child with the guardian as the acceptor, which is the record that actually means something. A family that half-creates is rolled back entirely rather than leaving a guardian who cannot re-register. The booking and enrolment forms gain a "Who is this for?" picker listing children first, so the default selection is never the parent — booking for the wrong child is correctable, quietly billing a parent for their kid's lesson is not. POST /bookings and POST /enrollments take an optional student_id honoured only for that child's guardian; anything else is a 403. That check is the authorisation boundary of the feature. Payments and credits gain a payer: the charge names the child it was for and the guardian who owes it, so per-child reporting is unchanged while notices, receipts and the payment step reach the parent. Credit is held by the payer, so one child's cancellation can settle a sibling's charge, and the daily billing scan sends a guardian one notice covering every child. Closes #132 Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
use Unsupervised\Schedular\Registration\Question;
|
||||
use Unsupervised\Schedular\Registration\QuestionField;
|
||||
|
||||
if (! defined('ABSPATH')) {
|
||||
exit;
|
||||
@@ -22,39 +23,6 @@ if (! defined('ABSPATH')) {
|
||||
* @var list<Question> $accountQuestions Studio-wide questions answered as step two.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Render one account-signup question's input, named `us_answers[<id>]`.
|
||||
*/
|
||||
$renderQuestionField = static function (Question $question): void {
|
||||
$id = (int) $question->id;
|
||||
$name = 'us_answers[' . $id . ']';
|
||||
$fieldId = 'us-reg-q-' . $id;
|
||||
$required = $question->isRequired ? ' required' : '';
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($fieldId); ?>">
|
||||
<?php echo esc_html($question->label); ?>
|
||||
<?php if ($question->isRequired) : ?>
|
||||
<span class="us-required" aria-hidden="true">*</span>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<?php if ($question->fieldType === Question::FIELD_TEXTAREA) : ?>
|
||||
<textarea name="<?php echo esc_attr($name); ?>" id="<?php echo esc_attr($fieldId); ?>" rows="4"<?php echo $required; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- literal attribute string. ?>></textarea>
|
||||
<?php elseif ($question->fieldType === Question::FIELD_SELECT) : ?>
|
||||
<select name="<?php echo esc_attr($name); ?>" id="<?php echo esc_attr($fieldId); ?>"<?php echo $required; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- literal attribute string. ?>>
|
||||
<option value=""><?php esc_html_e('— Select —', 'unsupervised-schedular'); ?></option>
|
||||
<?php foreach ((array) $question->options as $option) : ?>
|
||||
<option value="<?php echo esc_attr((string) $option); ?>"><?php echo esc_html((string) $option); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php elseif ($question->fieldType === Question::FIELD_CHECKBOX) : ?>
|
||||
<input type="checkbox" name="<?php echo esc_attr($name); ?>" id="<?php echo esc_attr($fieldId); ?>" value="1"<?php echo $required; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- literal attribute string. ?>>
|
||||
<?php else : ?>
|
||||
<input type="text" name="<?php echo esc_attr($name); ?>" id="<?php echo esc_attr($fieldId); ?>"<?php echo $required; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- literal attribute string. ?>>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<?php
|
||||
};
|
||||
?>
|
||||
<div class="us-register-form">
|
||||
<?php if ($successType === 'confirm') : ?>
|
||||
@@ -102,6 +70,48 @@ $renderQuestionField = static function (Question $question): void {
|
||||
<input type="password" name="password" id="us-reg-pass" autocomplete="new-password" minlength="8" required>
|
||||
</p>
|
||||
|
||||
<fieldset class="us-guardian">
|
||||
<legend><?php esc_html_e('Who are you registering?', 'unsupervised-schedular'); ?></legend>
|
||||
<p>
|
||||
<label>
|
||||
<input type="checkbox" name="us_is_guardian" id="us-is-guardian" value="1">
|
||||
<?php esc_html_e("I'm registering as a parent or guardian, for one or more children", 'unsupervised-schedular'); ?>
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<?php /* Revealed by the checkbox; without JS it is simply always visible. */ ?>
|
||||
<div class="us-children" id="us-children">
|
||||
<p class="us-children-intro"><?php esc_html_e('Add each child you will be booking lessons for. They do not need their own login — you book and pay for them from this account.', 'unsupervised-schedular'); ?></p>
|
||||
|
||||
<?php /* The first block is the template the "Add another child" button clones. */ ?>
|
||||
<div class="us-child" data-child-index="0">
|
||||
<p>
|
||||
<label for="us-child-0-name"><?php esc_html_e("Child's name", 'unsupervised-schedular'); ?></label>
|
||||
<input type="text" name="children[0][name]" id="us-child-0-name">
|
||||
</p>
|
||||
<p>
|
||||
<label for="us-child-0-dob"><?php esc_html_e('Date of birth', 'unsupervised-schedular'); ?></label>
|
||||
<input type="date" name="children[0][dob]" id="us-child-0-dob">
|
||||
</p>
|
||||
<?php foreach ($accountQuestions as $question) : ?>
|
||||
<?php
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- QuestionField::render() escapes every interpolated value.
|
||||
echo QuestionField::render(
|
||||
$question,
|
||||
'children[0][answers][' . (int) $question->id . ']',
|
||||
'us-child-0-q-' . (int) $question->id,
|
||||
enforceRequired: false
|
||||
);
|
||||
?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<button type="button" class="us-add-child"><?php esc_html_e('Add another child', 'unsupervised-schedular'); ?></button>
|
||||
</p>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<?php if (! empty($policyForms)) : ?>
|
||||
<fieldset class="us-policies">
|
||||
<legend><?php esc_html_e('Policies', 'unsupervised-schedular'); ?></legend>
|
||||
@@ -124,6 +134,17 @@ $renderQuestionField = static function (Question $question): void {
|
||||
<?php if ($hasQuestions) : ?>
|
||||
<p>
|
||||
<button type="button" class="us-reg-next"><?php esc_html_e('Next', 'unsupervised-schedular'); ?></button>
|
||||
<?php
|
||||
/*
|
||||
* In parent/guardian mode the questions are asked per child,
|
||||
* up in the children section, so step two has nothing left to
|
||||
* ask and "Next" leads nowhere. This submit takes its place —
|
||||
* hidden until the guardian box is ticked (and never shown at
|
||||
* all without JS, where both steps are visible anyway and the
|
||||
* step-two submit does the job).
|
||||
*/
|
||||
?>
|
||||
<input type="submit" name="us_register" class="us-reg-submit-early" hidden value="<?php esc_attr_e('Create Account', 'unsupervised-schedular'); ?>">
|
||||
</p>
|
||||
<?php else : ?>
|
||||
<p>
|
||||
@@ -137,7 +158,10 @@ $renderQuestionField = static function (Question $question): void {
|
||||
<fieldset class="us-reg-questions">
|
||||
<legend><?php esc_html_e('Registration information', 'unsupervised-schedular'); ?></legend>
|
||||
<?php foreach ($accountQuestions as $question) : ?>
|
||||
<?php $renderQuestionField($question); ?>
|
||||
<?php
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- QuestionField::render() escapes every interpolated value.
|
||||
echo QuestionField::render($question, 'us_answers[' . (int) $question->id . ']', 'us-reg-q-' . (int) $question->id);
|
||||
?>
|
||||
<?php endforeach; ?>
|
||||
</fieldset>
|
||||
<p>
|
||||
|
||||
Reference in New Issue
Block a user