Add Instructors admin page (create + per-capability access)
CI / No Debug Code (pull_request) Successful in 3s
CI / Tests (PHP 8.3) (pull_request) Successful in 48s
CI / Tests (PHP 8.2) (pull_request) Successful in 49s
CI / Tests (PHP 8.1) (pull_request) Successful in 54s
CI / Coding Standards (pull_request) Successful in 1m5s
CI / PHPStan (pull_request) Successful in 1m11s
CI / Build Plugin Zip (pull_request) Has been skipped

Completes the instructor-management half of #9: the studio admin can now
create instructor accounts and toggle each instructor's capabilities.

- InstructorController (manage_instructors): list instructors, create a
  us_instructor WP user (emailing a set-password link), and a per-instructor
  capability detail view.
- InstructorCapabilities: pure, unit-tested rules for which managed caps an
  admin may assign and how a submitted form maps to assignments. Managed caps
  are manage_offerings, manage_questions, view_own_payments, export_payments;
  manage_availability and view_own_lessons are core to every instructor.
- A studio admin can never grant a capability it does not itself hold: only
  held caps (checked via current_user_can, so an administrator's dynamic grant
  counts) are offered, and on creation any managed cap the admin lacks is
  denied on the new instructor so they never exceed their creator. The role
  grants the managed caps by default; the page layers per-user overrides.
- AdminMenu: register the Instructors page in the people section.
- Tests for the capability logic; docs/features/user-roles.md updated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-08 17:02:46 -03:00
parent fdadd2fb92
commit b5c076c3d6
7 changed files with 438 additions and 6 deletions
+60
View File
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
if (! defined('ABSPATH')) {
exit;
}
/**
* @var \WP_User $instructor
* @var array<string, array{granted: bool, grantable: bool}> $capabilities
* @var string $backUrl
* @var string $notice
*/
$capabilityLabels = [
'manage_offerings' => __('Manage their own offerings', 'unsupervised-schedular'),
'manage_questions' => __('Manage their own intake questions', 'unsupervised-schedular'),
'view_own_payments' => __('View their own payments report', 'unsupervised-schedular'),
'export_payments' => __('Export their own payments', 'unsupervised-schedular'),
];
?>
<div class="wrap">
<h1><?php echo esc_html($instructor->display_name); ?></h1>
<p><a href="<?php echo esc_url($backUrl); ?>">&larr; <?php esc_html_e('Back to instructors', 'unsupervised-schedular'); ?></a></p>
<?php if ('' !== $notice) : ?>
<div class="notice notice-info inline"><p><?php echo esc_html($notice); ?></p></div>
<?php endif; ?>
<p><?php echo esc_html($instructor->user_email); ?></p>
<h2><?php esc_html_e('Capabilities', 'unsupervised-schedular'); ?></h2>
<p class="description"><?php esc_html_e('Every instructor manages their own availability and sees their own lessons. The options below are set per instructor — ones you do not hold yourself cannot be changed.', 'unsupervised-schedular'); ?></p>
<form method="post">
<?php wp_nonce_field('usc_instructor_action'); ?>
<input type="hidden" name="usc_action" value="update_caps">
<input type="hidden" name="instructor_id" value="<?php echo esc_attr((string) $instructor->ID); ?>">
<table class="form-table">
<?php foreach ($capabilities as $cap => $state) : ?>
<tr>
<th scope="row"><?php echo esc_html($capabilityLabels[$cap] ?? $cap); ?></th>
<td>
<?php if ($state['grantable']) : ?>
<label>
<input type="checkbox" name="capabilities[]" value="<?php echo esc_attr($cap); ?>" <?php checked($state['granted']); ?>>
<?php esc_html_e('Allowed', 'unsupervised-schedular'); ?>
</label>
<?php else : ?>
<span class="description">
<?php echo $state['granted'] ? esc_html__('Allowed', 'unsupervised-schedular') : esc_html__('Not allowed', 'unsupervised-schedular'); ?>
— <?php esc_html_e('you cannot change this because you do not hold this capability yourself.', 'unsupervised-schedular'); ?>
</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php submit_button(esc_html__('Save Capabilities', 'unsupervised-schedular')); ?>
</form>
</div>