0 ? get_userdata( $studentId ) : false; if ( $student && in_array( RoleManager::STUDENT, (array) $student->roles, true ) ) { $this->renderDetail( $student ); return; } $students = array_map( fn( \WP_User $user ): array => [ 'id' => (int) $user->ID, 'name' => $user->display_name, 'email' => $user->user_email, 'registered' => $user->user_registered, 'upcoming' => $this->bookings->countUpcomingForStudent( (int) $user->ID ), 'enrolments' => $this->enrollments->countActiveForStudent( (int) $user->ID ), ], get_users( [ 'role' => RoleManager::STUDENT, 'orderby' => 'display_name', 'order' => 'ASC', ] ) ); $pageSlug = 'us-students'; include USC_PLUGIN_DIR . 'templates/admin/students.php'; } private function renderDetail( \WP_User $student ): void { $canBilling = current_user_can( RoleManager::CAP_MANAGE_BILLING ); if ( $canBilling && isset( $_POST['usc_action'] ) && check_admin_referer( 'usc_student_billing' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce checked above. $method = sanitize_key( wp_unslash( $_POST['payment_method'] ?? '' ) ); if ( in_array( $method, Payment::VALID_METHODS, true ) ) { update_user_meta( (int) $student->ID, BillingMethodResolver::META_METHOD, $method ); } else { delete_user_meta( (int) $student->ID, BillingMethodResolver::META_METHOD ); } } $billingOverride = (string) get_user_meta( (int) $student->ID, BillingMethodResolver::META_METHOD, true ); $billingDefault = $this->resolver->defaultMethod(); $now = current_time( 'mysql' ); $rows = array_map( fn( Lesson $lesson ): array => $this->lessonRow( $lesson ), $this->bookings->findByStudent( (int) $student->ID ) ); $schedule = StudentSchedule::partition( $rows, $now ); $upcoming = $schedule['upcoming']; $past = $schedule['past']; $enrolments = array_map( function ( Enrollment $enrollment ): array { $offering = $this->offerings->findById( $enrollment->offeringId ); return [ 'offering' => $offering ? $offering->title : (string) $enrollment->offeringId, 'status' => $enrollment->status, ]; }, $this->enrollments->findByStudent( (int) $student->ID ) ); $backUrl = admin_url( 'admin.php?page=us-students' ); include USC_PLUGIN_DIR . 'templates/admin/student-detail.php'; } /** * Build a display row for a lesson (slot time, offering, instructor, status). * * @return array */ private function lessonRow( Lesson $lesson ): array { $slot = $this->availability->findById( $lesson->slotId ); $offering = null !== $lesson->offeringId ? $this->offerings->findById( $lesson->offeringId ) : null; $instructor = get_userdata( $lesson->instructorId ); return [ 'start_dt' => $slot ? $slot->startDt : '', 'end_dt' => $slot ? $slot->endDt : '', 'offering' => $offering ? $offering->title : '—', 'instructor' => $instructor ? $instructor->display_name : (string) $lesson->instructorId, 'status' => $lesson->status, ]; } }