<script>
window.onload = function() {
    // Check if user is logged in and not an administrator
    fetch('/wp-json/wp/v2/users/me', { credentials: 'same-origin' })
        .then(response => {
            if (!response.ok) throw new Error('Network response was not ok');
            return response.json();
        })
        .then(user => {
            if (user && user.id !== 0 && !user.roles.includes('administrator')) {
                console.log("Redirecting non-admin user to /latest...");
                window.location.href = '/latest';
            } else {
                console.log("User is an administrator or not logged in.");
            }
        })
        .catch(error => console.error('There was a problem with the fetch operation:', error));
};

</script>