CI / No Debug Code (pull_request) Successful in 3s
CI / Tests (PHP 8.2) (pull_request) Successful in 48s
CI / Tests (PHP 8.3) (pull_request) Successful in 52s
CI / Coding Standards (pull_request) Successful in 57s
CI / Tests (PHP 8.1) (pull_request) Successful in 1m1s
CI / PHPStan (pull_request) Successful in 1m11s
CI / Build Plugin Zip (pull_request) Has been skipped
- Bump phpstan/phpstan ^2.0 and szepeviktor/phpstan-wordpress ^2.0 - Move the analysis level into phpstan.neon (single source) and raise it to 10 - Add Val, a runtime coercion helper that narrows untyped WordPress boundary values (wpdb rows, REST params, superglobals, options) with explicit checks instead of blind casts, plus unit tests - Type value-object fromRow() params as stdClass (what wpdb returns) and map columns through Val so unexpected shapes degrade safely - Use %i identifier placeholders for table names in all wpdb::prepare() calls so every query string is a literal and identifiers are escaped by WordPress; raises the minimum WordPress version to 6.2 where %i was introduced - Guard wpdb::prepare() null result before wpdb::query() in updateTax() - Fix nullable get_permalink()/strtotime() handling, list types at REST and capability call sites, dead null-coalescing on checked superglobals, and narrow get_users() results before mapping - Register Val method names with the ValidatedSanitizedInput sniff so it validates the real sanitizer around each superglobal read - Update repository unit tests for the %i placeholder arguments Co-Authored-By: Claude Fable 5 <[email protected]>
70 lines
2.4 KiB
PHP
70 lines
2.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Auth;
|
|
|
|
use Unsupervised\Schedular\Val;
|
|
|
|
/**
|
|
* Site-owner toggles for whether WordPress administrators automatically receive
|
|
* the studio-admin and/or instructor capabilities.
|
|
*
|
|
* Both default on, preserving the out-of-the-box experience where a single
|
|
* administrator runs the studio and teaches from one account. The settings page
|
|
* is gated on `manage_options` (the core WordPress administrator capability,
|
|
* which the plugin never grants or revokes) so an administrator can always reach
|
|
* it to re-enable a grant — disabling one can never lock them out.
|
|
*/
|
|
class AccessSettings {
|
|
|
|
public const OPT_GRANT_STUDIO = 'us_admin_grant_studio';
|
|
public const OPT_GRANT_INSTRUCTOR = 'us_admin_grant_instructor';
|
|
|
|
/**
|
|
* Whether WordPress administrators implicitly hold the studio-admin
|
|
* capabilities (offerings, policies, billing, reports, …).
|
|
*/
|
|
public function adminsAreStudioAdmins(): bool {
|
|
return $this->flag( self::OPT_GRANT_STUDIO );
|
|
}
|
|
|
|
/**
|
|
* Whether WordPress administrators implicitly hold the instructor
|
|
* capabilities (manage their own availability and lessons).
|
|
*/
|
|
public function adminsAreInstructors(): bool {
|
|
return $this->flag( self::OPT_GRANT_INSTRUCTOR );
|
|
}
|
|
|
|
/**
|
|
* Read a stored toggle, defaulting to on so a fresh install keeps the
|
|
* single-account behaviour.
|
|
*/
|
|
private function flag( string $option ): bool {
|
|
return '0' !== Val::string( get_option( $option, '1' ) );
|
|
}
|
|
|
|
public function renderPage(): void {
|
|
if ( ! current_user_can( 'manage_options' ) ) {
|
|
wp_die( esc_html__( 'You do not have permission to manage access settings.', 'unsupervised-schedular' ) );
|
|
}
|
|
|
|
if ( isset( $_POST['usc_action'] ) && check_admin_referer( 'usc_access_action' ) ) {
|
|
$this->save();
|
|
}
|
|
|
|
$adminsAreStudioAdmins = $this->adminsAreStudioAdmins();
|
|
$adminsAreInstructors = $this->adminsAreInstructors();
|
|
|
|
include USC_PLUGIN_DIR . 'templates/admin/access.php';
|
|
}
|
|
|
|
private function save(): void {
|
|
// Nonce is verified by the caller (renderPage) before this method runs.
|
|
// phpcs:disable WordPress.Security.NonceVerification.Missing
|
|
update_option( self::OPT_GRANT_STUDIO, isset( $_POST['grant_studio'] ) ? '1' : '0' );
|
|
update_option( self::OPT_GRANT_INSTRUCTOR, isset( $_POST['grant_instructor'] ) ? '1' : '0' );
|
|
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
|
}
|
|
}
|