Fix field-length saves, student wp-admin access, and empty instructor picker
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
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
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]>
This commit is contained in:
@@ -12,6 +12,9 @@ class Question {
|
||||
public const FIELD_SELECT = 'select';
|
||||
public const FIELD_CHECKBOX = 'checkbox';
|
||||
|
||||
/** Maximum length of a question label, matching the `label` VARCHAR(255) column. */
|
||||
public const MAX_LABEL_LENGTH = 255;
|
||||
|
||||
/** Question is scoped to a single offering, asked at booking/enrolment time. */
|
||||
public const SCOPE_OFFERING = 'offering';
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ class QuestionController {
|
||||
$label = sanitize_text_field( Val::string( wp_unslash( $_POST['label'] ?? '' ) ) );
|
||||
$fieldType = sanitize_key( Val::string( wp_unslash( $_POST['field_type'] ?? Question::FIELD_TEXT ) ) );
|
||||
|
||||
if ( '' === $label || ! in_array( $fieldType, Question::VALID_FIELD_TYPES, true ) ) {
|
||||
if ( '' === $label || mb_strlen( $label ) > Question::MAX_LABEL_LENGTH || ! in_array( $fieldType, Question::VALID_FIELD_TYPES, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,9 @@ class QuestionEndpoint {
|
||||
if ( '' === $label ) {
|
||||
return $this->invalid( __( 'A question label is required.', 'unsupervised-schedular' ) );
|
||||
}
|
||||
if ( mb_strlen( $label ) > Question::MAX_LABEL_LENGTH ) {
|
||||
return $this->invalid( $this->tooLongMessage( __( 'question', 'unsupervised-schedular' ), Question::MAX_LABEL_LENGTH ) );
|
||||
}
|
||||
|
||||
$fieldType = Val::string( $request->get_param( 'field_type' ) ?? Question::FIELD_TEXT );
|
||||
if ( ! in_array( $fieldType, Question::VALID_FIELD_TYPES, true ) ) {
|
||||
@@ -118,9 +121,17 @@ class QuestionEndpoint {
|
||||
return $this->invalid( __( 'Invalid field type.', 'unsupervised-schedular' ) );
|
||||
}
|
||||
|
||||
$label = $request->has_param( 'label' ) ? sanitize_text_field( Val::string( $request->get_param( 'label' ) ) ) : $existing->label;
|
||||
if ( '' === $label ) {
|
||||
return $this->invalid( __( 'A question label is required.', 'unsupervised-schedular' ) );
|
||||
}
|
||||
if ( mb_strlen( $label ) > Question::MAX_LABEL_LENGTH ) {
|
||||
return $this->invalid( $this->tooLongMessage( __( 'question', 'unsupervised-schedular' ), Question::MAX_LABEL_LENGTH ) );
|
||||
}
|
||||
|
||||
$question = new Question(
|
||||
offeringId: $existing->offeringId,
|
||||
label: $request->has_param( 'label' ) ? sanitize_text_field( Val::string( $request->get_param( 'label' ) ) ) : $existing->label,
|
||||
label: $label,
|
||||
fieldType: $fieldType,
|
||||
options: $request->has_param( 'options' ) ? $this->sanitizeOptions( $request->get_param( 'options' ) ) : $existing->options,
|
||||
isRequired: $request->has_param( 'is_required' ) ? (bool) $request->get_param( 'is_required' ) : $existing->isRequired,
|
||||
@@ -217,4 +228,16 @@ class QuestionEndpoint {
|
||||
private function invalid( string $message ): \WP_Error {
|
||||
return new \WP_Error( 'invalid_question', $message, [ 'status' => 400 ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a uniform "too long" validation message for a named field.
|
||||
*/
|
||||
private function tooLongMessage( string $field, int $max ): string {
|
||||
return sprintf(
|
||||
/* translators: 1: field name, 2: maximum character count. */
|
||||
__( 'The %1$s must be %2$d characters or fewer.', 'unsupervised-schedular' ),
|
||||
$field,
|
||||
$max
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user