I found this from a shortcode and we're having a bit of an issue with the loading time using this function. I was wondering if there's a way to further optimize this or perhaps use a php redirection instead of javascript?
function gdp_mss_after_login() {
$user = wp_get_current_user();
if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
$user_level = get_user_meta($user->ID, 'gdp_level', true);
ob_start();
if ( !empty($user_level) ) {
$post_id = get_option('gdp_mss_course_level_' . $user_level);
$url = esc_url(get_permalink($post_id));
?>
<script type="text/javascript">
window.location = '<?php echo $url; ?>';
</script>
<?php
}
}
return ob_get_clean();
}
add_shortcode( 'gdp_mss_login_redirect', 'gdp_mss_after_login' );