12
This commit is contained in:
parent
ff8df3f946
commit
151142df0e
@ -60,6 +60,7 @@ add_action('wp_head', function () {
|
||||
|
||||
add_action('template_redirect', 'matthew_lms_mvp_maybe_handle_login_submission');
|
||||
add_action('template_redirect', 'matthew_lms_mvp_maybe_handle_google_oauth_callback');
|
||||
add_action('template_redirect', 'matthew_lms_mvp_maybe_handle_signup_onboarding_submission');
|
||||
add_action('template_redirect', 'matthew_lms_mvp_maybe_handle_profile_source_submission');
|
||||
add_action('template_redirect', 'matthew_lms_mvp_require_auth_for_member_routes', 4);
|
||||
add_action('template_redirect', 'matthew_lms_mvp_maybe_render_course_route', 5);
|
||||
@ -134,13 +135,20 @@ function matthew_lms_mvp_require_auth_for_member_routes(): void {
|
||||
}
|
||||
|
||||
function matthew_lms_mvp_render_header(): string {
|
||||
$links = [
|
||||
$profile_url = matthew_lms_mvp_public_url('platform/');
|
||||
$lessons_url = matthew_lms_mvp_public_url('platform/course/');
|
||||
$public_links = [
|
||||
'Home' => matthew_lms_mvp_public_url(),
|
||||
'WAX Coach' => matthew_lms_mvp_public_url('career-coach/'),
|
||||
'Profile' => matthew_lms_mvp_member_access_url('platform/'),
|
||||
'Course' => matthew_lms_mvp_member_access_url('platform/course/'),
|
||||
];
|
||||
$login_url = add_query_arg('redirect_to', rawurlencode(matthew_lms_mvp_public_url('platform/')), matthew_lms_mvp_public_url('log-in/'));
|
||||
$access_links = [
|
||||
'Profile' => $profile_url,
|
||||
'Lessons' => $lessons_url,
|
||||
];
|
||||
$links = array_merge($public_links, $access_links);
|
||||
$login_url = add_query_arg('redirect_to', rawurlencode($profile_url), matthew_lms_mvp_public_url('log-in/'));
|
||||
$register_url = add_query_arg('redirect_to', rawurlencode($profile_url), matthew_lms_mvp_public_url('sign-up/'));
|
||||
$logout_url = wp_logout_url(matthew_lms_mvp_public_url());
|
||||
ob_start();
|
||||
?>
|
||||
<header class="mlms-site-header" role="banner">
|
||||
@ -152,8 +160,15 @@ function matthew_lms_mvp_render_header(): string {
|
||||
<?php endforeach; ?>
|
||||
</nav>
|
||||
<div class="mlms-header-actions">
|
||||
<a class="mlms-header-login" href="<?php echo esc_url($login_url); ?>">Login</a>
|
||||
<a class="mlms-btn mlms-btn-primary mlms-header-signup" href="<?php echo esc_url(matthew_lms_mvp_public_url('sign-up/')); ?>">Sign Up</a>
|
||||
<?php if (is_user_logged_in()): ?>
|
||||
<a class="mlms-btn mlms-btn-primary mlms-header-profile" href="<?php echo esc_url($profile_url); ?>">Profile</a>
|
||||
<a class="mlms-header-logout-icon" href="<?php echo esc_url($logout_url); ?>" aria-label="Log out" title="Log out">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M10 4a1 1 0 0 1 1 1v2H8v10h3v2a1 1 0 0 1-1 1H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h5Zm6.7 4.3 3.99 3.99a1 1 0 0 1 0 1.42l-3.99 3.99-1.4-1.42L17.58 14H10v-2h7.58l-2.28-2.28 1.4-1.42Z"/></svg>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<a class="mlms-btn mlms-btn-secondary mlms-header-login" href="<?php echo esc_url($login_url); ?>">Login</a>
|
||||
<a class="mlms-btn mlms-btn-primary mlms-header-signup" href="<?php echo esc_url($register_url); ?>">Register</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
@ -164,11 +179,15 @@ function matthew_lms_mvp_render_header(): string {
|
||||
function matthew_lms_mvp_render_footer(): string {
|
||||
$links = [
|
||||
'Career Coach' => matthew_lms_mvp_public_url('career-coach/'),
|
||||
'Profile' => matthew_lms_mvp_public_url('platform/'),
|
||||
'Course Dashboard' => matthew_lms_mvp_course_url('course'),
|
||||
'Log In' => matthew_lms_mvp_public_url('log-in/'),
|
||||
'Sign Up' => matthew_lms_mvp_public_url('sign-up/'),
|
||||
];
|
||||
if (is_user_logged_in()) {
|
||||
$links['Profile'] = matthew_lms_mvp_public_url('platform/');
|
||||
$links['Dashboard'] = matthew_lms_mvp_course_url('course');
|
||||
$links['Log Out'] = wp_logout_url(matthew_lms_mvp_public_url());
|
||||
} else {
|
||||
$links['Log In'] = matthew_lms_mvp_public_url('log-in/');
|
||||
$links['Sign Up'] = matthew_lms_mvp_public_url('sign-up/');
|
||||
}
|
||||
ob_start();
|
||||
?>
|
||||
<footer class="mlms-site-footer" role="contentinfo">
|
||||
@ -233,7 +252,10 @@ body{
|
||||
.mlms-header-nav a:hover,.mlms-header-login:hover{color:var(--mlms-primary)}
|
||||
.mlms-header-actions{display:flex;align-items:center;justify-content:flex-end;gap:12px}
|
||||
.mlms-header-login{padding:11px 14px;border-radius:999px;background:#fff;border:1px solid rgba(10,37,64,.10);box-shadow:0 6px 16px rgba(50,50,93,.06)}
|
||||
.mlms-header-signup{min-height:40px;padding:11px 16px;font-size:15px;box-shadow:0 10px 24px rgba(99,91,255,.20)}
|
||||
.mlms-header-signup,.mlms-header-profile{min-height:40px;padding:11px 16px;font-size:15px;box-shadow:0 10px 24px rgba(99,91,255,.20)}
|
||||
.mlms-header-logout-icon{width:42px;height:42px;border-radius:999px;display:inline-flex;align-items:center;justify-content:center;background:#fff;color:#31445B;border:1px solid rgba(10,37,64,.10);box-shadow:0 8px 20px rgba(50,50,93,.08);text-decoration:none!important;transition:transform .18s ease,box-shadow .18s ease,color .18s ease,background .18s ease}
|
||||
.mlms-header-logout-icon:hover{transform:translateY(-2px);color:var(--mlms-primary);box-shadow:0 12px 26px rgba(99,91,255,.16)}
|
||||
.mlms-header-logout-icon svg{width:20px;height:20px;display:block;fill:currentColor}
|
||||
body.page-id-47 .wp-block-post-title,body.page-id-48 .wp-block-post-title,body.page-id-49 .wp-block-post-title,body.page-id-50 .wp-block-post-title,.mlms-wax-page .wp-block-post-title{display:none!important}
|
||||
.entry-content{margin-top:0}.entry-content a{text-decoration:none}
|
||||
.entry-content>.mlms-page,.wp-block-post-content>.mlms-page{max-width:none!important;width:100%!important;margin-left:0!important;margin-right:0!important}
|
||||
@ -449,6 +471,25 @@ function matthew_lms_mvp_maybe_handle_login_submission(): void {
|
||||
}
|
||||
}
|
||||
|
||||
function matthew_lms_mvp_maybe_handle_signup_onboarding_submission(): void {
|
||||
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST' || !isset($_POST['mlms_signup_nonce'])) {
|
||||
return;
|
||||
}
|
||||
if (!is_page('sign-up')) {
|
||||
return;
|
||||
}
|
||||
$nonce = sanitize_text_field(wp_unslash($_POST['mlms_signup_nonce'] ?? ''));
|
||||
if (!wp_verify_nonce($nonce, 'mlms_signup_submit')) {
|
||||
$GLOBALS['mlms_signup_result'] = ['success' => false, 'message' => 'Your signup session expired. Please refresh and try again.'];
|
||||
return;
|
||||
}
|
||||
$GLOBALS['mlms_signup_result'] = matthew_lms_mvp_handle_signup_onboarding_submission();
|
||||
if (!empty($GLOBALS['mlms_signup_result']['success'])) {
|
||||
wp_redirect($GLOBALS['mlms_signup_result']['redirect']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function matthew_lms_mvp_maybe_handle_profile_source_submission(): void {
|
||||
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST' || !isset($_POST['mlms_profile_source_nonce'])) {
|
||||
return;
|
||||
@ -744,7 +785,7 @@ function matthew_lms_mvp_render_signup_success(array $result): string {
|
||||
<span><b>Email</b> <?php echo esc_html($result['email']); ?></span>
|
||||
<span><b>Role</b> <?php echo esc_html($result['role']); ?></span>
|
||||
</div>
|
||||
<div class="mlms-actions"><a class="mlms-btn mlms-btn-primary" href="<?php echo esc_url($result['redirect'] ?? matthew_lms_mvp_public_url('platform/')); ?>">Go to profile →</a><a class="mlms-btn mlms-btn-secondary" href="<?php echo esc_url(matthew_lms_mvp_public_url('platform/course/')); ?>">Start training</a></div>
|
||||
<div class="mlms-actions"><a class="mlms-btn mlms-btn-primary" href="<?php echo esc_url($result['redirect'] ?? matthew_lms_mvp_public_url('platform/')); ?>">Go to Profile →</a><a class="mlms-btn mlms-btn-secondary" href="<?php echo esc_url(matthew_lms_mvp_public_url('platform/course/')); ?>">Start Learning</a></div>
|
||||
</div>
|
||||
<div class="mlms-ai-profile">
|
||||
<div class="mlms-ai-profile-orb" aria-hidden="true">
|
||||
@ -2407,7 +2448,7 @@ add_shortcode('matthew_login', function () {
|
||||
<div class="mlms-form-card mlms-login-card" id="mlms-login-card">
|
||||
<?php if (is_user_logged_in()): ?>
|
||||
<div class="mlms-inline-note"><strong>You’re already signed in.</strong> Continue as <?php echo esc_html($current_user->user_email ?: $current_user->display_name); ?>.</div>
|
||||
<div class="mlms-actions"><a class="mlms-btn mlms-btn-primary" href="<?php echo esc_url($redirect_url); ?>">View WAX profile →</a><a class="mlms-btn mlms-btn-secondary" href="<?php echo esc_url(wp_logout_url(matthew_lms_mvp_public_url('log-in/'))); ?>">Log out</a></div>
|
||||
<div class="mlms-actions"><a class="mlms-btn mlms-btn-primary" href="<?php echo esc_url(matthew_lms_mvp_public_url('platform/')); ?>">Profile →</a><a class="mlms-btn mlms-btn-secondary" href="<?php echo esc_url(matthew_lms_mvp_public_url('platform/course/')); ?>">Lessons Dashboard</a><a class="mlms-btn mlms-btn-secondary" href="<?php echo esc_url(wp_logout_url(matthew_lms_mvp_public_url('log-in/'))); ?>">Log out</a></div>
|
||||
<?php else: ?>
|
||||
<h2>Log in to WAX.</h2>
|
||||
<p>Use Google for one-click access, or log in with your email/username and password.</p>
|
||||
@ -2443,15 +2484,9 @@ add_shortcode('matthew_login', function () {
|
||||
});
|
||||
|
||||
add_shortcode('matthew_signup_onboarding', function () {
|
||||
$result = null;
|
||||
$result = $GLOBALS['mlms_signup_result'] ?? null;
|
||||
$redirect_url = matthew_lms_mvp_redirect_url('platform/');
|
||||
$google_message = matthew_lms_mvp_take_google_oauth_message();
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['mlms_signup_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['mlms_signup_nonce'])), 'mlms_signup_submit')) {
|
||||
$result = matthew_lms_mvp_handle_signup_onboarding_submission();
|
||||
if (is_array($result) && !empty($result['success'])) {
|
||||
return matthew_lms_mvp_render_signup_success($result);
|
||||
}
|
||||
}
|
||||
$current_user = wp_get_current_user();
|
||||
$is_logged_in = is_user_logged_in();
|
||||
$prefill_email = $is_logged_in ? $current_user->user_email : sanitize_email(wp_unslash($_POST['mlms_signup_email'] ?? ''));
|
||||
@ -2468,7 +2503,7 @@ add_shortcode('matthew_signup_onboarding', function () {
|
||||
</div>
|
||||
<div class="mlms-form-card mlms-onboarding-card">
|
||||
<?php if (isset($_GET['mlms_gate'])): ?>
|
||||
<div class="mlms-inline-note"><strong>Create an account or log in to continue.</strong> Your WAX profile and course are available after registration.</div>
|
||||
<div class="mlms-inline-note"><strong>Create an account or log in to continue.</strong> Your WAX profile and lessons dashboard are available after registration or login.</div>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_GET['mlms_google_notice'])): ?>
|
||||
<div class="mlms-inline-note"><strong>Google sign-in is ready to connect.</strong> Add Google OAuth client credentials to enable real Gmail authentication. You can still sign up with email now.</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user