Skip to content

Instantly share code, notes, and snippets.

@annuman97
Created November 17, 2025 08:07
Show Gist options
  • Select an option

  • Save annuman97/4946d1213bfcaeecbca81eabac541bd3 to your computer and use it in GitHub Desktop.

Select an option

Save annuman97/4946d1213bfcaeecbca81eabac541bd3 to your computer and use it in GitHub Desktop.
All Courses and courses?type=enrolled menu
add_action('template_redirect', function () {
if (!class_exists('\FluentCommunity\App\Services\Helper')) {
return;
}
global $wp;
$req = isset($wp->request)
? $wp->request
: trim(parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH), '/');
if (\FluentCommunity\App\Services\Helper::getPortalRequestPath($req) === 'portal_home') {
wp_safe_redirect(\FluentCommunity\App\Services\Helper::baseUrl('courses'));
exit;
}
}, 0);
add_action('fluent_community/after_header_menu', function () {
?>
<script>
(function () {
document.addEventListener('click', function (e) {
const a = e.target.closest('a');
if (!a) return;
let url;
try {
url = new URL(a.href, window.location.origin);
} catch (err) {
return;
}
if (url.pathname !== '/portal/courses') return;
e.preventDefault();
const isEnrolled = url.searchParams.get('type') === 'enrolled';
const base = url.origin + '/portal/courses';
const target = isEnrolled ? base + '?type=enrolled' : base;
const router = window.fcomLayoutRef && window.fcomLayoutRef.$router;
if (router) {
const query = isEnrolled ? {type: 'enrolled'} : {};
router.push({path: '/courses', query})
.then(function () {
const cleanCurrent = window.location.href.split('#')[0];
if (cleanCurrent !== target) {
history.replaceState({}, '', target);
}
})
.catch(function () {
window.location.href = target;
});
} else {
window.location.href = target;
}
}, true);
})();
</script>
<?php
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment