- Remove unused AvailabilityRepository/BookingRepository from BookingPage and ShortcodeRegistrar (template is a JS shell; no PHP data needed yet) - Add @param array<string, string> to shortcode render() signatures - Add @return array<string, mixed> to model toArray() methods - Fix get_permalink() ?? '' — returns string|false not nullable, use cast - Remove unused ignoreErrors pattern from phpstan.neon Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Frontend;
|
|
|
|
class LoginPage
|
|
{
|
|
/**
|
|
* @param array<string, string> $atts
|
|
*/
|
|
public function render(array $atts): string
|
|
{
|
|
if (is_user_logged_in()) {
|
|
$redirect = esc_url((string) get_permalink());
|
|
return sprintf(
|
|
'<p>%s <a href="%s">%s</a>.</p>',
|
|
esc_html__('You are already logged in.', 'unsupervised-schedular'),
|
|
$redirect,
|
|
esc_html__('View available lessons', 'unsupervised-schedular')
|
|
);
|
|
}
|
|
|
|
$error = '';
|
|
$redirect = sanitize_url((string) get_permalink());
|
|
|
|
if (isset($_POST['us_login']) && check_admin_referer('us_student_login')) {
|
|
$credentials = [
|
|
'user_login' => sanitize_user($_POST['log'] ?? ''),
|
|
'user_password' => $_POST['pwd'] ?? '',
|
|
'remember' => isset($_POST['rememberme']),
|
|
];
|
|
|
|
$user = wp_signon($credentials, false);
|
|
|
|
if (is_wp_error($user)) {
|
|
$error = esc_html__('Invalid username or password.', 'unsupervised-schedular');
|
|
} else {
|
|
wp_safe_redirect($redirect);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
ob_start();
|
|
include USC_PLUGIN_DIR . 'templates/frontend/login-page.php';
|
|
return (string) ob_get_clean();
|
|
}
|
|
}
|