feat: Align question types in Manage Questions template

This commit is contained in:
Ruben Ramirez 2025-04-04 08:15:06 -05:00
parent 509288f087
commit c0687c652b

View file

@ -19,13 +19,15 @@ if ( ! is_user_logged_in() || ! current_user_can( $required_capability ) ) {
// wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'quiztech' ), 403 );
}
// Define available question types (should ideally come from a central config or helper)
$question_types = array(
'multiple-choice' => __( 'Multiple Choice', 'quiztech' ),
'true-false' => __( 'True/False', 'quiztech' ),
'short-answer' => __( 'Short Answer', 'quiztech' ),
// Add other types as needed
);
// Define available question types (Ideally, fetch this dynamically from the plugin)
$question_types = [
'text' => \__( 'Text (Single Line)', 'quiztech' ),
'textarea' => \__( 'Text Area (Multi-line)', 'quiztech' ),
'multiple-choice' => \__( 'Multiple Choice (Single Answer)', 'quiztech' ),
'checkbox' => \__( 'Checkboxes (Multiple Answers)', 'quiztech' ),
'numeric' => \__( 'Numeric', 'quiztech' ),
];
// TODO: Refactor this to use a plugin helper function or filter to avoid duplication.
get_header(); ?>
@ -43,7 +45,7 @@ get_header(); ?>
<div id="quiztech-add-edit-question-form" style="display: none; border: 1px solid #ccc; padding: 15px; margin-bottom: 20px;">
<h3><?php esc_html_e( 'Add/Edit Question', 'quiztech' ); ?></h3>
<p style="font-weight: bold;"><?php esc_html_e( 'Credits:', 'quiztech' ); ?> 3</p>
<p style="font-weight: bold;"><?php esc_html_e( 'Credits:', 'quiztech' ); ?> 3</p> <?php // TODO: Make credit cost dynamic ?>
<form id="question-form">
<?php wp_nonce_field( 'quiztech_save_question_action', 'quiztech_question_nonce' ); ?>
@ -72,7 +74,7 @@ get_header(); ?>
<p id="quiztech-question-options-wrapper" style="display: none;">
<label for="quiztech-question-options"><?php esc_html_e( 'Options (one per line, mark correct with *):', 'quiztech' ); ?></label><br>
<textarea id="quiztech-question-options" name="question_options" class="widefat" rows="5"></textarea>
<small><?php esc_html_e('Example: Option A*'); ?></small>
<small><?php esc_html_e('Example: Option A*'); ?></small> <?php // TODO: Clarify correct answer format for checkboxes ?>
</p>
<p>
@ -87,6 +89,7 @@ get_header(); ?>
'hierarchical' => 1,
) );
?>
</p> <?php // Closing </p> was missing here ?>
<p>
<label for="quiztech-question-points"><?php esc_html_e( 'Question Points:', 'quiztech' ); ?></label><br>
@ -94,7 +97,7 @@ get_header(); ?>
<small><?php esc_html_e('Points awarded for a correct answer.', 'quiztech'); ?></small>
</p>
</p>
<?php // Removed extra closing </p> tag from line 97 of original ?>
<p>
<button type="submit" class="button button-primary"><?php esc_html_e( 'Save Question', 'quiztech' ); ?></button>
@ -131,6 +134,7 @@ get_header(); ?>
<?php
$question_id = get_the_ID();
$q_type_value = get_post_meta( $question_id, '_quiztech_question_type', true );
// Use the updated $question_types array for display
$q_type_label = isset( $question_types[ $q_type_value ] ) ? $question_types[ $q_type_value ] : esc_html( $q_type_value );
$terms = get_the_terms( $question_id, 'quiztech_category' );
$category_name = ! empty( $terms ) && ! is_wp_error( $terms ) ? esc_html( $terms[0]->name ) : __( 'N/A', 'quiztech' );
@ -205,7 +209,8 @@ get_header(); ?>
// --- Type Change (Show/Hide Options) ---
$('#quiztech-question-type').on('change', function() {
const type = $(this).val();
if (type === 'multiple-choice' || type === 'true-false') {
// CORRECTED: Show options for multiple-choice and checkbox
if (type === 'multiple-choice' || type === 'checkbox') {
$('#quiztech-question-options-wrapper').show();
} else {
$('#quiztech-question-options-wrapper').hide();