feat: Align question types in Manage Questions template
This commit is contained in:
parent
509288f087
commit
c0687c652b
1 changed files with 16 additions and 11 deletions
|
|
@ -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 );
|
// 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)
|
// Define available question types (Ideally, fetch this dynamically from the plugin)
|
||||||
$question_types = array(
|
$question_types = [
|
||||||
'multiple-choice' => __( 'Multiple Choice', 'quiztech' ),
|
'text' => \__( 'Text (Single Line)', 'quiztech' ),
|
||||||
'true-false' => __( 'True/False', 'quiztech' ),
|
'textarea' => \__( 'Text Area (Multi-line)', 'quiztech' ),
|
||||||
'short-answer' => __( 'Short Answer', 'quiztech' ),
|
'multiple-choice' => \__( 'Multiple Choice (Single Answer)', 'quiztech' ),
|
||||||
// Add other types as needed
|
'checkbox' => \__( 'Checkboxes (Multiple Answers)', 'quiztech' ),
|
||||||
);
|
'numeric' => \__( 'Numeric', 'quiztech' ),
|
||||||
|
];
|
||||||
|
// TODO: Refactor this to use a plugin helper function or filter to avoid duplication.
|
||||||
|
|
||||||
get_header(); ?>
|
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;">
|
<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>
|
<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">
|
<form id="question-form">
|
||||||
<?php wp_nonce_field( 'quiztech_save_question_action', 'quiztech_question_nonce' ); ?>
|
<?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;">
|
<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>
|
<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>
|
<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>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
@ -87,6 +89,7 @@ get_header(); ?>
|
||||||
'hierarchical' => 1,
|
'hierarchical' => 1,
|
||||||
) );
|
) );
|
||||||
?>
|
?>
|
||||||
|
</p> <?php // Closing </p> was missing here ?>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<label for="quiztech-question-points"><?php esc_html_e( 'Question Points:', 'quiztech' ); ?></label><br>
|
<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>
|
<small><?php esc_html_e('Points awarded for a correct answer.', 'quiztech'); ?></small>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</p>
|
<?php // Removed extra closing </p> tag from line 97 of original ?>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<button type="submit" class="button button-primary"><?php esc_html_e( 'Save Question', 'quiztech' ); ?></button>
|
<button type="submit" class="button button-primary"><?php esc_html_e( 'Save Question', 'quiztech' ); ?></button>
|
||||||
|
|
@ -131,6 +134,7 @@ get_header(); ?>
|
||||||
<?php
|
<?php
|
||||||
$question_id = get_the_ID();
|
$question_id = get_the_ID();
|
||||||
$q_type_value = get_post_meta( $question_id, '_quiztech_question_type', true );
|
$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 );
|
$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' );
|
$terms = get_the_terms( $question_id, 'quiztech_category' );
|
||||||
$category_name = ! empty( $terms ) && ! is_wp_error( $terms ) ? esc_html( $terms[0]->name ) : __( 'N/A', 'quiztech' );
|
$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) ---
|
// --- Type Change (Show/Hide Options) ---
|
||||||
$('#quiztech-question-type').on('change', function() {
|
$('#quiztech-question-type').on('change', function() {
|
||||||
const type = $(this).val();
|
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();
|
$('#quiztech-question-options-wrapper').show();
|
||||||
} else {
|
} else {
|
||||||
$('#quiztech-question-options-wrapper').hide();
|
$('#quiztech-question-options-wrapper').hide();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue