| |
| <?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| add_action( 'show_user_profile', 'kic_add_scholar_student_meta_fields', 11 );
|
| add_action( 'edit_user_profile', 'kic_add_scholar_student_meta_fields', 11 );
|
|
|
| function kic_add_scholar_student_meta_fields( $user ) {
|
|
|
| wp_nonce_field( 'kic_scholar_meta_update', 'kic_scholar_meta_nonce' );
|
| ?>
|
|
|
| <!-- SCHOLAR/STUDENT SPECIFIC FIELDS - COLLAPSIBLE SECTION -->
|
| <div id="kic-scholar-fields-wrapper" class="postbox" style="margin-top: 40px;">
|
| <div class="postbox-header" style="cursor: pointer;">
|
| <h2 class="hndle" style="margin: 0; padding: 12px; border-bottom: 2px solid #d63638;">
|
| <span class="dashicons dashicons-arrow-down-alt2" style="margin-right: 8px;"></span>
|
| Scholar/Student Information
|
| </h2>
|
| </div>
|
| <div class="inside" id="kic-scholar-fields-content">
|
| <p style="background: #fcf0f1; border-left: 4px solid #d63638; padding: 10px; margin: 10px 0 20px;">
|
| <strong>Note:</strong> These fields are for scholars/students participating in programs. All fields are optional.
|
| </p>
|
|
|
| <h3>School Information</h3>
|
| <table class="form-table" role="presentation">
|
| <tr>
|
| <th><label for="kic_school_name">School Name</label></th>
|
| <td>
|
| <input type="text"
|
| name="kic_school_name"
|
| id="kic_school_name"
|
| value="<?php echo esc_attr( get_user_meta( $user->ID, 'kic_school_name', true ) ); ?>"
|
| class="regular-text" />
|
| <p class="description">Current school (optional)</p>
|
| </td>
|
| </tr>
|
| <tr>
|
| <th><label for="kic_school_grade">Grade Level</label></th>
|
| <td>
|
| <input type="text"
|
| name="kic_school_grade"
|
| id="kic_school_grade"
|
| value="<?php echo esc_attr( get_user_meta( $user->ID, 'kic_school_grade', true ) ); ?>"
|
| class="regular-text"
|
| placeholder="e.g., 9th, 10th, 11th, 12th"
|
| style="width: 200px;" />
|
| <p class="description">Current grade level (optional)</p>
|
| </td>
|
| </tr>
|
| </table>
|
|
|
| <h3>Household Information</h3>
|
| <table class="form-table" role="presentation">
|
| <tr>
|
| <th><label for="kic_household_size">Household Size</label></th>
|
| <td>
|
| <input type="number"
|
| name="kic_household_size"
|
| id="kic_household_size"
|
| value="<?php echo esc_attr( get_user_meta( $user->ID, 'kic_household_size', true ) ); ?>"
|
| min="1"
|
| style="width: 100px;" />
|
| <p class="description">Number of people in household (optional)</p>
|
| </td>
|
| </tr>
|
| <tr>
|
| <th><label for="kic_annual_income">Annual Household Income</label></th>
|
| <td>
|
| <select name="kic_annual_income" id="kic_annual_income" class="regular-text">
|
| <?php
|
| $income = get_user_meta( $user->ID, 'kic_annual_income', true );
|
| ?>
|
| <option value="">-- Select Income Range --</option>
|
| <option value="0-25000" <?php selected( $income, '0-25000' ); ?>>$0 - $25,000</option>
|
| <option value="25001-35000" <?php selected( $income, '25001-35000' ); ?>>$25,001 - $35,000</option>
|
| <option value="35001-50000" <?php selected( $income, '35001-50000' ); ?>>$35,001 - $50,000</option>
|
| <option value="50001-75000" <?php selected( $income, '50001-75000' ); ?>>$50,001 - $75,000</option>
|
| <option value="75001-100000" <?php selected( $income, '75001-100000' ); ?>>$75,001 - $100,000</option>
|
| <option value="100001+" <?php selected( $income, '100001+' ); ?>>$100,001+</option>
|
| </select>
|
| <p class="description">For program eligibility (optional)</p>
|
| </td>
|
| </tr>
|
| </table>
|
|
|
| <h3>Technology Access</h3>
|
| <table class="form-table" role="presentation">
|
| <tr>
|
| <th><label for="kic_internet_access">Internet Access</label></th>
|
| <td>
|
| <select name="kic_internet_access" id="kic_internet_access" class="regular-text">
|
| <?php
|
| $internet = get_user_meta( $user->ID, 'kic_internet_access', true );
|
| ?>
|
| <option value="">-- Select --</option>
|
| <option value="yes" <?php selected( $internet, 'yes' ); ?>>Yes - Consistent Access</option>
|
| <option value="inconsistent" <?php selected( $internet, 'inconsistent' ); ?>>Not Consistently</option>
|
| <option value="no" <?php selected( $internet, 'no' ); ?>>No</option>
|
| </select>
|
| <p class="description">For virtual programs (optional)</p>
|
| </td>
|
| </tr>
|
| <tr>
|
| <th><label for="kic_device_type">Primary Device Type</label></th>
|
| <td>
|
| <select name="kic_device_type" id="kic_device_type" class="regular-text">
|
| <?php
|
| $device = get_user_meta( $user->ID, 'kic_device_type', true );
|
| ?>
|
| <option value="">-- Select Device --</option>
|
| <option value="computer" <?php selected( $device, 'computer' ); ?>>Computer/Laptop</option>
|
| <option value="tablet" <?php selected( $device, 'tablet' ); ?>>Tablet/iPad</option>
|
| <option value="phone" <?php selected( $device, 'phone' ); ?>>Phone Only</option>
|
| <option value="none" <?php selected( $device, 'none' ); ?>>No Consistent Device</option>
|
| </select>
|
| <p class="description">For virtual learning (optional)</p>
|
| </td>
|
| </tr>
|
| </table>
|
|
|
| <h3>Program Preferences</h3>
|
| <table class="form-table" role="presentation">
|
| <tr>
|
| <th><label for="kic_activities_interest">Activities of Interest</label></th>
|
| <td>
|
| <input type="text"
|
| name="kic_activities_interest"
|
| id="kic_activities_interest"
|
| value="<?php echo esc_attr( get_user_meta( $user->ID, 'kic_activities_interest', true ) ); ?>"
|
| class="large-text"
|
| placeholder="e.g., Music, Art, Sports, STEM, Dance, etc." />
|
| <p class="description">Comma-separated interests (optional) - Form will provide options</p>
|
| </td>
|
| </tr>
|
| <tr>
|
| <th><label for="kic_transportation_needed">Transportation Needed</label></th>
|
| <td>
|
| <select name="kic_transportation_needed" id="kic_transportation_needed" class="regular-text">
|
| <?php
|
| $transport = get_user_meta( $user->ID, 'kic_transportation_needed', true );
|
| ?>
|
| <option value="">-- Select --</option>
|
| <option value="yes" <?php selected( $transport, 'yes' ); ?>>Yes</option>
|
| <option value="no" <?php selected( $transport, 'no' ); ?>>No</option>
|
| </select>
|
| <p class="description">Optional</p>
|
| </td>
|
| </tr>
|
| <tr>
|
| <th><label for="kic_shirt_size">Shirt Size</label></th>
|
| <td>
|
| <select name="kic_shirt_size" id="kic_shirt_size" class="regular-text">
|
| <?php
|
| $shirt = get_user_meta( $user->ID, 'kic_shirt_size', true );
|
| ?>
|
| <option value="">-- Select Size --</option>
|
| <option value="YS" <?php selected( $shirt, 'YS' ); ?>>Youth Small</option>
|
| <option value="YM" <?php selected( $shirt, 'YM' ); ?>>Youth Medium</option>
|
| <option value="YL" <?php selected( $shirt, 'YL' ); ?>>Youth Large</option>
|
| <option value="AS" <?php selected( $shirt, 'AS' ); ?>>Adult Small</option>
|
| <option value="AM" <?php selected( $shirt, 'AM' ); ?>>Adult Medium</option>
|
| <option value="AL" <?php selected( $shirt, 'AL' ); ?>>Adult Large</option>
|
| <option value="AXL" <?php selected( $shirt, 'AXL' ); ?>>Adult XL</option>
|
| <option value="A2XL" <?php selected( $shirt, 'A2XL' ); ?>>Adult 2XL</option>
|
| <option value="A3XL" <?php selected( $shirt, 'A3XL' ); ?>>Adult 3XL</option>
|
| </select>
|
| <p class="description">For program materials (optional)</p>
|
| </td>
|
| </tr>
|
| </table>
|
|
|
| <h3>Goals (Self-Reported - Appendable)</h3>
|
| <p style="background: #d7f2ff; border-left: 4px solid #0073aa; padding: 10px; margin: 10px 0;">
|
| <strong>💡 Note:</strong> This field appends new goal entries with date stamps. Each time goals are updated via forms, the new entry is added with a timestamp.
|
| </p>
|
| <table class="form-table" role="presentation">
|
| <tr>
|
| <th><label for="kic_goals_log">Goals History Log</label></th>
|
| <td>
|
| <textarea name="kic_goals_log"
|
| id="kic_goals_log"
|
| rows="10"
|
| class="large-text"
|
| readonly
|
| style="background-color: #f6f7f7;"><?php echo esc_textarea( get_user_meta( $user->ID, 'kic_goals_log', true ) ); ?></textarea>
|
| <p class="description">READ ONLY - Complete history of goals with dates (updated via forms)</p>
|
| </td>
|
| </tr>
|
| <tr>
|
| <th><label for="kic_goals_new_entry">Add New Goal Entry</label></th>
|
| <td>
|
| <textarea name="kic_goals_new_entry"
|
| id="kic_goals_new_entry"
|
| rows="4"
|
| class="large-text"
|
| placeholder="Enter new goals here (30-day, 60-day, 90-day goals). This will be appended to the log above with today's date."></textarea>
|
| <p class="description">Add a new goal entry (will be appended to history log with date)</p>
|
| </td>
|
| </tr>
|
| </table>
|
|
|
| <h3>Support Needs Assessment - Latest Scores</h3>
|
| <p style="background: #d7f2ff; border-left: 4px solid #0073aa; padding: 10px; margin: 10px 0;">
|
| <strong>💡 Note:</strong> Latest scores (1-5 scale). The complete history log shows all past assessments.
|
| </p>
|
| <table class="form-table" role="presentation">
|
| <tr>
|
| <th><label for="kic_support_need_transportation_latest">Transportation Support</label></th>
|
| <td>
|
| <input type="number"
|
| name="kic_support_need_transportation_latest"
|
| id="kic_support_need_transportation_latest"
|
| value="<?php echo esc_attr( get_user_meta( $user->ID, 'kic_support_need_transportation_latest', true ) ); ?>"
|
| min="1"
|
| max="5"
|
| style="width: 80px;" />
|
| <p class="description">1 (No Help Needed) to 5 (Support Needed) - Optional</p>
|
| </td>
|
| </tr>
|
| <tr>
|
| <th><label for="kic_support_need_mental_health_latest">Mental Health Support</label></th>
|
| <td>
|
| <input type="number"
|
| name="kic_support_need_mental_health_latest"
|
| id="kic_support_need_mental_health_latest"
|
| value="<?php echo esc_attr( get_user_meta( $user->ID, 'kic_support_need_mental_health_latest', true ) ); ?>"
|
| min="1"
|
| max="5"
|
| style="width: 80px;" />
|
| <p class="description">1 (No Help Needed) to 5 (Support Needed) - Optional</p>
|
| </td>
|
| </tr>
|
| <tr>
|
| <th><label for="kic_support_need_physical_health_latest">Physical Health Support</label></th>
|
| <td>
|
| <input type="number"
|
| name="kic_support_need_physical_health_latest"
|
| id="kic_support_need_physical_health_latest"
|
| value="<?php echo esc_attr( get_user_meta( $user->ID, 'kic_support_need_physical_health_latest', true ) ); ?>"
|
| min="1"
|
| max="5"
|
| style="width: 80px;" />
|
| <p class="description">1 (No Help Needed) to 5 (Support Needed) - Optional</p>
|
| </td>
|
| </tr>
|
| <tr>
|
| <th><label for="kic_support_need_substance_latest">Substance Support</label></th>
|
| <td>
|
| <input type="number"
|
| name="kic_support_need_substance_latest"
|
| id="kic_support_need_substance_latest"
|
| value="<?php echo esc_attr( get_user_meta( $user->ID, 'kic_support_need_substance_latest', true ) ); ?>"
|
| min="1"
|
| max="5"
|
| style="width: 80px;" />
|
| <p class="description">Alcohol/Addiction/Tobacco - 1 (No Help) to 5 (Support Needed) - Optional</p>
|
| </td>
|
| </tr>
|
| <tr>
|
| <th><label for="kic_support_need_housing_latest">Housing Support</label></th>
|
| <td>
|
| <input type="number"
|
| name="kic_support_need_housing_latest"
|
| id="kic_support_need_housing_latest"
|
| value="<?php echo esc_attr( get_user_meta( $user->ID, 'kic_support_need_housing_latest', true ) ); ?>"
|
| min="1"
|
| max="5"
|
| style="width: 80px;" />
|
| <p class="description">Living Situations - 1 (No Help) to 5 (Support Needed) - Optional</p>
|
| </td>
|
| </tr>
|
| <tr>
|
| <th><label for="kic_support_need_technology_latest">Technology Support</label></th>
|
| <td>
|
| <input type="number"
|
| name="kic_support_need_technology_latest"
|
| id="kic_support_need_technology_latest"
|
| value="<?php echo esc_attr( get_user_meta( $user->ID, 'kic_support_need_technology_latest', true ) ); ?>"
|
| min="1"
|
| max="5"
|
| style="width: 80px;" />
|
| <p class="description">Computer Access - 1 (No Help) to 5 (Support Needed) - Optional</p>
|
| </td>
|
| </tr>
|
| <tr>
|
| <th><label for="kic_support_need_food_latest">Food Support</label></th>
|
| <td>
|
| <input type="number"
|
| name="kic_support_need_food_latest"
|
| id="kic_support_need_food_latest"
|
| value="<?php echo esc_attr( get_user_meta( $user->ID, 'kic_support_need_food_latest', true ) ); ?>"
|
| min="1"
|
| max="5"
|
| style="width: 80px;" />
|
| <p class="description">1 (No Help Needed) to 5 (Support Needed) - Optional</p>
|
| </td>
|
| </tr>
|
| <tr>
|
| <th><label for="kic_support_need_internet_latest">Internet Access Support</label></th>
|
| <td>
|
| <input type="number"
|
| name="kic_support_need_internet_latest"
|
| id="kic_support_need_internet_latest"
|
| value="<?php echo esc_attr( get_user_meta( $user->ID, 'kic_support_need_internet_latest', true ) ); ?>"
|
| min="1"
|
| max="5"
|
| style="width: 80px;" />
|
| <p class="description">1 (No Help Needed) to 5 (Support Needed) - Optional</p>
|
| </td>
|
| </tr>
|
| </table>
|
|
|
| <h3>Support Needs History Log (Appendable)</h3>
|
| <table class="form-table" role="presentation">
|
| <tr>
|
| <th><label for="kic_support_needs_log">Complete Support Needs History</label></th>
|
| <td>
|
| <textarea name="kic_support_needs_log"
|
| id="kic_support_needs_log"
|
| rows="10"
|
| class="large-text"
|
| readonly
|
| style="background-color: #f6f7f7;"><?php echo esc_textarea( get_user_meta( $user->ID, 'kic_support_needs_log', true ) ); ?></textarea>
|
| <p class="description">READ ONLY - Complete history of all support needs assessments with dates (updated via forms)</p>
|
| </td>
|
| </tr>
|
| </table>
|
|
|
| </div><!-- #kic-scholar-fields-content -->
|
| </div><!-- #kic-scholar-fields-wrapper -->
|
|
|
| <script type="text/javascript">
|
| jQuery(document).ready(function($) {
|
|
|
| $('#kic-scholar-fields-wrapper .postbox-header').on('click', function() {
|
| var $wrapper = $('#kic-scholar-fields-wrapper');
|
| var $content = $('#kic-scholar-fields-content');
|
| var $icon = $wrapper.find('.dashicons');
|
|
|
| if ($content.is(':visible')) {
|
| $content.slideUp(300);
|
| $icon.removeClass('dashicons-arrow-down-alt2').addClass('dashicons-arrow-right-alt2');
|
| $wrapper.addClass('closed');
|
| } else {
|
| $content.slideDown(300);
|
| $icon.removeClass('dashicons-arrow-right-alt2').addClass('dashicons-arrow-down-alt2');
|
| $wrapper.removeClass('closed');
|
| }
|
| });
|
|
|
|
|
| $('#kic-scholar-fields-content').hide();
|
| $('#kic-scholar-fields-wrapper .dashicons').removeClass('dashicons-arrow-down-alt2').addClass('dashicons-arrow-right-alt2');
|
| });
|
| </script>
|
|
|
| <style>
|
|
|
| border: 1px solid
|
| background:
|
| }
|
|
|
| background:
|
| border-bottom: 1px solid
|
| }
|
|
|
| background:
|
| }
|
|
|
| padding: 0 12px 12px;
|
| }
|
|
|
| border-bottom: none;
|
| }
|
| </style>
|
|
|
| <?php
|
| }
|
|
|
|
|
| add_action( 'personal_options_update', 'kic_save_scholar_student_meta_fields', 11 );
|
| add_action( 'edit_user_profile_update', 'kic_save_scholar_student_meta_fields', 11 );
|
|
|
| function kic_save_scholar_student_meta_fields( $user_id ) {
|
|
|
| if ( ! isset( $_POST['kic_scholar_meta_nonce'] ) ||
|
| ! wp_verify_nonce( $_POST['kic_scholar_meta_nonce'], 'kic_scholar_meta_update' ) ) {
|
| return;
|
| }
|
|
|
| if ( ! current_user_can( 'edit_user', $user_id ) ) {
|
| return;
|
| }
|
|
|
|
|
| $update_or_delete_meta = function( $user_id, $meta_key, $value ) {
|
| if ( empty( $value ) ) {
|
| delete_user_meta( $user_id, $meta_key );
|
| } else {
|
| update_user_meta( $user_id, $meta_key, $value );
|
| }
|
| };
|
|
|
|
|
| $update_or_delete_meta( $user_id, 'kic_school_name',
|
| sanitize_text_field( $_POST['kic_school_name'] ?? '' ) );
|
|
|
| $update_or_delete_meta( $user_id, 'kic_school_grade',
|
| sanitize_text_field( $_POST['kic_school_grade'] ?? '' ) );
|
|
|
|
|
| $household_size = intval( $_POST['kic_household_size'] ?? 0 );
|
| if ( $household_size > 0 ) {
|
| update_user_meta( $user_id, 'kic_household_size', $household_size );
|
| } else {
|
| delete_user_meta( $user_id, 'kic_household_size' );
|
| }
|
|
|
| $update_or_delete_meta( $user_id, 'kic_annual_income',
|
| sanitize_text_field( $_POST['kic_annual_income'] ?? '' ) );
|
|
|
|
|
| $update_or_delete_meta( $user_id, 'kic_internet_access',
|
| sanitize_text_field( $_POST['kic_internet_access'] ?? '' ) );
|
|
|
| $update_or_delete_meta( $user_id, 'kic_device_type',
|
| sanitize_text_field( $_POST['kic_device_type'] ?? '' ) );
|
|
|
|
|
| $update_or_delete_meta( $user_id, 'kic_activities_interest',
|
| sanitize_text_field( $_POST['kic_activities_interest'] ?? '' ) );
|
|
|
| $update_or_delete_meta( $user_id, 'kic_transportation_needed',
|
| sanitize_text_field( $_POST['kic_transportation_needed'] ?? '' ) );
|
|
|
| $update_or_delete_meta( $user_id, 'kic_shirt_size',
|
| sanitize_text_field( $_POST['kic_shirt_size'] ?? '' ) );
|
|
|
|
|
|
|
| $new_goal_entry = sanitize_textarea_field( $_POST['kic_goals_new_entry'] ?? '' );
|
|
|
| if ( ! empty( $new_goal_entry ) ) {
|
| $existing_log = get_user_meta( $user_id, 'kic_goals_log', true );
|
| $date_stamp = current_time( 'Y-m-d H:i:s' );
|
| $new_entry = "[{$date_stamp}]\n{$new_goal_entry}\n\n---\n\n";
|
|
|
|
|
| $updated_log = $existing_log . $new_entry;
|
| update_user_meta( $user_id, 'kic_goals_log', $updated_log );
|
| }
|
|
|
|
|
| $support_fields = [
|
| 'kic_support_need_transportation_latest',
|
| 'kic_support_need_mental_health_latest',
|
| 'kic_support_need_physical_health_latest',
|
| 'kic_support_need_substance_latest',
|
| 'kic_support_need_housing_latest',
|
| 'kic_support_need_technology_latest',
|
| 'kic_support_need_food_latest',
|
| 'kic_support_need_internet_latest',
|
| ];
|
|
|
| $support_values_changed = false;
|
| $support_entry_parts = [];
|
|
|
| foreach ( $support_fields as $field ) {
|
| $value = intval( $_POST[$field] ?? 0 );
|
|
|
| if ( $value >= 1 && $value <= 5 ) {
|
| update_user_meta( $user_id, $field, $value );
|
| $support_values_changed = true;
|
|
|
|
|
| $field_name = str_replace( ['kic_support_need_', '_latest'], '', $field );
|
| $field_name = ucwords( str_replace( '_', ' ', $field_name ) );
|
| $support_entry_parts[] = "{$field_name}: {$value}";
|
| } else {
|
| delete_user_meta( $user_id, $field );
|
| }
|
| }
|
|
|
|
|
| if ( $support_values_changed && ! empty( $support_entry_parts ) ) {
|
| $existing_log = get_user_meta( $user_id, 'kic_support_needs_log', true );
|
| $date_stamp = current_time( 'Y-m-d H:i:s' );
|
| $support_entry = implode( ', ', $support_entry_parts );
|
| $new_entry = "[{$date_stamp}] {$support_entry}\n\n";
|
|
|
|
|
| $updated_log = $existing_log . $new_entry;
|
| update_user_meta( $user_id, 'kic_support_needs_log', $updated_log );
|
| }
|
| }
|
|
|
|
|
|
|
|
|
| add_filter( 'manage_users_columns', 'kic_add_scholar_user_list_columns' );
|
| function kic_add_scholar_user_list_columns( $columns ) {
|
| $new_columns = [];
|
| foreach ( $columns as $key => $value ) {
|
| $new_columns[$key] = $value;
|
| if ( 'email' === $key ) {
|
| $new_columns['kic_school_name'] = 'School';
|
| $new_columns['kic_school_grade'] = 'Grade';
|
| }
|
| }
|
| return $new_columns;
|
| }
|
|
|
| add_action( 'manage_users_custom_column', 'kic_show_scholar_user_list_column_content', 10, 3 );
|
| function kic_show_scholar_user_list_column_content( $value, $column_name, $user_id ) {
|
| switch ( $column_name ) {
|
| case 'kic_school_name':
|
| $school = get_user_meta( $user_id, 'kic_school_name', true );
|
| return $school ? esc_html( $school ) : '—';
|
| case 'kic_school_grade':
|
| $grade = get_user_meta( $user_id, 'kic_school_grade', true );
|
| return $grade ? esc_html( $grade ) : '—';
|
| default:
|
| return $value;
|
| }
|
| }
|
|
|
|
|
| add_filter( 'manage_users_sortable_columns', 'kic_make_scholar_user_columns_sortable' );
|
| function kic_make_scholar_user_columns_sortable( $columns ) {
|
| $columns['kic_school_name'] = 'kic_school_name';
|
| $columns['kic_school_grade'] = 'kic_school_grade';
|
| return $columns;
|
| }
|
|
|
|
|
| add_action( 'pre_user_query', 'kic_sort_scholar_users_by_custom_columns' );
|
| function kic_sort_scholar_users_by_custom_columns( $user_query ) {
|
| global $wpdb;
|
|
|
| $orderby = $user_query->get( 'orderby' );
|
|
|
| if ( ! $orderby || ! is_string( $orderby ) ) {
|
| return;
|
| }
|
|
|
| $meta_key_map = [
|
| 'kic_school_name' => 'kic_school_name',
|
| 'kic_school_grade' => 'kic_school_grade',
|
| ];
|
|
|
| if ( isset( $meta_key_map[ $orderby ] ) ) {
|
| $meta_key = $meta_key_map[ $orderby ];
|
| $user_query->query_vars['meta_key'] = $meta_key;
|
| $user_query->query_vars['orderby'] = 'meta_value';
|
| }
|
| }
|
| |
| |
Comments