CI / Tests (PHP 8.1) (pull_request) Successful in 1m18s
CI / Tests (PHP 8.2) (pull_request) Successful in 1m18s
CI / No Debug Code (pull_request) Successful in 2s
CI / PHPStan (pull_request) Successful in 3m20s
CI / Coding Standards (pull_request) Successful in 3m25s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m33s
CI / Build Plugin Zip (pull_request) Skipped
Students could previously join by invite only. Add an optional self-approval mode, toggled from Studio Settings → Registration: anyone may sign up on the existing [us_student_register] page, confirm their email via a tokenised link, and then be approved by a studio admin before the account is usable. - Enabling the toggle mirrors WordPress's own membership settings (users_can_register + default_role = us_student) and snapshots their previous values so disabling restores them. - WordPress's native registration form is blocked while open registration is on (login_init redirect + registration_errors fail-safe + register_url) so it cannot bypass signup policy acceptance. - Pending accounts: unconfirmed email cannot log in; confirmed but unapproved can log in but the booking capability is withheld and the booking page shows an "awaiting approval" screen. - Approve/reject from Students → Pending Students; reject hard-deletes the account so the email is freed to re-apply. - Invite registration is unchanged; both modes coexist. Account lifecycle lives in user meta (RegistrationStatus); no new tables. Closes #63 Co-Authored-By: Claude Opus 4.8 <[email protected]>
117 lines
3.1 KiB
PHP
117 lines
3.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
// Minimal WordPress constants required by plugin code under test.
|
|
if (! defined('ABSPATH')) {
|
|
define('ABSPATH', sys_get_temp_dir() . '/wordpress/');
|
|
}
|
|
|
|
define('WPINC', 'wp-includes');
|
|
define('USC_VERSION', '1.0.0');
|
|
define('USC_PLUGIN_FILE', dirname(__DIR__) . '/unsupervised-schedular.php');
|
|
define('USC_PLUGIN_DIR', dirname(__DIR__) . '/');
|
|
define('USC_PLUGIN_URL', 'http://example.com/wp-content/plugins/unsupervised-schedular/');
|
|
|
|
// Minimal WP_REST_Request stub: a simple parameter bag.
|
|
if (! class_exists('WP_REST_Request')) {
|
|
class WP_REST_Request
|
|
{
|
|
/** @param array<string, mixed> $params */
|
|
public function __construct(private array $params = [])
|
|
{
|
|
}
|
|
|
|
public function get_param(string $key): mixed
|
|
{
|
|
return $this->params[$key] ?? null;
|
|
}
|
|
|
|
public function set_param(string $key, mixed $value): void
|
|
{
|
|
$this->params[$key] = $value;
|
|
}
|
|
|
|
public function get_body(): string
|
|
{
|
|
return (string) ($this->params['__body'] ?? '');
|
|
}
|
|
|
|
public function get_header(string $key): string
|
|
{
|
|
return (string) ($this->params[$key] ?? '');
|
|
}
|
|
}
|
|
}
|
|
|
|
// Minimal WP_REST_Response stub exposing the data and status.
|
|
if (! class_exists('WP_REST_Response')) {
|
|
class WP_REST_Response
|
|
{
|
|
public function __construct(public mixed $data = null, public int $status = 200)
|
|
{
|
|
}
|
|
|
|
public function get_data(): mixed
|
|
{
|
|
return $this->data;
|
|
}
|
|
|
|
public function get_status(): int
|
|
{
|
|
return $this->status;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Minimal WP_Post stub exposing the fields the plugin reads.
|
|
if (! class_exists('WP_Post')) {
|
|
class WP_Post
|
|
{
|
|
public int $ID = 0;
|
|
public string $post_content = '';
|
|
}
|
|
}
|
|
|
|
// Minimal WP_Error stub for code under test that returns error objects.
|
|
if (! class_exists('WP_Error')) {
|
|
class WP_Error
|
|
{
|
|
/** @var array<string, list<string>> */
|
|
public array $errors = [];
|
|
|
|
/** @var array<string, mixed> */
|
|
public array $error_data = [];
|
|
|
|
public function __construct(string $code = '', string $message = '', mixed $data = '')
|
|
{
|
|
if ('' !== $code) {
|
|
$this->errors[$code][] = $message;
|
|
if ('' !== $data) {
|
|
$this->error_data[$code] = $data;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function get_error_code(): string
|
|
{
|
|
return (string) (array_key_first($this->errors) ?? '');
|
|
}
|
|
|
|
public function get_error_message(): string
|
|
{
|
|
$code = $this->get_error_code();
|
|
return '' !== $code ? ($this->errors[$code][0] ?? '') : '';
|
|
}
|
|
|
|
public function add(string $code, string $message = '', mixed $data = ''): void
|
|
{
|
|
$this->errors[$code][] = $message;
|
|
if ('' !== $data) {
|
|
$this->error_data[$code] = $data;
|
|
}
|
|
}
|
|
}
|
|
}
|