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]>
108 lines
5.9 KiB
PHP
108 lines
5.9 KiB
PHP
<?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>
|