CI / Tests (PHP 8.1) (pull_request) Successful in 41s
CI / Tests (PHP 8.2) (pull_request) Successful in 40s
CI / No Debug Code (pull_request) Successful in 2s
CI / Coding Standards (pull_request) Successful in 2m55s
CI / PHPStan (pull_request) Successful in 3m1s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m43s
CI / Build Plugin Zip (pull_request) Skipped
Sweep the translatable strings across the frontend templates, the admin screens, the editor previews and the block inserter entry. Nothing else moves: the database columns, request parameters, form field names, CSS classes, the us_family shortcode and the us-scheduler/family block name are contracts with existing installs and with post content people have already saved, so renaming them would break sites for no user-visible gain. Two strings are reworded rather than swapped, because the direct substitution reads wrong: - The students list said "Child of Jane" and now says "Managed by Jane". "Student of Jane" would read as a teacher's pupil, which is exactly the wrong idea in a music studio. - A managed account is now "a managed student account" rather than "a student account", which would not distinguish it from the account holder. The guardian feature doc gains a short section on the split, so the next person to work on it does not read the mismatch as drift and "fix" it. Closes #144 Co-Authored-By: Claude Opus 5 <[email protected]>
63 lines
2.2 KiB
PHP
63 lines
2.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Guardian;
|
|
|
|
use Unsupervised\Schedular\Auth\RoleManager;
|
|
|
|
/**
|
|
* Keeps child accounts unusable as logins. A child holds the `us_student` role
|
|
* so every `student_id` lookup in the schema keeps working, but nobody is ever
|
|
* given its credentials — this closes the door the role would otherwise leave
|
|
* open:
|
|
*
|
|
* - authentication is refused outright, and
|
|
* - the booking capability is withheld, so nothing that reaches a capability
|
|
* check on a child's own session (there should be none) can book as them.
|
|
*
|
|
* Both key off the `us_child` meta, so ordinary students are untouched.
|
|
*/
|
|
class ChildLoginGate {
|
|
|
|
public function register(): void {
|
|
add_filter( 'wp_authenticate_user', [ $this, 'blockChildLogin' ], 10, 1 );
|
|
add_filter( 'user_has_cap', [ $this, 'withholdBooking' ], 10, 4 );
|
|
}
|
|
|
|
/**
|
|
* Refuse authentication for a child account. Runs after password
|
|
* verification, so it holds even if a password were somehow set on one.
|
|
*
|
|
* @param \WP_User|\WP_Error $user Authenticating user, or an earlier error.
|
|
* @return \WP_User|\WP_Error
|
|
*/
|
|
public function blockChildLogin( $user ) {
|
|
if ( $user instanceof \WP_User && GuardianService::isChild( (int) $user->ID ) ) {
|
|
return new \WP_Error(
|
|
'us_child_account',
|
|
esc_html__( 'This is a managed student account and cannot be signed in to. Please sign in with the parent or guardian account.', 'unsupervised-schedular' )
|
|
);
|
|
}
|
|
|
|
return $user;
|
|
}
|
|
|
|
/**
|
|
* Strip the booking capability from a child account, so the only route to a
|
|
* lesson in their name is their guardian's authorised booking.
|
|
*
|
|
* @param array<string, bool> $allcaps All capabilities currently held.
|
|
* @param array<int, string> $caps Required capabilities (unused).
|
|
* @param array<int, mixed> $args Callback args (unused).
|
|
* @param mixed $user The user being checked (a WP_User in practice).
|
|
* @return array<string, bool>
|
|
*/
|
|
public function withholdBooking( array $allcaps, array $caps, array $args, mixed $user ): array {
|
|
if ( $user instanceof \WP_User && GuardianService::isChild( (int) $user->ID ) ) {
|
|
unset( $allcaps[ RoleManager::CAP_BOOK_LESSON ] );
|
|
}
|
|
|
|
return $allcaps;
|
|
}
|
|
}
|