Make WP admins instructors too, and add an Access toggle page
CI / No Debug Code (pull_request) Successful in 3s
CI / Tests (PHP 8.2) (pull_request) Successful in 41s
CI / Tests (PHP 8.3) (pull_request) Successful in 51s
CI / Tests (PHP 8.1) (pull_request) Successful in 54s
CI / Coding Standards (pull_request) Successful in 58s
CI / PHPStan (pull_request) Successful in 1m9s
CI / Build Plugin Zip (pull_request) Has been skipped

A WordPress administrator previously inherited the studio-admin
capabilities but not `manage_availability`, so the studio owner running
as an admin had no way to reach "My Availability" or act as the
instructor — breaking single-instructor businesses.

Grant the instructor capabilities to administrators as well (via the
existing `user_has_cap` filter), and make both grants — studio-admin and
instructor — independently toggleable from a new Access admin page.

- RoleManager: extract `INSTRUCTOR_CAPS`; apply studio and instructor
  cap sets to administrators, each gated on a stored toggle (default on).
- AccessSettings + templates/admin/access.php: two options
  (`us_admin_grant_studio` / `us_admin_grant_instructor`), gated on the
  core `manage_options` capability so disabling a grant can never lock an
  administrator out of re-enabling it.
- AdminMenu: register the Access page after Studio Settings; keep the
  studio sidebar separator visible for any administrator.
- Tests for the toggles and the new settings reader; docs updated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-08 16:39:41 -03:00
parent 0a78f4b1ac
commit 67f8144a4a
7 changed files with 279 additions and 22 deletions
+50
View File
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
if (! defined('ABSPATH')) {
exit;
}
/**
* @var bool $adminsAreStudioAdmins
* @var bool $adminsAreInstructors
*/
?>
<div class="wrap">
<h1><?php esc_html_e('Access', 'unsupervised-schedular'); ?></h1>
<div class="notice notice-info inline">
<p>
<?php esc_html_e('Control whether WordPress administrators automatically gain studio-admin and instructor abilities. Both are on by default, so the site owner can run the studio and teach from one account. Turn them off when dedicated Studio Admin or Instructor accounts run the studio instead.', 'unsupervised-schedular'); ?>
</p>
</div>
<form method="post">
<?php wp_nonce_field('usc_access_action'); ?>
<input type="hidden" name="usc_action" value="save">
<table class="form-table">
<tr>
<th scope="row"><?php esc_html_e('WordPress administrators', 'unsupervised-schedular'); ?></th>
<td>
<fieldset>
<label>
<input type="checkbox" name="grant_studio" value="1" <?php checked($adminsAreStudioAdmins); ?>>
<?php esc_html_e('Are Studio Admins', 'unsupervised-schedular'); ?>
</label>
<p class="description"><?php esc_html_e('Manage offerings, questions, policies, students, invites, billing, and reports.', 'unsupervised-schedular'); ?></p>
<br>
<label>
<input type="checkbox" name="grant_instructor" value="1" <?php checked($adminsAreInstructors); ?>>
<?php esc_html_e('Are Instructors', 'unsupervised-schedular'); ?>
</label>
<p class="description"><?php esc_html_e('Manage their own availability and see their own lessons — needed to set availability and be booked from the administrator account.', 'unsupervised-schedular'); ?></p>
</fieldset>
<p class="description">
<?php esc_html_e('You are a WordPress administrator, so this page stays available even if you turn both options off.', 'unsupervised-schedular'); ?>
</p>
</td>
</tr>
</table>
<?php submit_button(esc_html__('Save Access Settings', 'unsupervised-schedular')); ?>
</form>
</div>