Files
unsupervised-scheduler/templates/admin/questions.php
T
thatguygriffandClaude Opus 4.8 721c4be1d6
CI / Tests (PHP 8.1) (pull_request) Successful in 49s
CI / Tests (PHP 8.2) (pull_request) Successful in 49s
CI / No Debug Code (pull_request) Successful in 2s
CI / Coding Standards (pull_request) Successful in 2m47s
CI / PHPStan (pull_request) Successful in 3m16s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m41s
CI / Build Plugin Zip (pull_request) Skipped
Fix field-length saves, student wp-admin access, and empty instructor picker
Three bug fixes for the 1.2.1 section:

- Fixed-size fields (question labels, offering titles/notes/e-transfer
  email, policy titles/slugs) no longer silently fail to save when the
  value exceeds its column length. The REST endpoints reject over-long
  values with a 400, the admin controllers refuse to insert them, and the
  form inputs carry a maxlength so the browser blocks over-long entry.
  Limits are MAX_* constants on the value objects, kept in lockstep with
  the schema columns.

- Students are kept out of wp-admin entirely. New StudentAdminGuard
  redirects front-end-only users (no back-office capability) away from the
  dashboard and hides the admin bar for them, while administrators, studio
  admins, and instructors keep full access.

- The Add/Edit Offering instructor picker now includes WordPress
  administrators when they act as instructors (the default single-account
  setup), so a solo studio owner is selectable instead of the dropdown
  being empty.

composer test (618), composer lint, composer cs all pass.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-24 20:22:04 -03:00

125 lines
7.4 KiB
PHP

<?php
declare(strict_types=1);
use Unsupervised\Schedular\Registration\Question;
if (! defined('ABSPATH')) {
exit;
}
/**
* @var list<\Unsupervised\Schedular\Offering\Offering> $offeringList
* @var \Unsupervised\Schedular\Offering\Offering|null $selectedOffering
* @var bool $accountScope Whether the studio-wide account-signup questions are selected.
* @var bool $manageAll Whether the current user is a studio admin (may edit account questions).
* @var list<\Unsupervised\Schedular\Registration\Question>|null $questions
*/
?>
<div class="wrap">
<h1><?php esc_html_e('Registration Questions', 'unsupervised-schedular'); ?></h1>
<form method="get">
<input type="hidden" name="page" value="us-questions">
<label for="offering_id"><?php esc_html_e('Questions for', 'unsupervised-schedular'); ?></label>
<select name="offering_id" id="offering_id" onchange="this.form.submit()">
<option value="0"><?php esc_html_e('— Select —', 'unsupervised-schedular'); ?></option>
<?php if ($manageAll) : ?>
<option value="<?php echo esc_attr(Question::SCOPE_ACCOUNT); ?>" <?php selected($accountScope); ?>>
<?php esc_html_e('Account signup (all registrations)', 'unsupervised-schedular'); ?>
</option>
<?php endif; ?>
<?php foreach ($offeringList as $offering) : ?>
<option value="<?php echo esc_attr((string) $offering->id); ?>" <?php selected(! $accountScope && $selectedOffering && $selectedOffering->id === $offering->id); ?>>
<?php echo esc_html($offering->title); ?>
</option>
<?php endforeach; ?>
</select>
</form>
<?php if (! $accountScope && null === $selectedOffering) : ?>
<p><?php esc_html_e('Choose an offering to manage its intake questions, or "Account signup" for the questions every new student answers when registering.', 'unsupervised-schedular'); ?></p>
<?php else : ?>
<?php if ($accountScope) : ?>
<h2><?php esc_html_e('Account signup questions', 'unsupervised-schedular'); ?></h2>
<p><?php esc_html_e('Every new student answers these required-if-marked questions as a second step after choosing their name and password.', 'unsupervised-schedular'); ?></p>
<?php else : ?>
<h2><?php echo esc_html(sprintf(/* translators: %s: offering title */ __('Questions for "%s"', 'unsupervised-schedular'), $selectedOffering->title)); ?></h2>
<?php endif; ?>
<h3><?php esc_html_e('Add Question', 'unsupervised-schedular'); ?></h3>
<form method="post">
<?php wp_nonce_field('usc_question_action'); ?>
<input type="hidden" name="usc_action" value="add">
<table class="form-table">
<tr>
<th><label for="label"><?php esc_html_e('Question', 'unsupervised-schedular'); ?></label></th>
<td><input type="text" name="label" id="label" class="regular-text" maxlength="<?php echo esc_attr((string) Question::MAX_LABEL_LENGTH); ?>" required></td>
</tr>
<tr>
<th><label for="field_type"><?php esc_html_e('Field type', 'unsupervised-schedular'); ?></label></th>
<td>
<select name="field_type" id="field_type">
<option value="<?php echo esc_attr(Question::FIELD_TEXT); ?>"><?php esc_html_e('Text', 'unsupervised-schedular'); ?></option>
<option value="<?php echo esc_attr(Question::FIELD_TEXTAREA); ?>"><?php esc_html_e('Paragraph', 'unsupervised-schedular'); ?></option>
<option value="<?php echo esc_attr(Question::FIELD_SELECT); ?>"><?php esc_html_e('Dropdown', 'unsupervised-schedular'); ?></option>
<option value="<?php echo esc_attr(Question::FIELD_CHECKBOX); ?>"><?php esc_html_e('Checkbox', 'unsupervised-schedular'); ?></option>
</select>
</td>
</tr>
<tr>
<th><label for="options"><?php esc_html_e('Options', 'unsupervised-schedular'); ?></label></th>
<td>
<textarea name="options" id="options" rows="4" class="large-text" placeholder="<?php esc_attr_e('One choice per line (dropdown only)', 'unsupervised-schedular'); ?>"></textarea>
</td>
</tr>
<tr>
<th><label for="sort_order"><?php esc_html_e('Sort order', 'unsupervised-schedular'); ?></label></th>
<td><input type="number" name="sort_order" id="sort_order" min="0" step="1" value="0"></td>
</tr>
<tr>
<th><?php esc_html_e('Required', 'unsupervised-schedular'); ?></th>
<td><label><input type="checkbox" name="is_required" value="1"> <?php esc_html_e('Registrant must answer', 'unsupervised-schedular'); ?></label></td>
</tr>
</table>
<?php submit_button(esc_html__('Add Question', 'unsupervised-schedular')); ?>
</form>
<h3><?php esc_html_e('Current Questions', 'unsupervised-schedular'); ?></h3>
<?php if (empty($questions)) : ?>
<p><?php esc_html_e('No questions configured yet.', 'unsupervised-schedular'); ?></p>
<?php else : ?>
<table class="wp-list-table widefat fixed striped">
<thead>
<tr>
<th><?php esc_html_e('Order', 'unsupervised-schedular'); ?></th>
<th><?php esc_html_e('Question', 'unsupervised-schedular'); ?></th>
<th><?php esc_html_e('Type', 'unsupervised-schedular'); ?></th>
<th><?php esc_html_e('Required', 'unsupervised-schedular'); ?></th>
<th><?php esc_html_e('Actions', 'unsupervised-schedular'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($questions as $question) : ?>
<tr>
<td><?php echo esc_html((string) $question->sortOrder); ?></td>
<td><?php echo esc_html($question->label); ?></td>
<td><?php echo esc_html($question->fieldType); ?></td>
<td><?php echo $question->isRequired ? esc_html__('Yes', 'unsupervised-schedular') : esc_html__('No', 'unsupervised-schedular'); ?></td>
<td>
<form method="post" style="display:inline;">
<?php wp_nonce_field('usc_question_action'); ?>
<input type="hidden" name="usc_action" value="delete">
<input type="hidden" name="question_id" value="<?php echo esc_attr((string) $question->id); ?>">
<button type="submit" class="button button-small button-link-delete">
<?php esc_html_e('Delete', 'unsupervised-schedular'); ?>
</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<?php endif; ?>
</div>