Ask some registration questions of students only
CI / Tests (PHP 8.2) (pull_request) Successful in 58s
CI / Tests (PHP 8.1) (pull_request) Successful in 58s
CI / No Debug Code (pull_request) Successful in 3s
CI / Coding Standards (pull_request) Successful in 2m53s
CI / PHPStan (pull_request) Successful in 3m0s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m42s
CI / Build Plugin Zip (pull_request) Skipped

Every account-signup question was asked of everybody who registered, on the
same terms: "school and grade" had to be put to an adult signing themselves
up, and a question a studio needed answered for each student could only be
made required by demanding it of everyone.

A question now carries an audience — everyone, or only the students someone
registers on behalf of — and its own required flag for each side, so optional
for you and required for every student you enrol is expressible. Both settings
are account-scope only: an offering asks its questions once, about the student
being booked, so there is no second audience to differ from, and an offering
question mirrors its single "required" into both columns.

Every caller reads askedOfSelf()/isRequiredForSelf()/isRequiredForChild()
rather than the raw flags, so a students-only question can neither block the
account holder nor have an answer filed against them by a crafted post. The
family screen, which only ever adds a student, is held to the students' rule.

is_required_child arrives from dbDelta defaulting to 0, which would quietly
stop every existing required question being required of the students a
guardian registers — the case it most likely existed for. A one-time backfill
copies is_required across, guarded by its own option so a question later made
optional for students stays that way.

Closes #163

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
2026-07-30 13:51:52 -03:00
co-authored by Claude Opus 5
parent 84378e856b
commit 434fe801ba
20 changed files with 809 additions and 85 deletions
+6 -1
View File
@@ -94,7 +94,12 @@ if (! defined('ABSPATH')) {
<?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);
echo QuestionField::render(
$question,
'us_answers[' . (int) $question->id . ']',
'us-family-q-' . (int) $question->id,
isRequired: $question->isRequiredForChild()
);
?>
<?php endforeach; ?>
</fieldset>
+16 -3
View File
@@ -22,7 +22,7 @@ if (! defined('ABSPATH')) {
* @var string $loginUrl Where the post-confirmation sign-in link points.
* @var string $error
* @var list<array{policy: \Unsupervised\Schedular\Policy\Policy, version: \Unsupervised\Schedular\Policy\PolicyVersion}> $policyForms
* @var list<Question> $accountQuestions Studio-wide questions, asked of every student — the account holder included when they are one.
* @var list<Question> $accountQuestions Studio-wide questions, asked of every student being registered — the account holder included when they are one, unless the question is for students only.
*/
?>
@@ -121,9 +121,21 @@ if (! defined('ABSPATH')) {
<input type="number" name="birth_year" id="us-reg-birth-year" aria-required="true" required min="1900" max="<?php echo esc_attr(current_time('Y')); ?>" step="1" inputmode="numeric" autocomplete="bday-year" placeholder="<?php esc_attr_e('YYYY', 'unsupervised-schedular'); ?>">
</p>
<?php foreach ($accountQuestions as $question) : ?>
<?php
// A "students only" question describes a child being registered,
// so it is never put to the account holder about themselves.
if (! $question->askedOfSelf()) {
continue;
}
?>
<?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);
echo QuestionField::render(
$question,
'us_answers[' . (int) $question->id . ']',
'us-reg-q-' . (int) $question->id,
isRequired: $question->isRequiredForSelf()
);
?>
<?php endforeach; ?>
</fieldset>
@@ -150,7 +162,8 @@ if (! defined('ABSPATH')) {
$question,
'children[0][answers][' . (int) $question->id . ']',
'us-child-0-q-' . (int) $question->id,
enforceRequired: false
enforceRequired: false,
isRequired: $question->isRequiredForChild()
);
?>
<?php endforeach; ?>