Skip to content

Instantly share code, notes, and snippets.

@firasd
Created May 16, 2018 04:09
Show Gist options
  • Save firasd/7e09c287530a1dafd19690fdc9e6e167 to your computer and use it in GitHub Desktop.
Save firasd/7e09c287530a1dafd19690fdc9e6e167 to your computer and use it in GitHub Desktop.
Redirect WordPress user from LearnDash course page to first lesson page
<?php
add_action('template_redirect', function () {
if (is_user_logged_in()) {
$q_object = get_queried_object();
if (($q_object) && (is_a($q_object, 'WP_Post')) && ($q_object->post_type == 'sfwd-courses')) {
if (sfwd_lms_has_access($q_object->ID)) {
$steps = learndash_get_course_steps($q_object->ID);
if (count($steps)) {
wp_redirect(get_permalink($steps[0]));
die();
}
}
}
}
}
, 1);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment