Let parents register once and book for their children
CI / Tests (PHP 8.2) (pull_request) Successful in 42s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m45s
CI / Build Plugin Zip (pull_request) Skipped
CI / Tests (PHP 8.1) (pull_request) Failing after 52s
CI / No Debug Code (pull_request) Successful in 2s
CI / PHPStan (pull_request) Successful in 2m52s
CI / Coding Standards (pull_request) Successful in 2m57s

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:
2026-07-29 16:00:34 -03:00
co-authored by Claude Opus 5
parent bbc85d88f1
commit 4a41ba96fb
71 changed files with 4193 additions and 190 deletions
+7 -1
View File
@@ -9,8 +9,14 @@ if (! defined('ABSPATH')) {
/** @var bool $showTypeFilter Whether the "Show Only" lesson-type filter is offered. */
/** @var bool $showBooking Whether the booking calendar is part of this embed. */
/** @var bool $showUpcoming Whether the student's upcoming-lessons panel is part of this embed. */
/** @var list<array{id: int, name: string, is_self: bool}> $students Who this account may book for — children first, the account holder last. */
// The booking script reads the list as JSON rather than rendering a <select>
// here: the picker belongs inside the booking form it builds, and it is the same
// list the group-classes script needs.
$studentsJson = wp_json_encode(array_values($students));
?>
<div id="us-booking-app" data-nonce="<?php echo esc_attr(wp_create_nonce('wp_rest')); ?>"<?php echo $lessonTypeId > 0 ? ' data-lesson-type="' . esc_attr((string) $lessonTypeId) . '"' : ''; ?><?php echo $showTypeFilter ? '' : ' data-type-filter="0"'; ?>>
<div id="us-booking-app" data-nonce="<?php echo esc_attr(wp_create_nonce('wp_rest')); ?>" data-students="<?php echo esc_attr(is_string($studentsJson) ? $studentsJson : '[]'); ?>"<?php echo $lessonTypeId > 0 ? ' data-lesson-type="' . esc_attr((string) $lessonTypeId) . '"' : ''; ?><?php echo $showTypeFilter ? '' : ' data-type-filter="0"'; ?>>
<?php if ($showUpcoming) : ?>
<div id="us-my-lessons"></div>
<?php endif; ?>
+107
View File
@@ -0,0 +1,107 @@
<?php
declare(strict_types=1);
use Unsupervised\Schedular\Registration\QuestionField;
if (! defined('ABSPATH')) {
exit;
}
/**
* @var list<array{id: int, name: string, date_of_birth: string, relationship: string}> $children
* @var list<\Unsupervised\Schedular\Registration\Question> $questions Account-scope questions, asked once per child.
* @var string $error Validation error from the last submission, if any.
* @var string $notice Confirmation of a completed add/edit/remove, if any.
* @var int $editingId Child whose row is open for editing; 0 for none.
*/
?>
<div class="us-family">
<h3><?php esc_html_e('Your family', 'unsupervised-schedular'); ?></h3>
<?php if ($notice !== '') : ?>
<p class="us-success"><?php echo esc_html($notice); ?></p>
<?php endif; ?>
<?php if ($error !== '') : ?>
<p class="us-error" role="alert"><?php echo esc_html($error); ?></p>
<?php endif; ?>
<?php if (empty($children)) : ?>
<p><?php esc_html_e('You have not added any children yet. Add one below to start booking lessons for them.', 'unsupervised-schedular'); ?></p>
<?php else : ?>
<ul class="us-family-list">
<?php foreach ($children as $child) : ?>
<li class="us-family-child">
<?php if ($editingId === $child['id']) : ?>
<form method="post" action="" class="us-family-edit">
<?php wp_nonce_field('us_family'); ?>
<input type="hidden" name="us_family_action" value="edit">
<input type="hidden" name="child_id" value="<?php echo esc_attr((string) $child['id']); ?>">
<p>
<label for="us-edit-name-<?php echo esc_attr((string) $child['id']); ?>"><?php esc_html_e('Name', 'unsupervised-schedular'); ?></label>
<input type="text" name="child_name" id="us-edit-name-<?php echo esc_attr((string) $child['id']); ?>" value="<?php echo esc_attr($child['name']); ?>" required>
</p>
<p>
<label for="us-edit-dob-<?php echo esc_attr((string) $child['id']); ?>"><?php esc_html_e('Date of birth', 'unsupervised-schedular'); ?></label>
<input type="date" name="child_dob" id="us-edit-dob-<?php echo esc_attr((string) $child['id']); ?>" value="<?php echo esc_attr($child['date_of_birth']); ?>">
</p>
<p>
<button type="submit"><?php esc_html_e('Save', 'unsupervised-schedular'); ?></button>
<a href="<?php echo esc_url((string) get_permalink()); ?>"><?php esc_html_e('Cancel', 'unsupervised-schedular'); ?></a>
</p>
</form>
<?php else : ?>
<span class="us-family-child-name"><?php echo esc_html($child['name']); ?></span>
<?php if ($child['date_of_birth'] !== '') : ?>
<span class="us-family-child-dob"><?php echo esc_html($child['date_of_birth']); ?></span>
<?php endif; ?>
<span class="us-family-child-actions">
<a href="<?php echo esc_url(add_query_arg('us_edit_child', $child['id'], (string) get_permalink())); ?>"><?php esc_html_e('Edit', 'unsupervised-schedular'); ?></a>
<form method="post" action="" class="us-family-remove">
<?php wp_nonce_field('us_family'); ?>
<input type="hidden" name="us_family_action" value="remove">
<input type="hidden" name="child_id" value="<?php echo esc_attr((string) $child['id']); ?>">
<button type="submit"><?php esc_html_e('Remove', 'unsupervised-schedular'); ?></button>
</form>
</span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<form method="post" action="" class="us-family-add">
<?php wp_nonce_field('us_family'); ?>
<input type="hidden" name="us_family_action" value="add">
<h4><?php esc_html_e('Add a child', 'unsupervised-schedular'); ?></h4>
<p>
<label for="us-child-name"><?php esc_html_e('Name', 'unsupervised-schedular'); ?></label>
<input type="text" name="child_name" id="us-child-name" required>
</p>
<p>
<label for="us-child-dob"><?php esc_html_e('Date of birth', 'unsupervised-schedular'); ?></label>
<input type="date" name="child_dob" id="us-child-dob">
</p>
<p>
<label for="us-child-relationship"><?php esc_html_e('Your relationship to them', 'unsupervised-schedular'); ?></label>
<input type="text" name="child_relationship" id="us-child-relationship" placeholder="<?php esc_attr_e('Parent', 'unsupervised-schedular'); ?>">
</p>
<?php if (! empty($questions)) : ?>
<fieldset class="us-reg-questions">
<legend><?php esc_html_e('About this child', 'unsupervised-schedular'); ?></legend>
<?php foreach ($questions as $question) : ?>
<?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- QuestionField::render() escapes every interpolated value.
echo QuestionField::render($question, 'us_answers[' . (int) $question->id . ']', 'us-family-q-' . (int) $question->id);
?>
<?php endforeach; ?>
</fieldset>
<?php endif; ?>
<p>
<button type="submit"><?php esc_html_e('Add child', 'unsupervised-schedular'); ?></button>
</p>
</form>
</div>
+6 -1
View File
@@ -6,8 +6,13 @@ if (! defined('ABSPATH')) {
}
/** @var int $offeringId Offering id when the page is restricted to a single class; 0 for the full catalog. */
/** @var list<array{id: int, name: string, is_self: bool}> $students Who this account may enrol — children first, the account holder last. */
// The enrolment script reads the list as JSON, so the picker can be built inside
// the enrolment form it renders.
$studentsJson = wp_json_encode(array_values($students));
?>
<div id="us-group-app"<?php echo $offeringId > 0 ? ' data-offering="' . esc_attr((string) $offeringId) . '"' : ''; ?>>
<div id="us-group-app" data-students="<?php echo esc_attr(is_string($studentsJson) ? $studentsJson : '[]'); ?>"<?php echo $offeringId > 0 ? ' data-offering="' . esc_attr((string) $offeringId) . '"' : ''; ?>>
<div id="us-group-list">
<p><?php esc_html_e('Loading group classes…', 'unsupervised-schedular'); ?></p>
</div>
+58 -34
View File
@@ -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>