Last active
September 25, 2024 15:40
-
-
Save Preciousomonze/5815d182c2df0eab2bb9aa0b5b497a78 to your computer and use it in GitHub Desktop.
Tai-Bioptrics css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* TAI Team style start */ | |
.pum-theme-default-theme { | |
background-color: rgba( 0, 0, 0, 0.4 ); | |
} | |
.pum-content + .pum-close, .pum-theme-default-theme .pum-content + .pum-close { | |
border-radius: 0 0 0 10px; | |
background-color: #a0cf4f; | |
} | |
.fc-day .fc-daygrid-day-events::before, .fc-day .fc-daygrid-day-events::after { | |
content: ''; | |
display: inline-block; | |
width: 8px; | |
height: 8px; | |
border-radius: 50%; | |
margin: 7px 1px 2px 5px; | |
position: absolute; | |
bottom: 2px; | |
} | |
.fc-day:not(.fc-day-sat):not(.fc-day-sun) .fc-daygrid-day-events::before { | |
background-color: #607d30; | |
left: 13px; | |
} | |
.fc-day.fc-day-mon .fc-daygrid-day-events::after { | |
background-color: #f2aa52; | |
right: 14px; | |
} | |
.pum-theme-20304 .pum-container, .pum-theme-default-theme .pum-container { | |
padding: 18px 50px 18px 50px; | |
border-radius: 5px; | |
} | |
.checklist-success .button.integrity { | |
background-color: #607d30; | |
color: #ffffff !important; | |
border: 1px solid rgba(0, 0, 0, 0.11); | |
} | |
.checklist-success .button.accountability { | |
background-color: #f2aa52; | |
color: #FFFFFF; | |
border: 1px solid rgba(0,0,0,0.1); | |
} | |
.accordion-content { | |
position: relative; | |
} | |
.bp-checklist-form-layout-2 button.add-editor-btn { | |
width: auto !important; | |
min-width: 140px; | |
background-color: #a0cf4f !important; | |
color: #2e2e2e !important; | |
} | |
.bp-checklist-form-layout-2 button.add-editor-btn.side-by-side { | |
position: absolute; | |
left: 25px; | |
bottom: 34px; | |
margin-top: 0 !important; | |
} | |
#wp-checklist-form button.remove-field-btn { | |
background: #dc3545 !important; /* This is the actual danger red :)*/ | |
} | |
#wp-checklist-form button.remove-field-btn.side-by-side { | |
position: relative; | |
left: 175px; | |
} | |
.accordion h3 .info-icon { | |
position: relative; | |
display: inline-block; | |
margin-left: 8px; | |
cursor: pointer; | |
font-weight: bold; | |
font-size: 14px; | |
border: 1px solid #333; | |
border-radius: 50%; | |
width: 16px; | |
height: 16px; | |
display: inline-flex; | |
justify-content: center; | |
align-items: center; | |
background-color: #333; | |
color: white; | |
top: -2px; | |
} | |
.accordion h3 .info-icon::after { | |
content: attr(data-tooltip); | |
position: absolute; | |
background-color: #333; | |
color: #fff; | |
padding: 5px 10px; | |
border-radius: 4px; | |
white-space: nowrap; | |
opacity: 0; | |
pointer-events: none; | |
transition: opacity 0.2s ease; | |
bottom: 150%; | |
left: 50%; | |
transform: translateX(-50%); | |
margin-bottom: 5px; | |
z-index: 10; | |
font-size: 14px; | |
font-weight: lighter; | |
font-family: var(--ld-typography-font-family); | |
} | |
.accordion h3 .info-icon:hover::after { | |
opacity: 1; | |
} | |
.bp-checklist-form .custom-dropdown .selected-option { | |
width: 100% !important; | |
} | |
.bp-checklist-form .custom-dropdown .selected-option::after { | |
position: absolute; | |
right: 15px; | |
} | |
#wp-checklist-form button:disabled { | |
background-color: #d3d3d3; | |
color: #a1a1a1; | |
border: 1px solid #a1a1a1; | |
cursor: not-allowed; | |
} | |
/* Disabled button focus style (for accessibility) */ | |
#wp-checklist-form button:disabled:focus { | |
outline: none; | |
} | |
.reflection-sheet { | |
padding: 15px; | |
width: 100%; | |
background-color: #f8f0f5; | |
margin: 20px auto; | |
border-radius: 8px; | |
} | |
.reflection-sheet h3 { | |
color: #5d0c25; | |
background-color: rgba(237, 221, 230, 0.8); | |
padding: 10px; | |
border-bottom: 2px solid rgba(0, 0, 0, 0.1); | |
margin-bottom: 20px; | |
text-align: center; | |
font-family: Arial, sans-serif; | |
} | |
.reflection-sheet .form-group { | |
display: flex; | |
justify-content: space-between; | |
align-items: baseline; | |
padding: 0 10px; | |
} | |
.reflection-sheet label { | |
font-size: 16px; | |
color: black; | |
margin-right: 10px; | |
font-weight: bold; | |
} | |
.reflection-sheet .input-field { | |
padding: 5px 10px; | |
width: 45%; | |
background-color: #eef2fb; | |
border: 1px solid #999; | |
border-radius: 5px; | |
} | |
.reflection-sheet .date-label { | |
margin-left: 20px; | |
} | |
.reflection-sheet input[type="text"], input[type="date"] { | |
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1); | |
} | |
.fc-header-toolbar .fc-today-button { | |
padding: 0px 12px !important; | |
} | |
.indicator-guide { | |
display: flex; | |
gap: 30px; | |
align-items: center; | |
} | |
.indicator-item { | |
display: flex; | |
align-items: center; | |
font-family: Arial, sans-serif; | |
font-size: 14px; | |
color: #333; | |
} | |
.indicator-circle { | |
display: inline-block; | |
width: 12px; | |
height: 12px; | |
border-radius: 50%; | |
margin-right: 8px; | |
} | |
.indicator-item.integrity .indicator-circle { | |
background-color: #607d30; | |
} | |
.indicator-item.accountability .indicator-circle { | |
background-color: #f4c242; | |
} | |
.calendar-footer { | |
padding: 5px 30px; | |
background: #fff; | |
border-bottom: 1px solid rgba(0, 0, 0, 0.1); | |
bottom: 0; | |
position: relative; | |
text-align: center; | |
border-radius: 5px; | |
} | |
@media only screen and (min-width: 1024px) { | |
.pum-container.pum-responsive.pum-responsive-medium { | |
margin-left: -20%; | |
width: 40%; | |
} | |
} | |
/* TAI Team style end */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: WP Checklist | |
Description: A WordPress plugin to create and manage daily checklists with dynamic questions. | |
Version: 1.0 | |
Author: Your Name | |
*/ | |
// Create database tables on plugin activation | |
function wp_checklist_create_tables() { | |
global $wpdb; | |
$charset_collate = $wpdb->get_charset_collate(); | |
// Table to store questions | |
$questions_table = $wpdb->prefix . 'checklist_questions'; | |
$sql1 = "CREATE TABLE $questions_table ( | |
id mediumint(9) NOT NULL AUTO_INCREMENT, | |
section tinyint(1) NOT NULL, | |
question text NOT NULL, | |
PRIMARY KEY (id) | |
) $charset_collate;"; | |
// Table to store user responses | |
$responses_table = $wpdb->prefix . 'checklist_responses'; | |
$sql2 = "CREATE TABLE $responses_table ( | |
id mediumint(9) NOT NULL AUTO_INCREMENT, | |
user_id bigint(20) NOT NULL, | |
date date NOT NULL, | |
question_id mediumint(9) NOT NULL, | |
response text NOT NULL, | |
PRIMARY KEY (id), | |
KEY user_id (user_id), | |
KEY date (date) | |
) $charset_collate;"; | |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); | |
dbDelta($sql1); | |
dbDelta($sql2); | |
} | |
register_activation_hook(__FILE__, 'wp_checklist_create_tables'); | |
require_once dirname(__FILE__) . '/admin-functions.php'; | |
function wp_checklist_add_custom_capability() { | |
$role = get_role('administrator'); | |
if ($role) { | |
$role->add_cap('manage_checklist_admin', true); | |
} | |
$role = get_role('supervisor'); | |
if ($role) { | |
$role->add_cap('manage_checklist_admin', true); | |
} | |
} | |
register_activation_hook(__FILE__, 'wp_checklist_add_custom_capability'); | |
function wp_checklist_remove_custom_capability() { | |
$role = get_role('administrator'); | |
if ($role) { | |
$role->remove_cap('manage_checklist_admin'); | |
} | |
$role = get_role('supervisor'); | |
if ($role) { | |
$role->remove_cap('manage_checklist_admin'); | |
} | |
} | |
register_deactivation_hook(__FILE__, 'wp_checklist_remove_custom_capability'); | |
function pre($attr){ | |
echo "<pre>"; | |
print_r($attr); | |
echo "</pre>"; | |
} | |
// Shortcode to display the checklist form | |
function wp_checklist_shortcode() { | |
if (!is_user_logged_in()) { | |
return '<p>You must be logged in to view this content.</p>'; | |
} | |
global $wpdb; | |
$sections_table = $wpdb->prefix . 'checklist_sections'; | |
$responses_table = $wpdb->prefix . 'checklist_responses'; | |
// Fetch sections and label structures | |
$sections = $wpdb->get_results("SELECT * FROM $sections_table ORDER BY id"); | |
$user_id = get_current_user_id(); | |
$current_date = isset($_REQUEST['date']) ? $_REQUEST['date'] : date('Y-m-d'); | |
// Fetch existing responses for the current user and date | |
$responses = $wpdb->get_results($wpdb->prepare( | |
"SELECT section_id, response,supervisor_id FROM $responses_table WHERE user_id = %d AND date = %s", | |
$user_id, | |
$current_date | |
), ARRAY_A); | |
// Map existing responses by section for easier lookup | |
$existing_responses = []; | |
$saved_supervisor_ids = ''; | |
foreach ($responses as $response) { | |
// pre(json_decode($response['response'])); | |
$existing_responses[$response['section_id']] = json_decode($response['response'], true); | |
$saved_supervisor_ids = $response['supervisor_id']; | |
} | |
$args = array('role' => 'supervisor'); | |
$supervisors = get_users($args); | |
$completed_sections = []; | |
$response_sections = array_column($responses, 'section_id'); | |
foreach ($sections as $section) { | |
if (in_array($section->id, $response_sections)) { | |
$completed_sections[] = $section->id; | |
} | |
} | |
// Check if the first section is completed | |
$first_section_completed = in_array(1, $completed_sections); | |
// Determine if section 2 and 3 should be shown based on the completion of section 1 | |
$show_section_2_and_3 = $first_section_completed; | |
//pre($existing_responses); | |
ob_start(); | |
if (isset($_REQUEST['checklist']) && $_REQUEST['checklist'] == 'success'): ?> | |
<div id="successMessage" style="color: green; font-weight: bold; margin-bottom: 15px;"> | |
Checklist submitted successfully! | |
</div> | |
<?php endif; | |
if (!isset($_REQUEST['date'])) { ?> | |
<div id="calendar"></div> | |
<div id="loader-overlay" style="display:none;"> | |
<div id="loader"></div> | |
</div> | |
<?php } else { | |
$date_value = sanitize_text_field( $_REQUEST['date'] ); | |
// Convert the timestamp to the 'Y-m-d' format for the input | |
$date_value = ( is_numeric( $date_value ) ? date( 'Y-m-d', intval( $date_value ) ) : $date_value ); | |
$this_user = wp_get_current_user(); | |
$_username = ''; | |
if ( $this_user->ID !== 0 ) { | |
$first_name = get_user_meta( $this_user->ID, 'first_name', true ); | |
$last_name = get_user_meta( $this_user->ID, 'last_name', true ); | |
// If both first and last name are available, combine them. Otherwise, use whichever is available. | |
$_username = trim( $first_name . ' ' . $last_name ); | |
// Fallback to display_name if first and last name are empty | |
if ( empty( $_username ) ) { | |
$_username = $this_user->display_name; | |
} | |
} | |
?> | |
<style> | |
.accordion { | |
background-color: #f1f1f1; | |
color: #444; | |
cursor: pointer; | |
padding: 10px; | |
width: 100%; | |
border: none; | |
text-align: left; | |
outline: none; | |
font-size: 15px; | |
transition: background-color 0.4s ease; | |
margin-bottom: 5px; | |
} | |
.accordion.active, .accordion:hover { | |
background-color: #ccc; | |
} | |
.accordion-content { | |
display: none; | |
overflow: hidden; | |
background-color: #f9f9f9; | |
padding: 10px; | |
} | |
.form_row { | |
margin-bottom: 15px; | |
} | |
#submit-button { | |
margin-top: 20px; | |
} | |
.accordion-disabled { | |
pointer-events: none; | |
opacity: 0.5; | |
} | |
.accordion:first-of-type + .accordion-content { | |
display: block; | |
} | |
.remove-field-btn { | |
color: red; | |
cursor: pointer; | |
font-size: 14px; | |
background: none; | |
border: none; | |
padding: 0; | |
} | |
.add-editor-btn { | |
margin-top: 10px; | |
} | |
</style> | |
<div id="wp-checklist-popup" class="wp-checklist-popup"> | |
<input type="hidden" name="wp_checklist_nonce" value="<?php echo wp_create_nonce('wp_checklist_nonce'); ?>"> | |
<div class="popup_outer"> | |
<div class="popup_inner"> | |
<div class="wp-checklist-popup-header"> | |
<p class="wp-checklist-popup-content"> | |
<!--<strong>(to be done everyday till our next session) We will review 2 weeks of tracking progress.</strong><br>--> | |
This daily integrity checklist is designed to help you track your priorities, achievements, and areas for improvement and begin to see a pattern in your "reasons behind not being your word". By filling out this sheet each day, you reinforce accountability and develop a clearer understanding of your progress and the reasons or excuses that keep you from being responsible for what matters to you. | |
</p> | |
</div> | |
<form id="wp-checklist-form" method="POST"> | |
<div class="reflection-sheet"> | |
<h3>Daily Reflection Integrity Report</h3> | |
<div class="form-group"> | |
<label for="name">Name:</label> | |
<input type="text" name="r_user_name" value="<?php echo esc_attr( $_username ); ?>" class="input-field" readonly> | |
<label for="date" class="date-label">Date:</label> | |
<input type="date" name="r_date" value="<?php echo esc_attr( $date_value ); ?>" class="input-field" readonly> | |
</div> | |
</div> | |
<?php foreach ($sections as $section): ?> | |
<?php | |
// Decode the label structure (JSON format) | |
$labels = json_decode($section->label_structure, true); | |
// Get responses for this section, or display empty fields if no responses exist | |
$existing_response = isset($existing_responses[$section->id]) ? $existing_responses[$section->id] : []; | |
//pre($existing_responses[$section->id]);/ | |
//pre($existing_response); | |
$field_count = 1; | |
if(!empty($existing_responses)){ | |
$field_count = count($existing_response); // Number of fields per section | |
} | |
//$section_completed = !empty(array_intersect(array_column($questions_in_section, 'id'), array_column($responses, 'question_id'))); | |
$is_disabled = $section->id != 1 && !$first_section_completed; | |
/** | |
* Filters the title of the section before it is displayed. | |
* | |
* @param string $section_title The current section title. | |
* @param object $section The section object containing the title and other data. | |
* | |
* @return string The modified or original section title. | |
*/ | |
$section_tooltip = apply_filters( 'wp_checklist_section_tooltip', $section->sec_title, $section ); | |
?> | |
<div class="accordion <?= $is_disabled ? 'accordion-disabled' : ''; ?>" data-section-id="<?= $section->id; ?>" > | |
<h3><span>Section <?= $section->id; ?>: <?= htmlspecialchars($section->sec_title); ?><small class="info-icon fa fa-question-circle info-icon" data-tooltip="<?php echo htmlspecialchars( $section_tooltip ); ?>"></small></span></h3> | |
</div> | |
<div class="accordion-content" style="<?= $section->id == 1 ? 'display: block;' : ($is_disabled ? 'display: none;' : ''); ?>"> | |
<?php | |
// Loop through the labels and generate fields | |
for ($i = 1; $i <= $field_count; $i++) { | |
foreach ($labels as $index => $label_template) { | |
// pre($existing_response[$i]); | |
// Generate the label dynamically | |
$label = sprintf($label_template, $i); | |
$response = ''; | |
// Get the existing response if available | |
$response = isset($existing_response[$i][$index]) ? $existing_response[$i][$index] : ''; | |
?> | |
<div class="form_row" data-field-id="field_<?= $section->id . '_' . $i; ?>"> | |
<label for="field_<?= $section->id . '_' . $i; ?>"><?= $label; ?></label> | |
<?php | |
// Generate a unique ID for the editor | |
$editor_id = 'field_' . $section->id . '_' . $i.'_'.$index; | |
wp_editor($response, $editor_id, [ | |
'textarea_name' => "response[{$section->id}][$i][{$index}]", | |
'textarea_rows' => 4, | |
'teeny' => true, | |
'media_buttons' => false, | |
'quicktags' => false // Disable the text tab | |
]); | |
?> | |
<?php if ($field_count > 1): ?> | |
<button type="button" class="remove-field-btn" onclick="removeField(this)">Remove</button> | |
<?php endif; ?> | |
</div> | |
<?php | |
} | |
} | |
?> | |
<div id="dynamic-editor-fields-<?= $section->id; ?>"></div> | |
<button type="button" class="add-editor-btn" style="background-color:#a0cf4f !important;" data-section-id="<?= $section->id; ?>" data-labels='<?= json_encode($labels); ?>' data-last-field="<?= $i; ?>">Add New Priority</button> | |
</div> | |
<?php endforeach; ?> | |
<div class="form_row"> | |
<label for="supervisor_id">Supervisor:</label> | |
<?php | |
$supervisor_ids = array(); | |
if (!empty($saved_supervisor_ids)) { | |
$supervisor_ids = maybe_unserialize($saved_supervisor_ids); | |
// pre($supervisor_ids); | |
if (!is_array($supervisor_ids)) { | |
$supervisor_ids = array(); | |
} | |
} | |
//pre($supervisor_ids); | |
?> | |
<select class="custom-select" id="supervisor_id" placeholder="Select Supervisor" name="supervisor_id[]" multiple> | |
<?php foreach ($supervisors as $user) { | |
$avatar_url = bp_core_fetch_avatar(array( | |
'item_id' => $user->ID, | |
'type' => 'full', | |
'html' => false, | |
)); ?> | |
<option | |
<?php echo in_array($user->ID, $supervisor_ids) ? 'selected' : ''; ?> | |
data-image="<?php echo esc_url($avatar_url); ?>" | |
value="<?php echo $user->ID; ?>"> | |
<?php echo htmlspecialchars($user->first_name) . ' ' . htmlspecialchars($user->last_name); ?> | |
</option> | |
<?php } ?> | |
</select> | |
</div> | |
<?php | |
$timestamp_date = DateTime::createFromFormat('U', $_REQUEST['date']); | |
$submit_date = $timestamp_date->format('Y-m-d'); | |
?> | |
<input type="hidden" id="popup-date" name="date" value="<?php echo $submit_date; ?>"> | |
<?php | |
$disable_submit = ( isset( $_GET['checklist'] ) && sanitize_text_field( wp_unslash( $_GET['checklist'] ) ) === 'success' ? 'disabled' : '' ); ?> | |
<button type="submit" name="submit_checklist" id="submit-button" <?php echo $disable_submit; ?>>Submit</button> | |
</form> | |
</div> | |
</div> | |
</div> | |
<div id="loader-overlay" style="display:none;"> | |
<div id="loader"></div> | |
</div> | |
<script> | |
document.addEventListener('DOMContentLoaded', function() { | |
// Our Submit button. | |
const submitBtn = document.getElementById( 'submit-button' ); | |
// Select the input field inside the Select2 container. | |
const select2Input = document.querySelector( '.select2-search__field' ); | |
console.log({select2Input}); | |
if ( select2Input ) { | |
select2Input.placeholder = "Select Supervisors"; | |
} | |
// Find all the 'accordion-content' divs. | |
let accordionContents = document.querySelectorAll( '.accordion-content' ); | |
accordionContents.forEach( function( content ) { | |
let removeButtons = content.querySelectorAll( '.remove-field-btn' ); | |
// Add 'side-by-side' class to the last remove button. | |
if ( removeButtons.length > 0 ) { | |
removeButtons.forEach( function( btn ) { | |
btn.classList.remove( 'side-by-side' ); | |
}); | |
// Add the class to the last button in the list. | |
removeButtons[removeButtons.length - 1].classList.add( 'side-by-side' ); | |
// Add 'side-by-side' class to the button with the class 'add-editor-btn' if at least one remove button exists. | |
let addEditorButton = content.querySelector( '.add-editor-btn' ); | |
if ( addEditorButton ) { | |
addEditorButton.classList.add( 'side-by-side' ); | |
} | |
} | |
}); | |
function initializeTinyMCE(selector) { | |
tinymce.init({ | |
selector: selector, | |
menubar: false, | |
toolbar: 'undo redo | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat', | |
plugins: 'lists link', | |
branding: false, | |
setup: function(editor) { | |
editor.on('init', function() { | |
editor.setContent(editor.getElement().value); // Set initial content | |
}); | |
// Add event listener for changes in the editor. | |
editor.on( 'change', function() { | |
submitBtn.removeAttribute( 'disabled' ); | |
}); | |
} | |
}); | |
} | |
document.querySelectorAll('.add-editor-btn').forEach(button => { | |
button.addEventListener('click', function() { | |
const sectionId = button.getAttribute('data-section-id'); | |
const labels = JSON.parse(button.getAttribute('data-labels')); | |
let lastField = parseInt(button.getAttribute('data-last-field'), 10); | |
// Loop through the labels for each field | |
labels.forEach((label_template, index) => { | |
const newLabel = label_template.replace('%d', lastField); | |
const editorId = 'dynamic_field_' + sectionId + '_' + lastField + '_' + index; | |
// Create new field structure | |
const newFieldHtml = ` | |
<div class="form_row" data-field-id="${editorId}"> | |
<label for="${editorId}">${newLabel}</label> | |
<textarea id="${editorId}" name="response[${sectionId}][${lastField}][${index}]" rows="4"></textarea> | |
<button type="button" class="remove-field-btn" onclick="removeField(this)">Remove</button> | |
</div> | |
`; | |
document.getElementById('dynamic-editor-fields-' + sectionId).insertAdjacentHTML('beforeend', newFieldHtml); | |
// Initialize TinyMCE editor for the new textarea | |
initializeTinyMCE(`#${editorId}`); | |
// Increment field count | |
}); | |
lastField++; | |
button.setAttribute('data-last-field', lastField); | |
// Add our side-by-side class to editor btn. | |
if ( document.getElementById('dynamic-editor-fields-' + sectionId).children.length > 0 ) { | |
button.classList.add( 'side-by-side' ); | |
// Add 'side-by-side' class to the last remove button. | |
let removeButtons = document.getElementById( 'dynamic-editor-fields-' + sectionId ).querySelectorAll( '.remove-field-btn' ); | |
removeButtons.forEach( btn => btn.classList.remove( 'side-by-side' ) ); | |
removeButtons[removeButtons.length - 1].classList.add( 'side-by-side' ); | |
} | |
submitBtn.removeAttribute( 'disabled' ); | |
}); | |
}); | |
window.removeField = function(button) { | |
const fieldRow = button.closest('.form_row'); | |
const sectionId = button.closest( '.accordion-content' ).querySelector( '.add-editor-btn' ).getAttribute( 'data-section-id' ); | |
const dynamicFieldsContainer = document.getElementById( 'dynamic-editor-fields-' + sectionId ); | |
fieldRow.remove(); | |
// Remove TinyMCE instance if necessary | |
const textareaId = fieldRow.querySelector('textarea').id; | |
if (tinymce.get(textareaId)) { | |
tinymce.get(textareaId).remove(); | |
} | |
// If no more fields are available, remove the side-by-side class from the button. | |
const addButton = document.querySelector(`.add-editor-btn[data-section-id="${sectionId}"]`); | |
if ( dynamicFieldsContainer.children.length === 0 ) { | |
addButton.classList.remove( 'side-by-side' ); | |
} else { | |
// Add 'side-by-side' class to the last remove button. | |
const removeButtons = dynamicFieldsContainer.querySelectorAll( '.remove-field-btn' ); | |
removeButtons.forEach( btn => btn.classList.remove( 'side-by-side' ) ); | |
removeButtons[removeButtons.length - 1].classList.add( 'side-by-side' ); | |
} | |
submitBtn.removeAttribute( 'disabled' ); | |
}; | |
// Initialize TinyMCE for all existing editors | |
document.querySelectorAll('textarea').forEach(textarea => { | |
initializeTinyMCE(`#${textarea.id}`); | |
}); | |
var acc = document.getElementsByClassName("accordion"); | |
for (var i = 0; i < acc.length; i++) { | |
acc[i].addEventListener("click", function() { | |
// Toggle the "active" class and open/close the panel | |
if (!this.classList.contains('accordion-disabled')) { | |
this.classList.toggle("active"); | |
var panel = this.nextElementSibling; | |
if (panel.style.display === "block") { | |
panel.style.display = "none"; | |
} else { | |
panel.style.display = "block"; | |
} | |
} | |
}); | |
} | |
}); | |
</script> | |
<?php } | |
return ob_get_clean(); | |
} | |
add_shortcode('wp_checklist', 'wp_checklist_shortcode'); | |
function save_checklist_form() { | |
global $wpdb; | |
$responses_table = $wpdb->prefix . 'checklist_responses'; | |
$user_id = get_current_user_id(); | |
$date = sanitize_text_field($_POST['date']); | |
// if(!empty($date)){ | |
// $date = date('Y-m-d', $date); | |
// } | |
$supervisor_ids = $_POST['supervisor_id']; | |
$supervisor_data = maybe_serialize($supervisor_ids); | |
$this_user = wp_get_current_user(); | |
$_username = ''; | |
if ( $this_user->ID !== 0 ) { | |
$first_name = get_user_meta( $this_user->ID, 'first_name', true ); | |
$last_name = get_user_meta( $this_user->ID, 'last_name', true ); | |
// If both first and last name are available, combine them. Otherwise, use whichever is available. | |
$_username = trim( $first_name . ' ' . $last_name ); | |
// Fallback to display_name if first and last name are empty | |
if ( empty( $_username ) ) { | |
$_username = $this_user->display_name; | |
} | |
} | |
if (isset($_POST['response'])) { | |
$responses = isset($_POST['response']) ? $_POST['response'] : []; | |
// Save responses | |
foreach ($responses as $section_id => $response_set) { | |
$response_json = json_encode($response_set); | |
//pre($response_set); | |
$existing_response = $wpdb->get_row($wpdb->prepare( | |
"SELECT id FROM $responses_table WHERE user_id = %d AND date = %s AND section_id = %d", | |
$user_id, | |
$date, | |
$section_id | |
)); | |
if ($existing_response) { | |
// Update existing response | |
$wpdb->update( | |
$responses_table, | |
['response' => $response_json,'supervisor_id'=>$supervisor_data], | |
['id' => $existing_response->id] | |
); | |
} else { | |
// Insert new response | |
$wpdb->insert( | |
$responses_table, | |
[ | |
'user_id' => $user_id, | |
'date' => $date, | |
'section_id' => $section_id, | |
'response' => $response_json, | |
'supervisor_id'=>$supervisor_data | |
] | |
); | |
} | |
} | |
// pre($supervisor_ids); | |
if(!empty($supervisor_ids)){ | |
foreach($supervisor_ids as $supervisor_id){ | |
$supervisor = get_userdata($supervisor_id); | |
$supervisor_email = $supervisor->user_email; | |
// Prepare HTML email content | |
$subject = 'Integrity Checklist Form Submission'; | |
// Fetch all sections as before | |
$sections = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}checklist_sections ORDER BY id ASC"); | |
$section_msg = ''; | |
$i = 1; | |
// Assume you have the response data in this JSON format | |
// For example: {"1":["p1"],"2":["p2"]} | |
$decoded_responses = $_POST['response']; // Assuming the JSON data is in the $_POST | |
// Decode the JSON to an associative array | |
// pre($decoded_responses); | |
foreach ($sections as $section) { | |
$labels = json_decode($section->label_structure, true); | |
// Build the section structure | |
$section_msg .= '<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center"> | |
<tr> | |
<td> | |
<table cellpadding="0" cellspacing="0" border="0"> | |
<tr> | |
<td style="padding:15px 25px; background:#F8EED2;"> | |
<h3 style="color: #121212; margin: 0; text-transform: uppercase; font-size: 14px; letter-spacing: 1px;">' . $section->sec_title . '</h3> | |
</td> | |
</tr> | |
</table>'; | |
$section_msg .= '<table cellpadding="0" cellspacing="0" border="0" width="100%">'; | |
// Get the responses for this section by its ID | |
if (isset($decoded_responses[$section->id])) { | |
$section_responses = $decoded_responses[$section->id]; // This should be an array of responses for the section | |
// Loop through each response and add it to the email | |
$j=1; foreach ($section_responses as $response) { | |
// pre($response); | |
foreach ($labels as $index => $label_template) { | |
$label = sprintf($label_template, $j); | |
$response = sanitize_text_field($response[$index]); // Sanitize each response | |
$section_msg .= '<tr> | |
<td style="padding:25px; border-bottom: 1px solid #ebebeb;"> | |
<label style="font-weight:700;">'.$label.':</label>'; | |
// Special formatting for the third section | |
if ($i == 3) { | |
$section_msg .= '<p style="font-size: 13px; line-height: 19px; color: #111111; background:#f1f1f1; padding:20px; margin-left:20px;">' . $response . '</p>'; | |
} else { | |
$section_msg .= '<p style="font-size: 15px; line-height: 21px; color: #111111;">' . $response . '</p>'; | |
} | |
$section_msg .= '</td> | |
</tr>'; | |
} | |
$j++; } | |
} else { | |
// If no responses exist for this section, show a placeholder | |
$section_msg .= '<tr> | |
<td style="padding:25px; border-bottom: 1px solid #ebebeb;"> | |
<p style="font-size: 15px; line-height: 21px; color: #111111;">No responses for this section.</p> | |
</td> | |
</tr>'; | |
} | |
$section_msg .= '</table> | |
</td> | |
</tr> | |
</table>'; | |
$i++; | |
} | |
$message = '<body style="font-family:arial; margin:0; padding:0;"> | |
<table width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="#cccccc;" style="background:#cccccc;"> | |
<tr> | |
<td> | |
<table width="600px" cellpadding="0" cellspacing="0" border="0" align="center" bgcolor="#ffffff;" style="background:#ffffff; margin-top:50px; margin-bottom:50px;"> | |
<tr> | |
<td> | |
<!--- header ---> | |
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center"> | |
<tr> | |
<td style="padding:18px 25px; text-align:center; background:#552A47;"> | |
<img src="https://wordpress-453887-4616275.cloudwaysapps.com/wp-content/uploads/2024/06/logo.png" alt="Logo" /> | |
</td> | |
</tr> | |
</table> | |
<!--- header caption ---> | |
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center"> | |
<tr> | |
<td style="padding:18px 25px;"> | |
<h3 style="color:#552A47; margin:0; font-size:25px;">Integrity Checklist</h3> | |
<p style="font-size: 14px; line-height: 21px; color: #333333;">This daily Integrity checklist is designed to help you track your priorities, achievements, and areas for improvement and begin to see a pattern in your "reasons behind not being your word". By filling out this sheet each day, you reinforce accountability and develop a clearer understanding of your progress and the reasons or excuses that keep you from being responsible for what matters to you.</p> | |
</td> | |
</tr> | |
</table> | |
<!--- main title ---> | |
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center"> | |
<tr> | |
<td colspan="2" style="padding:20px 25px; background:#EEDCE7;"> | |
<h3 style="color:#552A47; margin:0;">Daily Reflection Integrity Report</h3> | |
</td> | |
</tr> | |
<tr> | |
<td style="padding:25px;"> | |
<h5 style="color:#111111; margin:0; font-size:16px;">' . $_username . '</h5> | |
</td> | |
<td style="padding:25px; text-align:right;"> | |
<h5 style="color:#111111; margin:0; font-size:16px;">' . $date . '</h5> | |
</td> | |
</tr> | |
</table>' . $section_msg . ' | |
</td> | |
</tr> | |
</table> | |
</td> | |
</tr> | |
</table> | |
</body>'; | |
// Set content type to HTML | |
$headers = array('Content-Type: text/html; charset=UTF-8'); | |
// $supervisor_email = '[email protected]'; | |
//print_r($supervisor_email); | |
// Send email to supervisor | |
wp_mail($supervisor_email, $subject, $message, $headers); | |
} | |
} | |
// die; | |
// Redirect to avoid resubmission on page refresh | |
wp_redirect(add_query_arg('checklist', 'success', get_permalink())); | |
exit; | |
} | |
} | |
add_action('init', 'save_checklist_form'); | |
function get_section_title($sec_id){ | |
global $wpdb; | |
$section_table = $wpdb->prefix . 'checklist_sections'; | |
$section = $wpdb->get_row($wpdb->prepare("SELECT * FROM $section_table WHERE id = %d", $sec_id)); | |
return $section->sec_title; | |
} | |
// Handle form submission | |
function wp_checklist_handle_form_submission() { | |
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit_checklist'])) { | |
if (!is_user_logged_in()) { | |
wp_die('You must be logged in to submit the form.'); | |
} | |
$user_id = get_current_user_id(); | |
$date = sanitize_text_field($_POST['date']); | |
global $wpdb; | |
$responses_table = $wpdb->prefix . 'checklist_responses'; | |
foreach ($_POST as $key => $value) { | |
if (strpos($key, 'question_') === 0) { | |
$question_id = str_replace('question_', '', $key); | |
$response = wp_kses_post($value); // Handle rich text data | |
$supervisor_id = sanitize_text_field($_POST['supervisor_id']); | |
$existing_entry = $wpdb->get_var($wpdb->prepare( | |
"SELECT id FROM $responses_table WHERE user_id = %d AND date = %s AND question_id = %d", | |
$user_id, $date, $question_id | |
)); | |
if ($existing_entry) { | |
// Update existing entry | |
$wpdb->update( | |
$responses_table, | |
array( | |
'response' => $response, | |
'supervisor_id' => $supervisor_id | |
), | |
array( | |
'id' => $existing_entry | |
) | |
); | |
} else { | |
// Insert new entry | |
$wpdb->insert($responses_table, array( | |
'user_id' => $user_id, | |
'date' => $date, | |
'question_id' => $question_id, | |
'response' => $response, | |
'supervisor_id' => $supervisor_id, | |
)); | |
} | |
} | |
} | |
// Handle email sending as before | |
wp_redirect(add_query_arg('checklist', 'success')); | |
exit; | |
} | |
} | |
//add_action('init', 'wp_checklist_handle_form_submission'); | |
function wp_checklist_handle_form() { | |
if (!is_user_logged_in()) { | |
wp_send_json_error(array('message' => 'You must be logged in to submit the form.')); | |
return; | |
} | |
$user_id = get_current_user_id(); | |
$date = sanitize_text_field($_POST['date']); | |
global $wpdb; | |
$responses_table = $wpdb->prefix . 'checklist_responses'; | |
$supervisor_id = sanitize_text_field($_POST['supervisor_id']); | |
foreach ($_POST as $key => $value) { | |
if (strpos($key, 'question_') === 0) { | |
$question_id = str_replace('question_', '', $key); | |
$response = wp_kses_post($value); // Allow HTML content with the default allowed tags | |
$existing_entry = $wpdb->get_var($wpdb->prepare( | |
"SELECT id FROM $responses_table WHERE user_id = %d AND date = %s AND question_id = %d", | |
$user_id, $date, $question_id | |
)); | |
if ($existing_entry) { | |
// Update existing entry | |
$wpdb->update( | |
$responses_table, | |
array( | |
'response' => $response, | |
'supervisor_id' => $supervisor_id | |
), | |
array( | |
'id' => $existing_entry | |
) | |
); | |
} else { | |
// Insert new entry | |
$wpdb->insert($responses_table, array( | |
'user_id' => $user_id, | |
'date' => $date, | |
'question_id' => $question_id, | |
'response' => $response, | |
'supervisor_id' => $supervisor_id, | |
)); | |
} | |
} | |
} | |
// Get supervisor email | |
$supervisor = get_userdata($supervisor_id); | |
if ($supervisor) { | |
$supervisor_email = $supervisor->user_email; | |
// Prepare HTML email content | |
$subject = 'Integrity Checklist Form Submission'; | |
$sections = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}checklist_sections ORDER BY id ASC"); | |
$section_msg = ''; | |
$i=1; | |
foreach( $sections as $section ) { | |
$section_msg .= '<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center"> | |
<tr> | |
<td> | |
<table cellpadding="0" cellspacing="0" border="0"> | |
<tr> | |
<td style="padding:15px 25px; background:#F8EED2;"> | |
<h3 style="color: #121212; margin: 0; text-transform: uppercase; font-size: 14px; letter-spacing: 1px;">'.$section->sec_title.'</h3> | |
</td> | |
</tr> | |
</table>'; | |
$questions = $wpdb->get_results($wpdb->prepare( | |
"SELECT * FROM {$wpdb->prefix}checklist_questions WHERE section = %d ORDER BY id ASC", | |
$section->id | |
)); | |
$section_msg .= '<table cellpadding="0" cellspacing="0" border="0" width="100%">'; | |
foreach ($questions as $question) { | |
$response = sanitize_text_field($_POST['question_' . $question->id]); | |
$section_msg .= '<tr> | |
<td style="padding:25px; border-bottom: 1px solid #ebebeb;"> | |
<label style="font-weight:700;">'.$question->question.':</label>'; | |
if($i == 3){ | |
$section_msg .='<p style="font-size: 13px; line-height: 19px; color: #111111; background:#f1f1f1; padding:20px; margin-left:20px;">'.$response.'</p>'; | |
}else{ | |
$section_msg .= '<p style="font-size: 15px; line-height: 21px; color: #111111;">'.$response.'</p>'; | |
} | |
$section_msg .= '</td> | |
</tr>'; | |
} | |
$section_msg .= '</table> | |
</td> | |
</tr> | |
</table>'; | |
$i++; | |
} | |
$message = '<body style="font-family:arial; margin:0; padding:0;"> | |
<table width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="#cccccc;" style="background:#cccccc;"> | |
<tr> | |
<td> | |
<table width="600px" cellpadding="0" cellspacing="0" border="0" align="center" bgcolor="#ffffff;" style="background:#ffffff; margin-top:50px; margin-bottom:50px;"> | |
<tr> | |
<td> | |
<!--- header ---> | |
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center"> | |
<tr> | |
<td style="padding:18px 25px; text-align:center; background:#552A47;"> | |
<img src="https://wordpress-453887-4616275.cloudwaysapps.com/wp-content/uploads/2024/06/logo.png" alt="Logo" /> | |
</td> | |
</tr> | |
</table> | |
<!--- header caption ---> | |
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center"> | |
<tr> | |
<td style="padding:18px 25px;"> | |
<h3 style="color:#552A47; margin:0; font-size:25px;">Integrity Checklist</h3> | |
<p style="font-size: 16px; line-height: 21px; color: #333333;"><strong>(to be done everyday till our next session) We will review 2 weeks of tracking progress.</strong></p> | |
<p style="font-size: 14px; line-height: 21px; color: #333333;">This daily Integrity checklist is designed to help you track your priorities, achievements, and areas for improvement and begin to see a pattern in your "reasons behind not being your word". By filling out this sheet each day, you reinforce accountability and develop a clearer understanding of your progress and the reasons or excuses that keep you from being responsible for what matters to you.</p> | |
</td> | |
</tr> | |
</table> | |
<!--- main title ---> | |
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center"> | |
<tr> | |
<td colspan="2" style="padding:20px 25px; background:#EEDCE7;"> | |
<h3 style="color:#552A47; margin:0;">Daily Reflection Integrity Report</h3> | |
</td> | |
</tr> | |
<tr> | |
<td style="padding:25px;"> | |
<h5 style="color:#111111; margin:0; font-size:16px;">' . wp_get_current_user()->display_name . '</h5> | |
</td> | |
<td style="padding:25px; text-align:right;"> | |
<h5 style="color:#111111; margin:0; font-size:16px;">' . $date . '</h5> | |
</td> | |
</tr> | |
</table>'.$section_msg.' | |
</td> | |
</tr> | |
</table> | |
</td> | |
</tr> | |
</table> | |
</body>'; | |
// Set content type to HTML | |
$headers = array('Content-Type: text/html; charset=UTF-8'); | |
// $supervisor_email = '[email protected]'; | |
// Send email to supervisor | |
// wp_mail($supervisor_email, $subject, $message, $headers); | |
} | |
wp_send_json_success(array('message' => 'Checklist submitted. Thank you for your commitment!')); | |
} | |
//add_action('wp_ajax_wp_checklist_handle_form', 'wp_checklist_handle_form'); | |
// Shortcode to display user's past entries | |
function wp_checklist_display_entries() { | |
if (!is_user_logged_in()) { | |
return '<p>You must be logged in to view this content.</p>'; | |
} | |
$user_id = get_current_user_id(); | |
global $wpdb; | |
$responses_table = $wpdb->prefix . 'checklist_responses'; | |
$questions_table = $wpdb->prefix . 'checklist_questions'; | |
$results = $wpdb->get_results($wpdb->prepare( | |
"SELECT r.date, q.section, q.question, r.response | |
FROM $responses_table r | |
JOIN $questions_table q ON r.question_id = q.id | |
WHERE r.user_id = %d | |
ORDER BY r.date DESC, q.section, q.id", | |
$user_id | |
)); | |
if (empty($results)) { | |
return '<p>No entries found.</p>'; | |
} | |
$current_date = ''; | |
ob_start(); | |
?> | |
<table> | |
<thead> | |
<tr> | |
<th>Date</th> | |
<th>Section</th> | |
<th>Question</th> | |
<th>Response</th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php foreach ($results as $entry) : ?> | |
<?php if ($current_date != $entry->date) : ?> | |
<tr> | |
<td colspan="4"><strong><?php echo esc_html($entry->date); ?></strong></td> | |
</tr> | |
<?php $current_date = $entry->date; ?> | |
<?php endif; ?> | |
<tr> | |
<td></td> | |
<td><?php echo esc_html($entry->section); ?></td> | |
<td><?php echo esc_html($entry->question); ?></td> | |
<td><?php echo esc_html($entry->response); ?></td> | |
</tr> | |
<?php endforeach; ?> | |
</tbody> | |
</table> | |
<?php | |
return ob_get_clean(); | |
} | |
add_shortcode('wp_checklist_display', 'wp_checklist_display_entries'); | |
// Enqueue scripts and styles | |
function wp_checklist_enqueue_scripts() { | |
$rand = rand(1,99999); | |
wp_enqueue_script('fullcalendar', 'https://cdn.jsdelivr.net/npm/[email protected]/main.min.js', array(), '5.5.1', true); | |
wp_enqueue_script('wp-checklist-js', plugins_url('/js/wp-checklist.js', __FILE__), array('fullcalendar'), time(), true); | |
wp_localize_script('wp-checklist-js', 'wpChecklistAjax', array('ajax_url' => admin_url('admin-ajax.php'))); | |
wp_enqueue_style('fullcalendar-css', 'https://cdn.jsdelivr.net/npm/[email protected]/main.min.css', array(), '5.5.1'); | |
wp_enqueue_style('wp-checklist-css', plugins_url('/css/wp-checklist.css', __FILE__), array(), rand(1, 9000)); | |
} | |
add_action('wp_enqueue_scripts', 'wp_checklist_enqueue_scripts'); | |
function register_select2_assets() { | |
// Register Select2 stylesheet | |
wp_enqueue_style( 'select2', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css' ); | |
// Register Select2 script | |
wp_enqueue_script( 'select2', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js', array('jquery') ); | |
} | |
add_action( 'wp_enqueue_scripts', 'register_select2_assets' ); | |
// Handle AJAX request to fetch dates with data | |
function wp_checklist_fetch_dates() { | |
if (!is_user_logged_in()) { | |
wp_send_json_error(array('message' => 'You must be logged in to fetch dates.')); | |
return; | |
} | |
$user_id = get_current_user_id(); | |
global $wpdb; | |
$responses_table = $wpdb->prefix . 'checklist_responses'; | |
$results = $wpdb->get_results($wpdb->prepare( | |
"SELECT DISTINCT date FROM $responses_table WHERE user_id = %d", | |
$user_id | |
)); | |
$dates = array(); | |
foreach ($results as $result) { | |
$dates[] = $result->date; | |
} | |
wp_send_json_success(array('dates' => $dates)); | |
} | |
add_action('wp_ajax_wp_checklist_fetch_dates', 'wp_checklist_fetch_dates'); | |
add_action('wp_ajax_nopriv_wp_checklist_fetch_dates', 'wp_checklist_fetch_dates'); | |
// Handle AJAX request to fetch data for a specific date | |
function wp_checklist_fetch_data() { | |
if (!is_user_logged_in()) { | |
wp_send_json_error(array('message' => 'You must be logged in to fetch data.')); | |
return; | |
} | |
$user_id = get_current_user_id(); | |
$date = sanitize_text_field($_GET['date']); | |
global $wpdb; | |
$responses_table = $wpdb->prefix . 'checklist_responses'; | |
$results = $wpdb->get_results($wpdb->prepare( | |
"SELECT question_id, response, supervisor_id FROM $responses_table WHERE user_id = %d AND date = %s", | |
$user_id, $date | |
)); | |
$data = array(); | |
foreach ($results as $result) { | |
$data['questions'][$result->question_id] = $result->response; | |
$data['supervisor_id'] = $result->supervisor_id; | |
} | |
wp_send_json_success(array('data' => $data)); | |
} | |
add_action('wp_ajax_wp_checklist_fetch_data', 'wp_checklist_fetch_data'); | |
add_action('wp_ajax_nopriv_wp_checklist_fetch_data', 'wp_checklist_fetch_data'); | |
//Admin section work | |
// In your main plugin file | |
function add_or_update_supervisor_users() { | |
$data = [ | |
["Maxim Nyanin", "[email protected]"], | |
["Deborah Jesusolu-Enioluwafe", "[email protected]"], | |
["Kathryne Muller", "[email protected]"], | |
["Candace Seguin", "[email protected]"], | |
["Abhishek Matken", "[email protected]"], | |
["Katherine Joy Gabriel", "[email protected]"], | |
["Simone Vitellaro", "[email protected]"], | |
["Maria Grazia Bevilacqua", "[email protected]"], | |
["Audrey Hlembizky", "[email protected]"], | |
["Ayushi Rathore", "[email protected]"], | |
["Sisey Shaban", "[email protected]"], | |
["Anzhelika Latysh", "[email protected]"], | |
["Kartika Kumar", "[email protected]"], | |
["Komal Gokani", "[email protected]"], | |
["Yuliia Kravchuk", "[email protected]"], | |
["Christine Johnson", "[email protected]"], | |
["DrMarvin Thompson", "[email protected]"], | |
["Krysten Wong", "[email protected]"] | |
]; | |
foreach ($data as $user_data) { | |
$full_name = $user_data[0]; | |
$user_email = sanitize_email($user_data[1]); | |
$name_parts = explode(' ', $full_name); | |
$first_name = $name_parts[0]; | |
$last_name = isset($name_parts[1]) ? $name_parts[1] : ''; | |
$user_name = sanitize_user(strtolower(str_replace(' ', '', $full_name))); | |
$user_id = email_exists($user_email); | |
if ($user_id) { | |
// If the user already exists, update their role to 'Supervisor' | |
$user = new WP_User($user_id); | |
$user->set_role('supervisor'); | |
// Update first name and last name | |
update_user_meta($user_id, 'first_name', $first_name); | |
update_user_meta($user_id, 'last_name', $last_name); | |
} else { | |
// If the user doesn't exist, create a new user | |
$user_id = wp_create_user($user_name, wp_generate_password(), $user_email); | |
if (!is_wp_error($user_id)) { | |
$user = new WP_User($user_id); | |
$user->set_role('supervisor'); | |
// Set first name and last name | |
update_user_meta($user_id, 'first_name', $first_name); | |
update_user_meta($user_id, 'last_name', $last_name); | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment